mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-24 09:01:54 +01:00
ArgumentLoop cleanup
This commit is contained in:
parent
e0d0c14933
commit
df2ee23a7c
@ -414,7 +414,7 @@ public final class CommandManager {
|
|||||||
|
|
||||||
DeclareCommandsPacket.Node literalNode = createMainNode(name, syntaxes.isEmpty());
|
DeclareCommandsPacket.Node literalNode = createMainNode(name, syntaxes.isEmpty());
|
||||||
|
|
||||||
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<>();
|
List<Argument<?>[]> syntaxesArguments = new ArrayList<>();
|
||||||
@ -434,7 +434,7 @@ public final class CommandManager {
|
|||||||
// Represent the children of the last node
|
// Represent the children of the last node
|
||||||
IntList argChildren = cmdChildren;
|
IntList argChildren = cmdChildren;
|
||||||
|
|
||||||
NodeMaker nodeMaker = new NodeMaker(lastNodes);
|
NodeMaker nodeMaker = new NodeMaker(lastNodes, literalNodeId);
|
||||||
int lastArgumentNodeIndex = nodeMaker.getNodesCount();
|
int lastArgumentNodeIndex = nodeMaker.getNodesCount();
|
||||||
|
|
||||||
final Argument<?>[] arguments = syntax.getArguments();
|
final Argument<?>[] arguments = syntax.getArguments();
|
||||||
@ -525,10 +525,12 @@ public final class CommandManager {
|
|||||||
return literalNode;
|
return literalNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addCommandNameNode(@NotNull DeclareCommandsPacket.Node commandNode,
|
private int addCommandNameNode(@NotNull DeclareCommandsPacket.Node commandNode,
|
||||||
@NotNull IntList rootChildren,
|
@NotNull IntList rootChildren,
|
||||||
@NotNull List<DeclareCommandsPacket.Node> nodes) {
|
@NotNull List<DeclareCommandsPacket.Node> nodes) {
|
||||||
rootChildren.add(nodes.size());
|
final int node = nodes.size();
|
||||||
|
rootChildren.add(node);
|
||||||
nodes.add(commandNode);
|
nodes.add(commandNode);
|
||||||
|
return node;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,8 +18,11 @@ public class NodeMaker {
|
|||||||
private Rule rule;
|
private Rule rule;
|
||||||
private int ruleCount;
|
private int ruleCount;
|
||||||
|
|
||||||
public NodeMaker(@NotNull DeclareCommandsPacket.Node[] commandNodes){
|
public NodeMaker(@NotNull DeclareCommandsPacket.Node[] commandNodes, int id) {
|
||||||
addNodes(commandNodes);
|
addNodes(commandNodes);
|
||||||
|
for (DeclareCommandsPacket.Node node : commandNodes) {
|
||||||
|
this.nodeIdsMap.put(node, id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfiguredNodes getLatestConfiguredNodes() {
|
public ConfiguredNodes getLatestConfiguredNodes() {
|
||||||
|
@ -66,12 +66,11 @@ public class ArgumentLoop<T> extends Argument<List<T>> {
|
|||||||
final int id = nodeMaker.getNodeIdsMap().getInt(latestNode);
|
final int id = nodeMaker.getNodeIdsMap().getInt(latestNode);
|
||||||
|
|
||||||
for (Argument<T> argument : arguments) {
|
for (Argument<T> argument : arguments) {
|
||||||
DeclareCommandsPacket.Node[] latestCache = nodeMaker.getLatestNodes();
|
|
||||||
argument.processNodes(nodeMaker, executable);
|
argument.processNodes(nodeMaker, executable);
|
||||||
|
|
||||||
NodeMaker.ConfiguredNodes configuredNodes = nodeMaker.getLatestConfiguredNodes();
|
NodeMaker.ConfiguredNodes configuredNodes = nodeMaker.getLatestConfiguredNodes();
|
||||||
// For the next loop argument to start at the same place
|
// For the next loop argument to start at the same place
|
||||||
configuredNodes.getOptions().setPreviousNodes(latestCache);
|
configuredNodes.getOptions().setPreviousNodes(latestNodes);
|
||||||
for (DeclareCommandsPacket.Node lastArgumentNode : configuredNodes.getNodes()) {
|
for (DeclareCommandsPacket.Node lastArgumentNode : configuredNodes.getNodes()) {
|
||||||
lastArgumentNode.flags |= 0x08;
|
lastArgumentNode.flags |= 0x08;
|
||||||
lastArgumentNode.redirectedNode = id;
|
lastArgumentNode.redirectedNode = id;
|
||||||
|
Loading…
Reference in New Issue
Block a user