mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-22 08:02:31 +01:00
Revert to check shared command arguments
This commit is contained in:
parent
ff3888d972
commit
99be06f571
@ -432,6 +432,11 @@ public final class CommandManager {
|
||||
|
||||
final int literalNodeId = addCommandNameNode(literalNode, rootChildren, nodes);
|
||||
|
||||
// Contains the arguments of the already-parsed syntaxes
|
||||
List<Argument<?>[]> syntaxesArguments = new ArrayList<>();
|
||||
// Contains the nodes of an argument
|
||||
Map<Argument<?>, List<DeclareCommandsPacket.Node[]>> storedArgumentsNodes = new HashMap<>();
|
||||
|
||||
// Sort syntaxes by argument count. Brigadier requires it.
|
||||
syntaxes = syntaxes.stream().sorted(Comparator.comparingInt(o -> -o.getArguments().length)).collect(Collectors.toList());
|
||||
for (CommandSyntax syntax : syntaxes) {
|
||||
@ -455,12 +460,33 @@ public final class CommandManager {
|
||||
final Argument<?> argument = arguments[i];
|
||||
final boolean isLast = i == arguments.length - 1;
|
||||
|
||||
// Search previously parsed syntaxes to find identical part in order to create a node between those
|
||||
{
|
||||
// Find shared part
|
||||
boolean foundSharedPart = false;
|
||||
for (Argument<?>[] parsedArguments : syntaxesArguments) {
|
||||
final int index = i + 1;
|
||||
if (ArrayUtils.sameStart(arguments, parsedArguments, index)) {
|
||||
final Argument<?> sharedArgument = parsedArguments[i];
|
||||
final List<DeclareCommandsPacket.Node[]> storedNodes = storedArgumentsNodes.get(sharedArgument);
|
||||
|
||||
argChildren = new IntArrayList();
|
||||
lastNodes = storedNodes.get(index);
|
||||
foundSharedPart = true;
|
||||
}
|
||||
}
|
||||
if (foundSharedPart) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// Process the nodes for the argument
|
||||
{
|
||||
argument.processNodes(nodeMaker, isLast);
|
||||
|
||||
// Each node array represent a layer
|
||||
final List<DeclareCommandsPacket.Node[]> nodesLayer = nodeMaker.getNodes();
|
||||
storedArgumentsNodes.put(argument, nodesLayer);
|
||||
for (int nodeIndex = lastArgumentNodeIndex; nodeIndex < nodesLayer.size(); nodeIndex++) {
|
||||
final NodeMaker.ConfiguredNodes configuredNodes = nodeMaker.getConfiguredNodes().get(nodeIndex);
|
||||
final NodeMaker.Options options = configuredNodes.getOptions();
|
||||
@ -497,6 +523,7 @@ public final class CommandManager {
|
||||
lastArgumentNodeIndex = nodesLayer.size();
|
||||
}
|
||||
}
|
||||
syntaxesArguments.add(arguments);
|
||||
}
|
||||
|
||||
literalNode.children = ArrayUtils.toArray(cmdChildren);
|
||||
|
Loading…
Reference in New Issue
Block a user