Fix CommandDispatcher#findCommandResult never returning null, + cleanup

This commit is contained in:
themode 2021-02-11 00:33:55 +01:00
parent 266c4d9bed
commit dffb90e1b4

View File

@ -94,7 +94,7 @@ public class CommandDispatcher {
// Find the used syntax // Find the used syntax
CommandResult result = new CommandResult(); CommandResult result = new CommandResult();
ParsedCommand parsedCommand = findCommandResult(command, args); ParsedCommand parsedCommand = findParsedCommand(command, args);
if (parsedCommand != null) { if (parsedCommand != null) {
// Syntax found // Syntax found
result.type = CommandResult.Type.SUCCESS; result.type = CommandResult.Type.SUCCESS;
@ -125,18 +125,16 @@ public class CommandDispatcher {
} }
@Nullable @Nullable
private ParsedCommand findCommandResult(@NotNull Command command, @NotNull String[] args) { private ParsedCommand findParsedCommand(@NotNull Command command, @NotNull String[] args) {
ParsedCommand parsedCommand = new ParsedCommand(); ParsedCommand parsedCommand = new ParsedCommand();
parsedCommand.command = command; parsedCommand.command = command;
Arguments executorArgs = new Arguments();
// The default executor should be used if no argument is provided // The default executor should be used if no argument is provided
{ {
final CommandExecutor defaultExecutor = command.getDefaultExecutor(); final CommandExecutor defaultExecutor = command.getDefaultExecutor();
if (defaultExecutor != null && args[0].length() == 0) { if (defaultExecutor != null && args[0].length() == 0) {
parsedCommand.executor = defaultExecutor; parsedCommand.executor = defaultExecutor;
parsedCommand.arguments = executorArgs; parsedCommand.arguments = new Arguments();
return parsedCommand; return parsedCommand;
} }
} }
@ -262,6 +260,7 @@ public class CommandDispatcher {
// Check if there is at least one correct syntax // Check if there is at least one correct syntax
if (!validSyntaxes.isEmpty()) { if (!validSyntaxes.isEmpty()) {
Arguments executorArgs = new Arguments();
// Search the syntax with all perfect args // Search the syntax with all perfect args
final CommandSyntax finalSyntax = findMostCorrectSyntax(validSyntaxes, executorArgs); final CommandSyntax finalSyntax = findMostCorrectSyntax(validSyntaxes, executorArgs);
if (finalSyntax != null) { if (finalSyntax != null) {
@ -295,11 +294,8 @@ public class CommandDispatcher {
} }
} }
// Use the default executor at last resort // No syntax found
parsedCommand.executor = command.getDefaultExecutor(); return null;
parsedCommand.arguments = executorArgs;
return parsedCommand;
} }
/** /**