From 00099b53323ad7dfbcaacd1ffb91610a3d9fdb1c Mon Sep 17 00:00:00 2001 From: rtm516 Date: Sat, 11 Apr 2020 15:53:53 +0100 Subject: [PATCH] Multi arguments handling --- .../JavaServerDeclareCommandsTranslator.java | 44 +++++++++++++++---- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaServerDeclareCommandsTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaServerDeclareCommandsTranslator.java index 22d6e7a64..f8d31be9b 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaServerDeclareCommandsTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaServerDeclareCommandsTranslator.java @@ -120,18 +120,17 @@ public class JavaServerDeclareCommandsTranslator extends PacketTranslator treeData = rootParam.getTree(); + CommandParamData[][] params = new CommandParamData[treeData.size()][]; // Fill the nested params array int i = 0; - for (ParamInfo parmInfo : rootParam.getChildren()) { - CommandParamData[] paramParts = new CommandParamData[1]; - paramParts[0] = parmInfo.getParamData(); - params[i] = paramParts; + for (CommandParamData[] tree : treeData) { + params[i] = tree; i++; } @@ -253,6 +252,35 @@ public class JavaServerDeclareCommandsTranslator extends PacketTranslator getTree() { + List treeParamData = new ArrayList<>(); + + for (ParamInfo child : children) { + List childTree = child.getTree(); + for (CommandParamData[] subchild : childTree) { + CommandParamData[] tmpTree = new ArrayList() { + { + add(child.getParamData()); + addAll(Arrays.asList(subchild)); + } + }.toArray(new CommandParamData[0]); + + treeParamData.add(tmpTree); + } + + if (childTree.size() == 0) { + treeParamData.add(new CommandParamData[] { child.getParamData() }); + } + } + + return treeParamData; } } }