mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-04 23:47:59 +01:00
Potentially fix command node creation
This commit is contained in:
parent
93fa65f90b
commit
97104df793
@ -316,9 +316,9 @@ public final class CommandManager {
|
|||||||
final int literalNodeId = addCommandNameNode(literalNode, rootChildren, nodes);
|
final int literalNodeId = addCommandNameNode(literalNode, rootChildren, nodes);
|
||||||
|
|
||||||
// Contains the arguments of the already-parsed syntaxes
|
// Contains the arguments of the already-parsed syntaxes
|
||||||
List<Argument<?>[]> syntaxesArguments = new ArrayList<>();
|
Map<CommandSyntax, Argument<?>[]> syntaxesArguments = new HashMap<>();
|
||||||
// Contains the nodes of an argument
|
// Contains the nodes of an argument
|
||||||
Map<Argument<?>, List<DeclareCommandsPacket.Node[]>> storedArgumentsNodes = new HashMap<>();
|
Map<IndexedArgument, List<DeclareCommandsPacket.Node[]>> storedArgumentsNodes = new HashMap<>();
|
||||||
|
|
||||||
// Sort syntaxes by argument count. Brigadier requires it.
|
// Sort syntaxes by argument count. Brigadier requires it.
|
||||||
syntaxes = syntaxes.stream().sorted(Comparator.comparingInt(o -> -o.getArguments().length)).collect(Collectors.toList());
|
syntaxes = syntaxes.stream().sorted(Comparator.comparingInt(o -> -o.getArguments().length)).collect(Collectors.toList());
|
||||||
@ -347,14 +347,16 @@ public final class CommandManager {
|
|||||||
{
|
{
|
||||||
// Find shared part
|
// Find shared part
|
||||||
boolean foundSharedPart = false;
|
boolean foundSharedPart = false;
|
||||||
for (Argument<?>[] parsedArguments : syntaxesArguments) {
|
for (var entry : syntaxesArguments.entrySet()) {
|
||||||
|
final var parsedArguments = entry.getValue();
|
||||||
final int index = i + 1;
|
final int index = i + 1;
|
||||||
if (ArrayUtils.sameStart(arguments, parsedArguments, index)) {
|
if (ArrayUtils.sameStart(arguments, parsedArguments, index)) {
|
||||||
final Argument<?> sharedArgument = parsedArguments[i];
|
final Argument<?> sharedArgument = parsedArguments[i];
|
||||||
final List<DeclareCommandsPacket.Node[]> storedNodes = storedArgumentsNodes.get(sharedArgument);
|
final var indexed = new IndexedArgument(entry.getKey(), sharedArgument, i);
|
||||||
|
final List<DeclareCommandsPacket.Node[]> storedNodes = storedArgumentsNodes.get(indexed);
|
||||||
|
|
||||||
argChildren = new IntArrayList();
|
argChildren = new IntArrayList();
|
||||||
lastNodes = storedNodes.get(storedNodes.size() > index ? index : i);
|
lastNodes = storedNodes.get(index);
|
||||||
foundSharedPart = true;
|
foundSharedPart = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -369,7 +371,7 @@ public final class CommandManager {
|
|||||||
|
|
||||||
// Each node array represent a layer
|
// Each node array represent a layer
|
||||||
final List<DeclareCommandsPacket.Node[]> nodesLayer = nodeMaker.getNodes();
|
final List<DeclareCommandsPacket.Node[]> nodesLayer = nodeMaker.getNodes();
|
||||||
storedArgumentsNodes.put(argument, new ArrayList<>(nodesLayer));
|
storedArgumentsNodes.put(new IndexedArgument(syntax, argument, i), new ArrayList<>(nodesLayer));
|
||||||
for (int nodeIndex = lastArgumentNodeIndex; nodeIndex < nodesLayer.size(); nodeIndex++) {
|
for (int nodeIndex = lastArgumentNodeIndex; nodeIndex < nodesLayer.size(); nodeIndex++) {
|
||||||
final NodeMaker.ConfiguredNodes configuredNodes = nodeMaker.getConfiguredNodes().get(nodeIndex);
|
final NodeMaker.ConfiguredNodes configuredNodes = nodeMaker.getConfiguredNodes().get(nodeIndex);
|
||||||
final NodeMaker.Options options = configuredNodes.getOptions();
|
final NodeMaker.Options options = configuredNodes.getOptions();
|
||||||
@ -417,17 +419,18 @@ public final class CommandManager {
|
|||||||
|
|
||||||
nodeRequests.addAll(nodeMaker.getNodeRequests());
|
nodeRequests.addAll(nodeMaker.getNodeRequests());
|
||||||
|
|
||||||
syntaxesArguments.add(arguments);
|
syntaxesArguments.put(syntax, arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
storedArgumentsNodes.forEach((argument, argNodes) -> {
|
storedArgumentsNodes.forEach((indexedArgument, argNodes) -> {
|
||||||
int value = 0;
|
int value = 0;
|
||||||
for (DeclareCommandsPacket.Node[] n1 : argNodes) {
|
for (DeclareCommandsPacket.Node[] n1 : argNodes) {
|
||||||
for (DeclareCommandsPacket.Node n2 : n1) {
|
for (DeclareCommandsPacket.Node n2 : n1) {
|
||||||
value = nodes.indexOf(n2);
|
value = nodes.indexOf(n2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
argumentIdentityMap.put(argument, value);
|
// FIXME: add syntax for indexing
|
||||||
|
argumentIdentityMap.put(indexedArgument.argument, value);
|
||||||
});
|
});
|
||||||
|
|
||||||
literalNode.children = ArrayUtils.toArray(cmdChildren);
|
literalNode.children = ArrayUtils.toArray(cmdChildren);
|
||||||
@ -451,4 +454,38 @@ public final class CommandManager {
|
|||||||
nodes.add(commandNode);
|
nodes.add(commandNode);
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class IndexedArgument {
|
||||||
|
private final CommandSyntax syntax;
|
||||||
|
private final Argument<?> argument;
|
||||||
|
private final int index;
|
||||||
|
|
||||||
|
public IndexedArgument(CommandSyntax syntax, Argument<?> argument, int index) {
|
||||||
|
this.syntax = syntax;
|
||||||
|
this.argument = argument;
|
||||||
|
this.index = index;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
IndexedArgument that = (IndexedArgument) o;
|
||||||
|
return index == that.index && Objects.equals(syntax, that.syntax) && Objects.equals(argument, that.argument);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(syntax, argument, index);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "IndexedArgument{" +
|
||||||
|
"syntax=" + syntax +
|
||||||
|
", argument=" + argument +
|
||||||
|
", index=" + index +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user