ProtocolLib

3M Downloads

Packet Server.COMMANDS error and usages

arkillon1 opened this issue ยท 0 comments

commented

Question
I want to get the commands sent (the spigot event for this is PlayerCommandSendEvent) and delete and change a few things.
I tried a code (which should be in 1.19) given by the ProtocolLib devlopper in another problem but in 1.20 I got an error. Is this a bug? Or should I use other methods in version 1.20?
Thanks

Error
java.lang.NullPointerException: Cannot invoke "Object.getClass()" because "generic" is null
at com.comphenix.protocol.events.InternalStructure$1.getSpecific(InternalStructure.java:23) ~[?:?]
at com.comphenix.protocol.events.InternalStructure$1.getSpecific(InternalStructure.java:15) ~[?:?]
at com.comphenix.protocol.reflect.StructureModifier.readInternal(StructureModifier.java:301) ~[?:?]
at com.comphenix.protocol.reflect.StructureModifier.read(StructureModifier.java:251) ~[?:?]

Code
int rootIndex = event.getPacket().getIntegers().read(0);

            StructureModifier<List<InternalStructure>> lists = event.getPacket().getLists(InternalStructure.getConverter());
            List<InternalStructure> commands = lists.read(0);

            int[] subCommands = commands.get(rootIndex).getIntegerArrays().read(0);
            for (int i = 0; i < subCommands.length; i++) {
                InternalStructure subCommand = commands.get(i);
                InternalStructure commandInfo = subCommand.getStructures().read(0);
                String commandName = commandInfo.getStrings().read(0);

                if (commandName.equals("help")) {
                    System.out.println("help");
                }
            }

(error generated by InternalStructure commandInfo = subCommand.getStructures().read(0);)