When parsing nodes, return the deepest node we went into
This commit is contained in:
@@ -21,24 +21,23 @@ public class ArgumentCommandNode<T> extends CommandNode {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void parse(String command) throws IllegalCommandArgumentException {
|
||||
public CommandNode parse(String command) throws IllegalCommandArgumentException {
|
||||
CommandArgumentType.CommandArgumentParseResult<T> parsed = type.parse(command);
|
||||
int start = parsed.getRaw().length() + 1;
|
||||
|
||||
if (start < command.length()) {
|
||||
String result = command.substring(start);
|
||||
IllegalCommandArgumentException exception = new IllegalCommandArgumentException();
|
||||
|
||||
for (CommandNode node : getChildren()) {
|
||||
try {
|
||||
node.parse(result);
|
||||
return;
|
||||
} catch (IllegalCommandArgumentException ex) {
|
||||
exception = ex;
|
||||
return node.parse(result);
|
||||
} catch (IllegalCommandArgumentException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
throw exception;
|
||||
throw new IllegalCommandArgumentException();
|
||||
} else {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,5 +16,5 @@ public abstract class CommandNode {
|
||||
children.add(node);
|
||||
}
|
||||
|
||||
public abstract void parse(String command) throws IllegalCommandArgumentException;
|
||||
public abstract CommandNode parse(String command) throws IllegalCommandArgumentException;
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ public class LiteralCommandNode extends CommandNode {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void parse(String command) throws IllegalCommandArgumentException {
|
||||
public CommandNode parse(String command) throws IllegalCommandArgumentException {
|
||||
if (command.startsWith(literal)) {
|
||||
int start = literal.length() + 1;
|
||||
|
||||
@@ -28,11 +28,15 @@ public class LiteralCommandNode extends CommandNode {
|
||||
String result = command.substring(start);
|
||||
|
||||
for (CommandNode node : getChildren()) {
|
||||
node.parse(result);
|
||||
return;
|
||||
try {
|
||||
return node.parse(result);
|
||||
} catch (IllegalCommandArgumentException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
throw new IllegalCommandArgumentException();
|
||||
} else {
|
||||
return this;
|
||||
}
|
||||
} else {
|
||||
throw new IllegalCommandArgumentException();
|
||||
|
||||
Reference in New Issue
Block a user