Comands packet can't be changed/read correctly on 1.19
Nononitas opened this issue ยท 11 comments
Describe the bug
On version 1.19 the command declare packet doesn't contains command nodes anymore. Instead there are only nms Objects of the class PacketPlayOutCommands in an array on index 1, see: https://pastebin.com/wvv2FACE
There is also no StructureModifier or a wrapper for it as far as I've seen.
To Reproduce
Steps to reproduce the behavior:
- Make a listener for the play out commands packet
- Try to read the packet information on index 1 without using nms
Expected behavior
Getting the CommandNode/RootCommandNode without resorting to nms, like in previous minecraft versions where the RootCommandNode was at index 0 and no nms is needed to read or change the data or a strucuture modifier.
Version Info
v5.0.0-SNAPSHOT-b568
I had no time yet to look into your problem deeply, but I would suggest using the internal structure modifier here
As I said, use the internal structure converter for that purpose. I did some testing:
int rootIndex = event.getPacket().getIntegers().read(0);
StructureModifier<List<InternalStructure>> lists = event.getPacket().getLists(InternalStructure.getConverter());
List<InternalStructure> commands = lists.read(0);
The root command node (at the index) has an array of integers with all commands which are registered to it, you then need to walk down the tree:
int[] subCommands = commands.get(rootIndex).getIntegerArrays().read(0);
for (int i = 0; i < subCommands.length; i++) {
}
Each of these wrappers then contain an information about the command:
InternalStructure subCommand = commands.get(i);
InternalStructure commandInfo = subCommand.getStructures().read(0);
String commandName = commandInfo.getStrings().read(0);
Then just collect all the subCommands you want to remove and in the end make a final removeAll
call:
if (commandName.equals(...)) {
toRemove.add(subCommand);
}
// ... then:
commands.removeAll(toRemove);
And to write the new list to the field just do
lists.write(0, commands);
Ok, I'm not getting something here. I don't remember seeing the command send packet change, why did the method that worked before break in the first place?
I don't know which "method that worked before" you are referring to
RootCommandNode<?> node = (RootCommandNode<?>) packet.getModifier().getValues().get(0);
It was piss easy on 4.8.0, having to do all that extra work sounds like a huge downgrade.
I tested the code from this reply, it doesn't work, commandInfo will always be null.
I was piss easy on 4.8.0, having to do all that extra work sounds like a huge downgrade.
That code you were using wasn't supported api by ProtocolLib. We're just wrapping the packet and allowing you to read/write to fields in these packets. If Mojang changes their structure (which they did) you need to adopt to that.
I tested the code from this reply, it doesn't work, commandInfo will always be null.
Then you're using the code wrongly, the info is only null if you're trying to access it on the root command node.