From f44920103375903b8a59514cb6ba6259a10eda05 Mon Sep 17 00:00:00 2001 From: themode Date: Wed, 17 Mar 2021 05:06:09 +0100 Subject: [PATCH] Remove the need for the command string in ParsedCommand --- .../minestom/server/command/builder/CommandDispatcher.java | 3 ++- .../net/minestom/server/command/builder/ParsedCommand.java | 7 ++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/minestom/server/command/builder/CommandDispatcher.java b/src/main/java/net/minestom/server/command/builder/CommandDispatcher.java index a60560d2e..3212c0b5d 100644 --- a/src/main/java/net/minestom/server/command/builder/CommandDispatcher.java +++ b/src/main/java/net/minestom/server/command/builder/CommandDispatcher.java @@ -91,7 +91,7 @@ public class CommandDispatcher { CommandResult commandResult = parse(commandString); ParsedCommand parsedCommand = commandResult.parsedCommand; if (parsedCommand != null) { - commandResult.commandData = parsedCommand.execute(source, commandString); + commandResult.commandData = parsedCommand.execute(source); } return commandResult; } @@ -162,6 +162,7 @@ public class CommandDispatcher { ParsedCommand parsedCommand = new ParsedCommand(); parsedCommand.command = command; + parsedCommand.commandString = commandString; // The default executor should be used if no argument is provided { diff --git a/src/main/java/net/minestom/server/command/builder/ParsedCommand.java b/src/main/java/net/minestom/server/command/builder/ParsedCommand.java index 4a1f09492..cc3059af2 100644 --- a/src/main/java/net/minestom/server/command/builder/ParsedCommand.java +++ b/src/main/java/net/minestom/server/command/builder/ParsedCommand.java @@ -13,6 +13,7 @@ public class ParsedCommand { // Command protected Command command; + protected String commandString; // Command Executor protected CommandSyntax syntax; @@ -30,12 +31,11 @@ public class ParsedCommand { * The command will not be executed if {@link Command#getCondition()} * is not validated. * - * @param source the command source - * @param commandString the command string + * @param source the command source * @return the command data, null if none */ @Nullable - public CommandData execute(@NotNull CommandSender source, @NotNull String commandString) { + public CommandData execute(@NotNull CommandSender source) { // Global listener command.globalListener(source, context, commandString); // Command condition check @@ -78,6 +78,7 @@ public class ParsedCommand { public static ParsedCommand withDefaultExecutor(@NotNull Command command, @NotNull String input) { ParsedCommand parsedCommand = new ParsedCommand(); parsedCommand.command = command; + parsedCommand.commandString = input; parsedCommand.executor = command.getDefaultExecutor(); parsedCommand.context = new CommandContext(input); return parsedCommand;