mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-27 02:21:38 +01:00
Fixed CommandManager#execute not throwing NPE
This commit is contained in:
parent
26762bec17
commit
b9a0a761c4
@ -202,27 +202,29 @@ public final class CommandManager {
|
||||
}
|
||||
|
||||
// Process the command
|
||||
try {
|
||||
|
||||
{
|
||||
// Check for rich-command
|
||||
this.dispatcher.execute(sender, command);
|
||||
return true;
|
||||
} catch (NullPointerException e) {
|
||||
// Check for legacy-command
|
||||
final String[] splitCommand = command.split(" ");
|
||||
final String commandName = splitCommand[0];
|
||||
final CommandProcessor commandProcessor = commandProcessorMap.get(commandName.toLowerCase());
|
||||
if (commandProcessor == null) {
|
||||
if (unknownCommandCallback != null) {
|
||||
this.unknownCommandCallback.apply(sender, command);
|
||||
final boolean result = this.dispatcher.execute(sender, command);
|
||||
if (result) {
|
||||
return true;
|
||||
} else {
|
||||
// Check for legacy-command
|
||||
final String[] splitCommand = command.split(" ");
|
||||
final String commandName = splitCommand[0];
|
||||
final CommandProcessor commandProcessor = commandProcessorMap.get(commandName.toLowerCase());
|
||||
if (commandProcessor == null) {
|
||||
if (unknownCommandCallback != null) {
|
||||
this.unknownCommandCallback.apply(sender, command);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
|
||||
// Execute the legacy-command
|
||||
final String[] args = command.substring(command.indexOf(" ") + 1).split(" ");
|
||||
|
||||
return commandProcessor.process(sender, commandName, args);
|
||||
}
|
||||
|
||||
// Execute the legacy-command
|
||||
final String[] args = command.substring(command.indexOf(" ") + 1).split(" ");
|
||||
|
||||
return commandProcessor.process(sender, commandName, args);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -148,7 +148,7 @@ public final class Arguments {
|
||||
public Object getObject(@NotNull String id) {
|
||||
return args.computeIfAbsent(id, s -> {
|
||||
throw new NullPointerException(
|
||||
"The argument with the id " + id + " has no value assigned, be sure to check your arguments id, your syntax, and that you do not change the argument id dynamically.");
|
||||
"The argument with the id '" + id + "' has no value assigned, be sure to check your arguments id, your syntax, and that you do not change the argument id dynamically.");
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -75,9 +75,19 @@ public class CommandDispatcher {
|
||||
return findCommandResult(command, args);
|
||||
}
|
||||
|
||||
public void execute(@NotNull CommandSender source, @NotNull String commandString) {
|
||||
/**
|
||||
* Check if the command exists, and execute it.
|
||||
*
|
||||
* @param source the command source
|
||||
* @param commandString the command with the argument(s)
|
||||
* @return true if the command executed successfully, false if the command doesn't exist
|
||||
*/
|
||||
public boolean execute(@NotNull CommandSender source, @NotNull String commandString) {
|
||||
CommandResult result = parse(commandString);
|
||||
result.execute(source, commandString);
|
||||
if (result != null) {
|
||||
result.execute(source, commandString);
|
||||
}
|
||||
return result != null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
Loading…
Reference in New Issue
Block a user