mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-24 09:01:54 +01:00
Fix command aliases + cleanup
This commit is contained in:
parent
f0105d7058
commit
84da72d798
@ -320,19 +320,22 @@ public final class CommandManager {
|
|||||||
final Collection<CommandSyntax> syntaxes = command.getSyntaxes();
|
final Collection<CommandSyntax> syntaxes = command.getSyntaxes();
|
||||||
|
|
||||||
// Create command for main name
|
// Create command for main name
|
||||||
int mainNodeIndex = createCommand(player, nodes, cmdChildren, command.getName(), syntaxes, rootChildren);
|
final int mainNodeIndex = createCommand(player, nodes, cmdChildren,
|
||||||
|
command.getName(), syntaxes, rootChildren);
|
||||||
|
|
||||||
// Use redirection to hook aliases with the command
|
// Use redirection to hook aliases with the command
|
||||||
if (command.getAliases() == null)
|
final String[] aliases = command.getAliases();
|
||||||
|
if (aliases == null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
for (String alias : command.getAliases()) {
|
for (String alias : aliases) {
|
||||||
DeclareCommandsPacket.Node node = new DeclareCommandsPacket.Node();
|
DeclareCommandsPacket.Node aliasNode = new DeclareCommandsPacket.Node();
|
||||||
node.flags = DeclareCommandsPacket.getFlag(DeclareCommandsPacket.NodeType.LITERAL,
|
aliasNode.flags = DeclareCommandsPacket.getFlag(DeclareCommandsPacket.NodeType.LITERAL,
|
||||||
false, true, false);
|
false, true, false);
|
||||||
node.name = alias;
|
aliasNode.name = alias;
|
||||||
node.redirectedNode = mainNodeIndex;
|
aliasNode.redirectedNode = mainNodeIndex;
|
||||||
nodes.add(node);
|
|
||||||
|
addCommandNameNode(aliasNode, rootChildren, nodes);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -379,8 +382,7 @@ public final class CommandManager {
|
|||||||
literalNode.name = name;
|
literalNode.name = name;
|
||||||
literalNode.children = new int[]{nodes.size() - 1};
|
literalNode.children = new int[]{nodes.size() - 1};
|
||||||
|
|
||||||
rootChildren.add(nodes.size());
|
addCommandNameNode(literalNode, rootChildren, nodes);
|
||||||
nodes.add(literalNode);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add root node children
|
// Add root node children
|
||||||
@ -412,8 +414,7 @@ public final class CommandManager {
|
|||||||
|
|
||||||
DeclareCommandsPacket.Node literalNode = createMainNode(name, syntaxes.isEmpty());
|
DeclareCommandsPacket.Node literalNode = createMainNode(name, syntaxes.isEmpty());
|
||||||
|
|
||||||
rootChildren.add(nodes.size());
|
addCommandNameNode(literalNode, rootChildren, nodes);
|
||||||
nodes.add(literalNode);
|
|
||||||
|
|
||||||
// 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<>();
|
||||||
@ -427,15 +428,14 @@ public final class CommandManager {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeMaker nodeMaker = new NodeMaker();
|
|
||||||
|
|
||||||
// Represent the last nodes computed in the last iteration
|
// Represent the last nodes computed in the last iteration
|
||||||
DeclareCommandsPacket.Node[] lastNodes = new DeclareCommandsPacket.Node[]{literalNode};
|
DeclareCommandsPacket.Node[] lastNodes = new DeclareCommandsPacket.Node[]{literalNode};
|
||||||
|
|
||||||
// Represent the children of the last node
|
// Represent the children of the last node
|
||||||
IntList argChildren = cmdChildren;
|
IntList argChildren = cmdChildren;
|
||||||
|
|
||||||
int lastArgumentNodeIndex = 0;
|
NodeMaker nodeMaker = new NodeMaker(lastNodes);
|
||||||
|
int lastArgumentNodeIndex = nodeMaker.getNodesCount();
|
||||||
|
|
||||||
final Argument<?>[] arguments = syntax.getArguments();
|
final Argument<?>[] arguments = syntax.getArguments();
|
||||||
for (int i = 0; i < arguments.length; i++) {
|
for (int i = 0; i < arguments.length; i++) {
|
||||||
@ -508,12 +508,8 @@ public final class CommandManager {
|
|||||||
syntaxesArguments.add(arguments);
|
syntaxesArguments.add(arguments);
|
||||||
|
|
||||||
}
|
}
|
||||||
final int[] children = ArrayUtils.toArray(cmdChildren);
|
|
||||||
//System.out.println("test " + children.length + " : " + children[0]);
|
literalNode.children = ArrayUtils.toArray(cmdChildren);
|
||||||
literalNode.children = children;
|
|
||||||
if (children.length > 0) {
|
|
||||||
literalNode.redirectedNode = children[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
return nodes.indexOf(literalNode);
|
return nodes.indexOf(literalNode);
|
||||||
|
|
||||||
@ -527,4 +523,11 @@ public final class CommandManager {
|
|||||||
|
|
||||||
return literalNode;
|
return literalNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void addCommandNameNode(@NotNull DeclareCommandsPacket.Node commandNode,
|
||||||
|
@NotNull IntList rootChildren,
|
||||||
|
@NotNull List<DeclareCommandsPacket.Node> nodes) {
|
||||||
|
rootChildren.add(nodes.size());
|
||||||
|
nodes.add(commandNode);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,10 @@ public class NodeMaker {
|
|||||||
private Rule rule;
|
private Rule rule;
|
||||||
private int ruleCount;
|
private int ruleCount;
|
||||||
|
|
||||||
|
public NodeMaker(@NotNull DeclareCommandsPacket.Node[] commandNodes){
|
||||||
|
addNodes(commandNodes);
|
||||||
|
}
|
||||||
|
|
||||||
public ConfiguredNodes getLatestConfiguredNodes() {
|
public ConfiguredNodes getLatestConfiguredNodes() {
|
||||||
if (configuredNodes.isEmpty())
|
if (configuredNodes.isEmpty())
|
||||||
return null;
|
return null;
|
||||||
@ -29,6 +33,10 @@ public class NodeMaker {
|
|||||||
return configuredNodes != null ? configuredNodes.nodes : null;
|
return configuredNodes != null ? configuredNodes.nodes : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getNodesCount() {
|
||||||
|
return nodes.size();
|
||||||
|
}
|
||||||
|
|
||||||
public void addNodes(@NotNull DeclareCommandsPacket.Node[] nodes) {
|
public void addNodes(@NotNull DeclareCommandsPacket.Node[] nodes) {
|
||||||
Options options = null;
|
Options options = null;
|
||||||
if (rule != null) {
|
if (rule != null) {
|
||||||
|
Loading…
Reference in New Issue
Block a user