ProtocolLib
ProtocolLib copied to clipboard
[1.19] DecoderException: Received unexpected null component.
public NametagHelper(Player player, ChatColor teamColor) {
this.packet = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.SCOREBOARD_TEAM);
this.packet.getStrings().write(0, RandomString.make(10));
this.packet.getIntegers().write(0, 0);
this.internalStructure = this.packet.getOptionalStructures().readSafely(0).get();
this.internalStructure.getChatComponents().write(0, WrappedChatComponent.fromText(ChatColor.translateAlternateColorCodes('&', "&7ESSA")));
this.internalStructure.getStrings().write(0, "always");
this.internalStructure.getStrings().write(1, "never");
this.internalStructure.getEnumModifier(ChatColor.class, MinecraftReflection.getMinecraftClass("EnumChatFormat")).write(0, teamColor);
this.packet.getOptionalStructures().write(0, Optional.of(this.internalStructure));
this.packet.getSpecificModifier(Collection.class).write(0, Collections.singletonList(player.getName()));
}
public NametagHelper setPrefix(String prefix) {
this.internalStructure.getChatComponents()
.write(
1,
WrappedChatComponent.fromJson(
this.gsonComponentSerializer.serialize(this.miniMessage.deserialize(prefix + " "))
)
);
return this;
}