ProtocolLib

3M Downloads

WrappedChatComponent is null in some server chat packets

jaqobb opened this issue ยท 1 comments

commented

Describe the bug
WrappedChatComponent seems to be null in some places when I believe that this shouldn't be the case. While I only found /plugins to be causing this issue, I was already reported with some action bar messages also causing it. I assume this might be because a field that is being used is null while the components field contains the actual message

Error from my testing:
https://pastebin.com/BSfwqxuk

Line 85 is just trying to print the message:

this.getPlugin().getLogger().log(Level.INFO, message.toString());

message is:

WrappedChatComponent message = oldPacket.getChatComponents().read(0);

oldPacket is:

PacketContainer oldPacket = event.getPacket();

To reproduce
Steps to reproduce the behavior:

  1. Start listening to PacketType.Play.Server.CHAT.
  2. Print packet's message via i.e.: event.getPacket().getChatComponents().read(0).toString().
  3. Test with /plugins command.
  4. See an error in the console.

Expected behavior
WrappedChatComponent is not null and I can receive the message.

Version Info
https://pastebin.com/WPxNjptU

commented

I managed to fix this issue by getting and setting message from/to BaseComponent[] if WrappedChatComponent is null:

WrappedChatComponent message = newPacket.getChatComponents().read(0);
String messageJson;
if (message != null) {
    messageJson = message.getJson();
} else {
    messageJson = ComponentSerializer.toString(newPacket.getSpecificModifier(BaseComponent[].class).read(0));
 }
if (message != null) {
    newPacket.getChatComponents().write(0, WrappedChatComponent.fromJson(messageJson));
} else {
    newPacket.getSpecificModifier(BaseComponent[].class).write(0, ComponentSerializer.parse(messageJson));
}