Fixed commands with a trailing whitespace

This commit is contained in:
Nathan Adams 2017-11-08 09:20:48 +01:00
parent 2c39925cda
commit 6e61fef225
3 changed files with 14 additions and 2 deletions

View file

@ -3,7 +3,7 @@ import groovy.io.FileType
apply plugin: 'java-library' apply plugin: 'java-library'
apply plugin: 'maven' apply plugin: 'maven'
version = '0.1.1' version = '0.1.2'
group = 'com.mojang' group = 'com.mojang'
task wrapper(type: Wrapper) { task wrapper(type: Wrapper) {

View file

@ -153,7 +153,9 @@ public class CommandDispatcher<S> {
context.withCommand(child.getCommand()); context.withCommand(child.getCommand());
if (reader.canRead()) { if (reader.canRead()) {
if (reader.canRead(2)) {
reader.skip(); reader.skip();
}
if (child.getRedirect() != null) { if (child.getRedirect() != null) {
final CommandContextBuilder<S> childContext = new CommandContextBuilder<>(this, source, reader.getCursor()); final CommandContextBuilder<S> childContext = new CommandContextBuilder<>(this, source, reader.getCursor());
childContext.withNode(child.getRedirect(), new StringRange(reader.getCursor(), reader.getCursor())); childContext.withNode(child.getRedirect(), new StringRange(reader.getCursor(), reader.getCursor()));

View file

@ -173,6 +173,16 @@ public class CommandDispatcherTest {
verify(subCommand).run(any(CommandContext.class)); verify(subCommand).run(any(CommandContext.class));
} }
@SuppressWarnings("unchecked")
@Test
public void testParseIncomplete() throws Exception {
subject.register(literal("foo").then(literal("bar").executes(command)));
final ParseResults<Object> parse = subject.parse("foo ", source);
assertThat(parse.getReader().getRemaining(), equalTo(" "));
assertThat(parse.getContext().getNodes().size(), is(1));
}
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Test @Test
public void testExecuteAmbiguiousParentSubcommand() throws Exception { public void testExecuteAmbiguiousParentSubcommand() throws Exception {