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

Valid Chat packet without ChatComponents #118

Closed dadus33 closed 7 years ago

dadus33 commented 7 years ago

Debug paste link: https://hastebin.com/upopecabuh.rb

Description and relevant errors: Ok so I admit this might not actually be a bug, but it surely is related to protocollib. I have a plugin which uses ProtocolLib's packet listener functionality to intercept and edit outgoing chat packets. Until recently, all worked perfectly well. However, one of my users stated that my plugin is incompatible with another one (ChatControl Pro, it is it's packet listener - the one that listens to tab complete - that you see listed in the paste beneath ChatItem, which is my plugin). Now I've done some extensive debugging and managed to identify the issue. That plugin is using spigot's chat component API, which basically sends packets the old fashioned way. By decompiling the spigot source, I got this: https://hastebin.com/zuxuxopuwi.cs However, when that packet is sent, although the packet event fires indeed, I can't seem to get the ChatComponent of the packet. More formally, using packet.getChatComponents().readSafely(0) returns null, even though I'm 100% sure it should contain a valid ChatComponent. This only happens for packets sent that way, normal packets sent by the server as a response to a command or a player chat work perfectly. Any help would be much appreciated.

dmulloy2 commented 7 years ago

It's related to ProtocolLib, yes, but it's caused by how Spigot sends custom chat components. Basically how it works is Spigot uses their own implementation (from Bungee) and a separate variable. The packet ends up looking like this:

    private IChatBaseComponent a;
    public net.md_5.bungee.api.chat.BaseComponent[] components; // Spigot
    private byte b;

With that said, you can still modify the Spigot components with packet.getSpecificModifier(BaseComponent[].class).readSafely(0). Note that Spigot components take priority over vanilla MC components.

dadus33 commented 7 years ago

Thank you! That's exactly what I needed to know!