When parsing nodes, return the deepest node we went into

This commit is contained in:
Nathan Adams
2014-09-22 15:20:57 +02:00
parent 8d164e4b66
commit 397ab17e64
5 changed files with 28 additions and 17 deletions
@@ -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;
}
}
}