From 967ee4f58d9f4515ea71844fea6b5033085542af Mon Sep 17 00:00:00 2001 From: Camotoy <20743703+Camotoy@users.noreply.github.com> Date: Mon, 13 Dec 2021 22:25:08 -0500 Subject: [PATCH] Fix command descriptions merging --- .../protocol/java/JavaCommandsTranslator.java | 35 ++++++++++++------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/JavaCommandsTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/JavaCommandsTranslator.java index d0ab68d8f..5e918d5d3 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/JavaCommandsTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/JavaCommandsTranslator.java @@ -43,6 +43,7 @@ import lombok.Getter; import lombok.ToString; import net.kyori.adventure.text.format.NamedTextColor; import org.geysermc.geyser.GeyserImpl; +import org.geysermc.geyser.command.CommandManager; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.translator.protocol.PacketTranslator; import org.geysermc.geyser.translator.protocol.Translator; @@ -61,20 +62,22 @@ public class JavaCommandsTranslator extends PacketTranslator PARAM_STRATEGY = new Hash.Strategy<>() { + private static final Hash.Strategy PARAM_STRATEGY = new Hash.Strategy<>() { @Override - public int hashCode(CommandParamData[][] o) { - return Arrays.deepHashCode(o); + public int hashCode(BedrockCommandInfo o) { + int paramHash = Arrays.deepHashCode(o.paramData()); + return 31 * paramHash + o.description().hashCode(); } @Override - public boolean equals(CommandParamData[][] a, CommandParamData[][] b) { + public boolean equals(BedrockCommandInfo a, BedrockCommandInfo b) { if (a == b) return true; if (a == null || b == null) return false; - if (a.length != b.length) return false; - for (int i = 0; i < a.length; i++) { - CommandParamData[] a1 = a[i]; - CommandParamData[] b1 = b[i]; + if (!a.description().equals(b.description())) return false; + if (a.paramData().length != b.paramData().length) return false; + for (int i = 0; i < a.paramData().length; i++) { + CommandParamData[] a1 = a.paramData()[i]; + CommandParamData[] b1 = b.paramData()[i]; if (a1.length != b1.length) return false; for (int j = 0; j < a1.length; j++) { @@ -109,11 +112,12 @@ public class JavaCommandsTranslator extends PacketTranslator commandData = new ArrayList<>(); IntSet commandNodes = new IntOpenHashSet(); Set knownAliases = new HashSet<>(); - Map> commands = new Object2ObjectOpenCustomHashMap<>(PARAM_STRATEGY); + Map> commands = new Object2ObjectOpenCustomHashMap<>(PARAM_STRATEGY); Int2ObjectMap> commandArgs = new Int2ObjectOpenHashMap<>(); // Get the first node, it should be a root node @@ -137,7 +141,8 @@ public class JavaCommandsTranslator extends PacketTranslator new HashSet<>()).add(node.getName().toLowerCase()); + commands.computeIfAbsent(new BedrockCommandInfo(manager.getDescription(node.getName().toLowerCase(Locale.ROOT)), params), + index -> new HashSet<>()).add(node.getName().toLowerCase()); } // The command flags, not sure what these do apart from break things @@ -145,14 +150,14 @@ public class JavaCommandsTranslator extends PacketTranslator> entry : commands.entrySet()) { + for (Map.Entry> entry : commands.entrySet()) { String commandName = entry.getValue().iterator().next(); // We know this has a value // Create a basic alias CommandEnumData aliases = new CommandEnumData(commandName + "Aliases", entry.getValue().toArray(new String[0]), false); // Build the completed command and add it to the final list - CommandData data = new CommandData(commandName, session.getGeyser().getCommandManager().getDescription(commandName), flags, (byte) 0, aliases, entry.getKey()); + CommandData data = new CommandData(commandName, entry.getKey().description(), flags, (byte) 0, aliases, entry.getKey().paramData()); commandData.add(data); } @@ -228,6 +233,12 @@ public class JavaCommandsTranslator extends PacketTranslator