diff --git a/src/main/java/net/minecraft/commands/tree/ArgumentCommandNode.java b/src/main/java/net/minecraft/commands/tree/ArgumentCommandNode.java index e054ffa..a67f722 100644 --- a/src/main/java/net/minecraft/commands/tree/ArgumentCommandNode.java +++ b/src/main/java/net/minecraft/commands/tree/ArgumentCommandNode.java @@ -21,24 +21,23 @@ public class ArgumentCommandNode extends CommandNode { } @Override - public void parse(String command) throws IllegalCommandArgumentException { + public CommandNode parse(String command) throws IllegalCommandArgumentException { CommandArgumentType.CommandArgumentParseResult 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; } } } diff --git a/src/main/java/net/minecraft/commands/tree/CommandNode.java b/src/main/java/net/minecraft/commands/tree/CommandNode.java index 0555975..47eb258 100644 --- a/src/main/java/net/minecraft/commands/tree/CommandNode.java +++ b/src/main/java/net/minecraft/commands/tree/CommandNode.java @@ -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; } diff --git a/src/main/java/net/minecraft/commands/tree/LiteralCommandNode.java b/src/main/java/net/minecraft/commands/tree/LiteralCommandNode.java index b1bb87a..bc7b23e 100644 --- a/src/main/java/net/minecraft/commands/tree/LiteralCommandNode.java +++ b/src/main/java/net/minecraft/commands/tree/LiteralCommandNode.java @@ -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(); diff --git a/src/main/test/net/minecraft/commands/tree/ArgumentCommandNodeTest.java b/src/main/test/net/minecraft/commands/tree/ArgumentCommandNodeTest.java index 63b46d8..486da94 100644 --- a/src/main/test/net/minecraft/commands/tree/ArgumentCommandNodeTest.java +++ b/src/main/test/net/minecraft/commands/tree/ArgumentCommandNodeTest.java @@ -6,6 +6,8 @@ import org.junit.Test; import static net.minecraft.commands.arguments.IntegerArgumentType.integer; import static net.minecraft.commands.builder.RequiredArgumentBuilder.argument; +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertThat; public class ArgumentCommandNodeTest { ArgumentCommandNode node; @@ -17,7 +19,7 @@ public class ArgumentCommandNodeTest { @Test public void testParse() throws Exception { - node.parse("123"); + assertThat((ArgumentCommandNode) node.parse("123"), is(node)); } @Test(expected = IllegalCommandArgumentException.class) @@ -27,9 +29,11 @@ public class ArgumentCommandNodeTest { @Test public void testParseChild() throws Exception { - node.addChild(argument("bar", integer()).build()); + CommandNode child = argument("bar", integer()).build(); - node.parse("123 123"); + node.addChild(child); + + assertThat(node.parse("123 123"), is(child)); } @Test(expected = IllegalCommandArgumentException.class) diff --git a/src/main/test/net/minecraft/commands/tree/LiteralCommandNodeTest.java b/src/main/test/net/minecraft/commands/tree/LiteralCommandNodeTest.java index 9132d46..d7557b0 100644 --- a/src/main/test/net/minecraft/commands/tree/LiteralCommandNodeTest.java +++ b/src/main/test/net/minecraft/commands/tree/LiteralCommandNodeTest.java @@ -7,6 +7,8 @@ import org.junit.Test; import static net.minecraft.commands.arguments.IntegerArgumentType.integer; import static net.minecraft.commands.builder.CommandBuilder.command; import static net.minecraft.commands.builder.RequiredArgumentBuilder.argument; +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertThat; public class LiteralCommandNodeTest { LiteralCommandNode node; @@ -18,7 +20,7 @@ public class LiteralCommandNodeTest { @Test public void testParse() throws Exception { - node.parse("foo"); + assertThat((LiteralCommandNode) node.parse("foo"), is(node)); } @Test(expected = IllegalCommandArgumentException.class) @@ -28,9 +30,11 @@ public class LiteralCommandNodeTest { @Test public void testParseChild() throws Exception { - node.addChild(argument("bar", integer()).build()); + CommandNode child = argument("bar", integer()).build(); - node.parse("foo 123"); + node.addChild(child); + + assertThat(node.parse("foo 123"), is(child)); } @Test(expected = IllegalCommandArgumentException.class)