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