ProtocolLib

3M Downloads

1.17 Teams Packet - Chat Component Writing

linsaftw opened this issue ยท 15 comments

commented

Describe the question
Can't write Chat Components or Strings in 1.17 Teams packet. Writing safely is like writing nothing.

Expected behavior
To be able to write the 3 strings/chatcomponents, prefix, suffix and displayname.

Code

final StructureModifier<String> strings = packet.getStrings();
final StructureModifier<WrappedChatComponent> chatComponents = packet.getChatComponents();

strings.writeSafely(1, teamDisplayName);
strings.writeSafely(2, prefix);
strings.writeSafely(3, suffix);
chatComponents.writeSafely(0, teamDisplayName);
chatComponents.writeSafely(1, prefix);
chatComponents.writeSafely(2, suffix);
commented
commented

#1388

Can you please give us an example on what to do to write this ChatComponents/Strings? In that issue there is no explanation of writing, just about reading and I can't find any way to modify Optional<> objects.

commented

#1388

Can you please give us an example on what to do to write this ChatComponents/Strings? In that issue there is no explanation of writing, just about reading and I can't find any way to modify Optional<> objects.

It should be enough to modify the values with the setters of WrappedScoreboardTeam.

To create a new PacketPlayOutScoreboardTeam, first try if the optional is getting filled with a PacketPlayOutScoreboardTeam$b by protocollib. If not, its time for protocollib to handle this

commented

#1388

Can you please give us an example on what to do to write this ChatComponents/Strings? In that issue there is no explanation of writing, just about reading and I can't find any way to modify Optional<> objects.

It should be enough to modify the values with the setters of WrappedScoreboardTeam.

To create a new PacketPlayOutScoreboardTeam, first try if the optional is getting filled with a PacketPlayOutScoreboardTeam$b by protocollib. If not, its time for protocollib to handle this

The optional is getting filled, but how do I modify it?

How do I access the WrappedScoreboardTeam from the ProtocolLib maven dependency? I can't find any imports. I just found one repo but it is only for 1.13. Do I have to include it with the plugin or is it included in ProtocolLib jar? I am experiencing a class not found issue when trying to use the WrappedScoreboardTeam.

commented

This optional has a NMS class. Using it will break old versions. How do I modify it without breaking the plugin on older versions?

commented

I tried copying the wrapper thingy and it's not working at all. Am I doing something wrong?

            final WrappedScoreboardTeam team = WrappedScoreboardTeam.fromHandle(optionals.read(0).get());

            team.setDisplayName(WrappedChatComponent.fromText(displayName)); // team display name
            team.setPrefix(WrappedChatComponent.fromText(prefix)); // prefix
            team.setSuffix(WrappedChatComponent.fromText(suffix)); // suffix
            optionals.write(0, Optional.of(team.getHandle()));
commented

Okay now its working. How do I set an empty color? Because with the wrapper class it seems that there is no way to do so.

commented

Okay now its working. How do I set an empty color? Because with the wrapper class it seems that there is no way to do so.

Am empty color does not exist on packet level you could try ChatColor.RESET though

commented

Okay now its working. How do I set an empty color? Because with the wrapper class it seems that there is no way to do so.

Am empty color does not exist on packet level you could try ChatColor.RESET though

Sadly this resets colors. ViaVersion is for some reason able to send this packets. (1.8 server with 1.17 client for example) and on 1.8/1.16 it doesn't require colors at all.

commented

Okay now its working. How do I set an empty color? Because with the wrapper class it seems that there is no way to do so.

Am empty color does not exist on packet level you could try ChatColor.RESET though

Sadly this resets colors. ViaVersion is for some reason able to send this packets. (1.8 server with 1.17 client for example) and on 1.8/1.16 it doesn't require colors at all.

No, ViaVersion is NOT able to do that.
Color was never optional for a team creation.

commented

Okay now its working. How do I set an empty color? Because with the wrapper class it seems that there is no way to do so.

Am empty color does not exist on packet level you could try ChatColor.RESET though

Sadly this resets colors. ViaVersion is for some reason able to send this packets. (1.8 server with 1.17 client for example) and on 1.8/1.16 it doesn't require colors at all.

No, ViaVersion is NOT able to do that. Color was never optional for a team creation.

How does it pass the color of the prefix then? Maybe it takes the color of the prefix and puts it into the team color variable?

commented

Okay now its working. How do I set an empty color? Because with the wrapper class it seems that there is no way to do so.

Am empty color does not exist on packet level you could try ChatColor.RESET though

Sadly this resets colors. ViaVersion is for some reason able to send this packets. (1.8 server with 1.17 client for example) and on 1.8/1.16 it doesn't require colors at all.

No, ViaVersion is NOT able to do that. Color was never optional for a team creation.

How does it pass the color of the prefix then? Maybe it takes the color of the prefix and puts it into the team color variable?

Well, viaversion already sees a packet with existing team color, nothing to extract there

commented

The only thing I know is that on 1.8/1.16 if you don't write anything into the packet "color" integer it just doesn't display any colors.

commented

The only thing I know is that on 1.8/1.16 if you don't write anything into the packet "color" integer it just doesn't display any colors.

default for 1.16 is reset, check yourself maybe with /packet command

commented

https://github.com/2lstudios-mc/SwiftBoard - Some context about the project I am using ProtocolLib for.