mirror of
https://github.com/Minestom/Minestom.git
synced 2024-11-12 13:44:28 +01:00
Fix context being null in globalListener
This commit is contained in:
parent
129a39fc3d
commit
93fc7235e0
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user