diff --git a/src/main/java/net/minestom/server/command/builder/CommandResult.java b/src/main/java/net/minestom/server/command/builder/CommandResult.java index 84fcbcbe3..5eeed6a72 100644 --- a/src/main/java/net/minestom/server/command/builder/CommandResult.java +++ b/src/main/java/net/minestom/server/command/builder/CommandResult.java @@ -10,23 +10,19 @@ public class CommandResult { protected ParsedCommand parsedCommand; protected CommandData commandData; - @NotNull - public Type getType() { + public @NotNull Type getType() { return type; } - @NotNull - public String getInput() { + public @NotNull String getInput() { return input; } - @Nullable - public ParsedCommand getParsedCommand() { + public @Nullable ParsedCommand getParsedCommand() { return parsedCommand; } - @Nullable - public CommandData getCommandData() { + public @Nullable CommandData getCommandData() { return commandData; } @@ -35,30 +31,25 @@ public class CommandResult { * Command and syntax successfully found. */ SUCCESS, - /** * Command found, but the syntax is invalid. * Executor sets to {@link Command#getDefaultExecutor()}. */ INVALID_SYNTAX, - /** * Command cancelled by an event listener. */ CANCELLED, - /** * Command is not registered, it is also the default result type. */ UNKNOWN } - @NotNull - public static CommandResult of(@NotNull Type type, @NotNull String input) { + public static @NotNull CommandResult of(@NotNull Type type, @NotNull String input) { CommandResult result = new CommandResult(); result.type = type; result.input = input; return result; } - } 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 496f4023b..e22e5d985 100644 --- a/src/main/java/net/minestom/server/command/builder/ParsedCommand.java +++ b/src/main/java/net/minestom/server/command/builder/ParsedCommand.java @@ -7,6 +7,8 @@ import net.minestom.server.command.builder.exception.ArgumentSyntaxException; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.Objects; + /** * Represents a {@link Command} ready to be executed (already parsed). */ @@ -35,10 +37,9 @@ public class ParsedCommand { * @param source the command source * @return the command data, null if none */ - @Nullable - public CommandData execute(@NotNull CommandSender source) { + public @Nullable CommandData execute(@NotNull CommandSender source) { // Global listener - command.globalListener(source, context, commandString); + command.globalListener(source, Objects.requireNonNullElseGet(context, () -> new CommandContext(commandString)), commandString); // Command condition check final CommandCondition condition = command.getCondition(); if (condition != null) { @@ -83,8 +84,7 @@ public class ParsedCommand { return context.getReturnData(); } - @NotNull - public static ParsedCommand withDefaultExecutor(@NotNull Command command, @NotNull String input) { + public static @NotNull ParsedCommand withDefaultExecutor(@NotNull Command command, @NotNull String input) { ParsedCommand parsedCommand = new ParsedCommand(); parsedCommand.command = command; parsedCommand.commandString = input; @@ -92,5 +92,4 @@ public class ParsedCommand { parsedCommand.context = new CommandContext(input); return parsedCommand; } - }