WrappedChatComponent is null in some server chat packets
jaqobb opened this issue ยท 1 comments
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:
- Start listening to
PacketType.Play.Server.CHAT
. - Print packet's message via i.e.:
event.getPacket().getChatComponents().read(0).toString()
. - Test with
/plugins
command. - See an error in the console.
Expected behavior
WrappedChatComponent is not null and I can receive the message.
Version Info
https://pastebin.com/WPxNjptU
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));
}