mirror of
https://github.com/Minestom/Minestom.git
synced 2024-09-27 06:03:01 +02:00
Use redirection for aliases instead of repetition
This commit is contained in:
parent
6b4c514254
commit
3d74e74b9e
3
.gitignore
vendored
3
.gitignore
vendored
@ -55,4 +55,5 @@ gradle-app.setting
|
|||||||
/extensions/
|
/extensions/
|
||||||
|
|
||||||
# When compiling we get a docs folder
|
# When compiling we get a docs folder
|
||||||
/docs
|
/docs
|
||||||
|
.mixin.out/
|
||||||
|
@ -312,11 +312,15 @@ 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
|
||||||
createCommand(player, nodes, cmdChildren, command.getName(), syntaxes, rootChildren);
|
int mainNodeIndex = createCommand(player, nodes, cmdChildren, command.getName(), syntaxes, rootChildren);
|
||||||
|
|
||||||
// Repeat that for all aliases.
|
// Use redirection to hook aliases with the command
|
||||||
for (String alias : command.getAliases()) {
|
for (String alias : command.getAliases()) {
|
||||||
createCommand(player, nodes, cmdChildren, alias, syntaxes, rootChildren);
|
DeclareCommandsPacket.Node node = new DeclareCommandsPacket.Node();
|
||||||
|
node.flags = getFlag(NodeType.LITERAL, false, true, false);
|
||||||
|
node.name = alias;
|
||||||
|
node.redirectedNode = mainNodeIndex;
|
||||||
|
nodes.add(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -386,8 +390,10 @@ public final class CommandManager {
|
|||||||
* @param name the name of the command (or the alias)
|
* @param name the name of the command (or the alias)
|
||||||
* @param syntaxes the syntaxes of the command
|
* @param syntaxes the syntaxes of the command
|
||||||
* @param rootChildren the children of the main node (all commands name)
|
* @param rootChildren the children of the main node (all commands name)
|
||||||
|
*
|
||||||
|
* @return The index of the main node for alias redirection
|
||||||
*/
|
*/
|
||||||
private void createCommand(@NotNull CommandSender sender,
|
private int createCommand(@NotNull CommandSender sender,
|
||||||
@NotNull List<DeclareCommandsPacket.Node> nodes,
|
@NotNull List<DeclareCommandsPacket.Node> nodes,
|
||||||
@NotNull IntList cmdChildren,
|
@NotNull IntList cmdChildren,
|
||||||
@NotNull String name,
|
@NotNull String name,
|
||||||
@ -493,6 +499,9 @@ public final class CommandManager {
|
|||||||
if (children.length > 0) {
|
if (children.length > 0) {
|
||||||
literalNode.redirectedNode = children[0];
|
literalNode.redirectedNode = children[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return nodes.indexOf(literalNode);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
Loading…
Reference in New Issue
Block a user