mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-20 07:02:32 +01:00
Fix empty command chain causing NullPointerException (#1931)
* Fix empty command chain causing NullPointerException * Add test for empty command input
This commit is contained in:
parent
2b8beadd3e
commit
3645d4311d
@ -101,18 +101,19 @@ final class CommandParserImpl implements CommandParser {
|
||||
|
||||
NodeResult result = parseNode(parent, chain, reader);
|
||||
chain = result.chain;
|
||||
if (result.argumentResult instanceof ArgumentResult.Success<?>) {
|
||||
NodeResult lastNodeResult = chain.nodeResults.peekLast();
|
||||
Node lastNode = lastNodeResult.node;
|
||||
|
||||
NodeResult lastNodeResult = chain.nodeResults.peekLast();
|
||||
if (lastNodeResult == null) return UnknownCommandResult.INSTANCE;
|
||||
Node lastNode = lastNodeResult.node;
|
||||
|
||||
if (result.argumentResult instanceof ArgumentResult.Success<?>) {
|
||||
CommandExecutor executor = nullSafeGetter(lastNode.execution(), Graph.Execution::executor);
|
||||
if (executor != null) return ValidCommand.executor(input, chain, executor);
|
||||
}
|
||||
// If here, then the command failed or didn't have an executor
|
||||
|
||||
// Look for a default executor, or give up if we got nowhere
|
||||
NodeResult lastNode = chain.nodeResults.peekLast();
|
||||
if (lastNode.node.equals(parent)) return UnknownCommandResult.INSTANCE;
|
||||
if (lastNode.equals(parent)) return UnknownCommandResult.INSTANCE;
|
||||
if (chain.defaultExecutor != null) {
|
||||
return ValidCommand.defaultExecutor(input, chain);
|
||||
}
|
||||
|
@ -13,6 +13,12 @@ import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class CommandParseTest {
|
||||
|
||||
@Test
|
||||
public void emptyCommand() {
|
||||
var graph = Graph.merge(Graph.builder(Literal("foo"), createExecutor(new AtomicBoolean())).build());
|
||||
assertUnknown(graph, "");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void singleParameterlessCommand() {
|
||||
final AtomicBoolean b = new AtomicBoolean();
|
||||
|
Loading…
Reference in New Issue
Block a user