diff --git a/build.gradle b/build.gradle index 0b2d68b..1a372e0 100644 --- a/build.gradle +++ b/build.gradle @@ -3,7 +3,7 @@ import groovy.io.FileType apply plugin: 'java-library' apply plugin: 'maven' -version = '0.1.2' +version = '0.1.3' group = 'com.mojang' task wrapper(type: Wrapper) { diff --git a/src/main/java/com/mojang/brigadier/CommandDispatcher.java b/src/main/java/com/mojang/brigadier/CommandDispatcher.java index 25193be..2d2f7ad 100644 --- a/src/main/java/com/mojang/brigadier/CommandDispatcher.java +++ b/src/main/java/com/mojang/brigadier/CommandDispatcher.java @@ -152,10 +152,8 @@ public class CommandDispatcher { } context.withCommand(child.getCommand()); - if (reader.canRead()) { - if (reader.canRead(2)) { - reader.skip(); - } + if (reader.canRead(2)) { + reader.skip(); if (child.getRedirect() != null) { final CommandContextBuilder childContext = new CommandContextBuilder<>(this, source, reader.getCursor()); childContext.withNode(child.getRedirect(), new StringRange(reader.getCursor(), reader.getCursor())); diff --git a/src/test/java/com/mojang/brigadier/CommandDispatcherTest.java b/src/test/java/com/mojang/brigadier/CommandDispatcherTest.java index 3352b47..1d32790 100644 --- a/src/test/java/com/mojang/brigadier/CommandDispatcherTest.java +++ b/src/test/java/com/mojang/brigadier/CommandDispatcherTest.java @@ -175,7 +175,7 @@ public class CommandDispatcherTest { @SuppressWarnings("unchecked") @Test - public void testParseIncomplete() throws Exception { + public void testParseIncompleteLiteral() throws Exception { subject.register(literal("foo").then(literal("bar").executes(command))); final ParseResults parse = subject.parse("foo ", source); @@ -183,6 +183,16 @@ public class CommandDispatcherTest { assertThat(parse.getContext().getNodes().size(), is(1)); } + @SuppressWarnings("unchecked") + @Test + public void testParseIncompleteArgument() throws Exception { + subject.register(literal("foo").then(argument("bar", integer()).executes(command))); + + final ParseResults parse = subject.parse("foo ", source); + assertThat(parse.getReader().getRemaining(), equalTo(" ")); + assertThat(parse.getContext().getNodes().size(), is(1)); + } + @SuppressWarnings("unchecked") @Test public void testExecuteAmbiguiousParentSubcommand() throws Exception {