PacketType.Play.Server.Chat has null fields when message has a sender
repeater64 opened this issue ยท 1 comments
Server version: 1.16.5
Using latest protocollib download, version 4.7.0
Describe the bug
Whenever a chat message is sent to a client and it is some kind of a system message (the sender is 00000000-0000-0000-0000-000000000000), all works as expected and I can read the message with packet.getChatComponents().read(0)
However whenever the chat message has an associated sender, such as when I type "hi" in chat and the packet containing the message is sent back to me, the field is null. I can confirm this by throwing an exception in my listener, causing the following protocollib dump to be printed:
Parameters: net.minecraft.server.v1_16_R3.PacketPlayOutChat@2ebc65e8[ a=<null> components=<null> b=CHAT c=29c9385d-c6df-4e0b-940f-d9d7260b6a0d ]
To Reproduce
Steps to reproduce the behavior:
- Register an event listener for PacketType.Play.Server.Chat
- In your listener, print out event.getPacket().getChatComponents().readSafely(0)
- On the server, type a message in chat. It will print "null"
- But if a system message is sent, eg a player join message, or you run /say, it will correctly print out the chat component.
Expected behavior
The result of getChatComponents.read(0) to never be null (except maybe in the case of a blank message or something).
Version Info
https://pastebin.com/z7vqQujQ
The pastebin shows that my plugin (CastleSiegePlugin) is the only plugin that registers a listener on that packet type.
Update - I needed this pretty urgently so ended up doing it just with NMS packets. Found some interesting stuff that kind of explains the reason behind this. I'm not at all an expert but maybe this will make some sense to you dmulloy!
So, PacketPlayOutChat has the following fields:
private IChatBaseComponent a; public Component adventure$message; public BaseComponent[] components; private ChatMessageType b; private UUID c;
My testing showed that "IChatBaseComponent a" is used for most system messages.
"Component adventure$message" (Component being net.kyori.adventure.text.Component) is used for actual CHAT messages
"BaseComponent[] components" seemed to be used for titles for some reason??
Anyway, maybe this is useful information.