Fix command name recursion

This commit is contained in:
themode 2021-03-21 09:09:32 +01:00
parent cd273b4d99
commit 3e3cb4b213

View File

@ -20,8 +20,8 @@ public class CommandParser {
private static final CommandManager COMMAND_MANAGER = MinecraftServer.getCommandManager(); private static final CommandManager COMMAND_MANAGER = MinecraftServer.getCommandManager();
@Nullable @Nullable
public static CommandQueryResult findCommand(@NotNull String commandName, @NotNull String[] args) { public static CommandQueryResult findCommand(@Nullable Command parentCommand, @NotNull String commandName, @NotNull String[] args) {
Command command = COMMAND_MANAGER.getDispatcher().findCommand(commandName); Command command = parentCommand == null ? COMMAND_MANAGER.getDispatcher().findCommand(commandName) : parentCommand;
if (command == null) { if (command == null) {
return null; return null;
} }
@ -31,21 +31,18 @@ public class CommandParser {
commandQueryResult.commandName = commandName; commandQueryResult.commandName = commandName;
commandQueryResult.args = args; commandQueryResult.args = args;
boolean correct; if (commandQueryResult.args.length > 0) {
do { final String subCommandName = commandQueryResult.args[0];
correct = false; for (Command subcommand : command.getSubcommands()) {
if (Command.isValidName(subcommand, subCommandName)) {
if (commandQueryResult.args.length > 0) { final String[] subArgs = Arrays.copyOfRange(args, 1, args.length);
final String firstArgument = commandQueryResult.args[0]; commandQueryResult.command = subcommand;
for (Command subcommand : command.getSubcommands()) { commandQueryResult.commandName = subCommandName;
if ((correct = Command.isValidName(subcommand, firstArgument))) { commandQueryResult.args = subArgs;
commandQueryResult.command = subcommand; return findCommand(subcommand, subCommandName, subArgs);
commandQueryResult.commandName = firstArgument;
commandQueryResult.args = Arrays.copyOfRange(args, 1, args.length);
}
} }
} }
} while (correct); }
return commandQueryResult; return commandQueryResult;
} }
@ -57,7 +54,7 @@ public class CommandParser {
String[] args = new String[parts.length - 1]; String[] args = new String[parts.length - 1];
System.arraycopy(parts, 1, args, 0, args.length); System.arraycopy(parts, 1, args, 0, args.length);
return CommandParser.findCommand(commandName, args); return CommandParser.findCommand(null, commandName, args);
} }
public static void parse(@Nullable CommandSyntax syntax, @NotNull Argument<?>[] commandArguments, @NotNull String[] inputArguments, public static void parse(@Nullable CommandSyntax syntax, @NotNull Argument<?>[] commandArguments, @NotNull String[] inputArguments,