aadnk / ProtocolLib

Provides read and write access to the Minecraft protocol with Bukkit.
GNU General Public License v2.0
288 stars 92 forks source link

[1.19] DecoderException: Received unexpected null component. #199

Open arthurr0 opened 2 years ago

arthurr0 commented 2 years ago

image

    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;
    }