ScoreboardTeam Packet failed to encode
DevLeven opened this issue ยท 3 comments
Make sure you're doing the following
- [Y] You're using the latest build for your server version
- [N] This isn't an issue caused by another plugin
- [Y] You've checked for duplicate issues
- [Y] You didn't use
/reload
Describe the question
When I try to create and set a scoreboard team for a player entity I create using packets, it kicks the player saying the Error sending packet clientbound/minecraft:set_player_team
. It then goes on the say Parameters not present, but method is 0
. Doing some digging I found that when the action is set to 0 meaning creating a new team, you have to set optional fields, which I did, but it still does not function.
API method(s) used
List what API method(s) you're using
Expected behavior
A new scoreboard team should be created for the player entity and set to the player entity, hiding their nametag.
Code
If applicable, add relevant code from your project
`getPacketContainer().getModifier().write(0, action);
// SETS UNiQUE NAME FOR TEAM
getPacketContainer().getStrings().write(0, scoreboardName);
var teamDisplayName = WrappedChatComponent.fromText("");//Get team display name
//Create optional internal structure
var optStruct = getPacketContainer().getOptionalStructures().read(0);
//Check if is present and write data
if (optStruct.isPresent()) { //IS ALWAYS PRESENT
System.out.println("Scoreboard optional parameters is present!");
//Get internal structures
var struct = optStruct.get();
//Write data for internal structure
struct.getChatComponents().write(0, teamDisplayName); //Sets team display name || CRUCIAL for team to work
struct.getIntegers().write(0, 1); //Sets amount of entities the team can accept || Only the corpse
struct.getStrings().write(0, "never"); //Entity name tag visibility || NEVER
struct.getStrings().write(1, "never"); //Entity Collision rule || NEVER
//Write internal structure to packet
getPacketContainer().getOptionalStructures().write(0, Optional.of(struct));
}
//Add entity to team
getPacketContainer().getModifier().write(2, Lists.newArrayList(entityName));`
Additional context
I recently switched from 1.20.2 to 1.20.6, I didn't experience any code-breaking issues besides this one.
Running into a related issue. Basically the optional structure seems to be empty by default now
edit: looks like WrappedTeamParameters are the solution
I'm now using the following:
WrappedTeamParameters parameters = WrappedTeamParameters.newBuilder()
.displayName(WrappedChatComponent.fromText(displayName))
.prefix(WrappedChatComponent.fromText(prefix))
.suffix(WrappedChatComponent.fromText(suffix))
.nametagVisibility(nameTagVisibility)
.collisionRule(collisionRule)
.color(ChatFormatting.RESET)
.build();
packet.getOptionalTeamParameters().write(0, Optional.of(parameters));