ProtocolLib

3M Downloads

Problem with PacketType.Play.Server.SYSTEM_CHAT with packetlistener on 1.20.1 on last dev build

SuperMax8 opened this issue ยท 2 comments

commented
  • This issue is not solved in a development build

Describe the bug
String from the listener of Systemchatmessage is null, maybe indirectly affect the getvalues structure thing error

To Reproduce
Steps to reproduce the behavior:
protocolManager.addPacketListener(new PacketAdapter(ConversationPlugin.getInst(), ListenerPriority.HIGH, PacketType.Play.Server.SYSTEM_CHAT) {
@OverRide
public void onPacketSending(PacketEvent e) {
if (e.isCancelled()) return;
try {
PacketContainer packet = e.getPacket();

                        if (packet.getBooleans().read(0)) return;

                        // TEST BUT ERROR
                        packet.getStructures().getValues().forEach(s -> {
                            System.out.println(s.toString());
                        });
                        StructureModifier<String> strings = packet.getStrings();
                        // OUPUT ONE VALUE THAT IS NULL
                        System.out.println("SYSTEM CHAT: " + strings.getValues());
                        // RESULT: >.... [04:46:48 INFO]: [Conversation] SYSTEM CHAT: [null] 
                        String message = BaseComponent.toLegacyText(ComponentSerializer.parse(strings.read(1)));

error with packet.getStructures.getvalues

.... [04:43:50 WARN]: java.lang.NullPointerException: Cannot invoke "Object.getClass()" because "generic" is null
.... [04:43:50 WARN]: at ProtocolLib.jar//com.comphenix.protocol.events.InternalStructure$1.getSpecific(InternalStructure.java:23)
.... [04:43:50 WARN]: at ProtocolLib.jar//com.comphenix.protocol.events.InternalStructure$1.getSpecific(InternalStructure.java:15)
.... [04:43:50 WARN]: at ProtocolLib.jar//com.comphenix.protocol.reflect.StructureModifier.readInternal(StructureModifier.java:301)
.... [04:43:50 WARN]: at ProtocolLib.jar//com.comphenix.protocol.reflect.StructureModifier.readSafely(StructureModifier.java:275)
.... [04:43:50 WARN]: at ProtocolLib.jar//com.comphenix.protocol.reflect.StructureModifier.getValues(StructureModifier.java:484)
.... [04:43:50 WARN]: at original-conversation-1.1.2.jar//fr.supermax_8.conversation.listener.ReceiveMessageListener$5.onPacketSending(ReceiveMessageListener.java:189)

Version Info
Provide your ProtocolLib install info with /protocol dump through pastebin.

commented

Paper added another field that can contain an adventure chat component as an alternative to the JSON encoded string you are trying to access. If the adventure chat component is non-null, the string message will be empty.

Please have a look at this: https://github.com/lukalt/PacketWrapper/blob/master/src/main/java/com/comphenix/packetwrapper/wrappers/play/clientbound/WrapperPlayServerSystemChat.java
This is one way of handling both cases.

commented

Thanks a lot
Your version of packetwrapper work perfectly for my plugin