mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-20 15:11:22 +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);
|
NodeResult result = parseNode(parent, chain, reader);
|
||||||
chain = result.chain;
|
chain = result.chain;
|
||||||
if (result.argumentResult instanceof ArgumentResult.Success<?>) {
|
|
||||||
NodeResult lastNodeResult = chain.nodeResults.peekLast();
|
NodeResult lastNodeResult = chain.nodeResults.peekLast();
|
||||||
|
if (lastNodeResult == null) return UnknownCommandResult.INSTANCE;
|
||||||
Node lastNode = lastNodeResult.node;
|
Node lastNode = lastNodeResult.node;
|
||||||
|
|
||||||
|
if (result.argumentResult instanceof ArgumentResult.Success<?>) {
|
||||||
CommandExecutor executor = nullSafeGetter(lastNode.execution(), Graph.Execution::executor);
|
CommandExecutor executor = nullSafeGetter(lastNode.execution(), Graph.Execution::executor);
|
||||||
if (executor != null) return ValidCommand.executor(input, chain, executor);
|
if (executor != null) return ValidCommand.executor(input, chain, executor);
|
||||||
}
|
}
|
||||||
// If here, then the command failed or didn't have an 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
|
// Look for a default executor, or give up if we got nowhere
|
||||||
NodeResult lastNode = chain.nodeResults.peekLast();
|
if (lastNode.equals(parent)) return UnknownCommandResult.INSTANCE;
|
||||||
if (lastNode.node.equals(parent)) return UnknownCommandResult.INSTANCE;
|
|
||||||
if (chain.defaultExecutor != null) {
|
if (chain.defaultExecutor != null) {
|
||||||
return ValidCommand.defaultExecutor(input, chain);
|
return ValidCommand.defaultExecutor(input, chain);
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,12 @@ import static org.junit.jupiter.api.Assertions.*;
|
|||||||
|
|
||||||
public class CommandParseTest {
|
public class CommandParseTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void emptyCommand() {
|
||||||
|
var graph = Graph.merge(Graph.builder(Literal("foo"), createExecutor(new AtomicBoolean())).build());
|
||||||
|
assertUnknown(graph, "");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void singleParameterlessCommand() {
|
public void singleParameterlessCommand() {
|
||||||
final AtomicBoolean b = new AtomicBoolean();
|
final AtomicBoolean b = new AtomicBoolean();
|
||||||
|
Loading…
Reference in New Issue
Block a user