Allow for multiple spaces between arguments

https://github.com/Mojang/brigadier/pull/136
This commit is contained in:
2024-08-13 01:38:13 +08:00
parent d2e25c1bfe
commit 4c8d2abf45
2 changed files with 12 additions and 1 deletions
@@ -325,7 +325,9 @@ public class CommandDispatcher<S> {
context.withCommand(child.getCommand());
if (reader.canRead(child.getRedirect() == null ? 2 : 1)) {
reader.skip();
do {
reader.skip();
} while (reader.canRead() && reader.peek() == ARGUMENT_SEPARATOR_CHAR);
if (child.getRedirect() != null) {
final CommandContextBuilder<S> childContext = new CommandContextBuilder<>(this, source, child.getRedirect(), reader.getCursor());
final ParseResults<S> parse = parseNodes(child.getRedirect(), reader, childContext);
@@ -449,6 +449,15 @@ public class CommandDispatcherTest {
}
}
@SuppressWarnings("unchecked")
@Test
public void parse_multipleSpaceSeparator() throws Exception {
subject.register(literal("foo").then(literal("bar").executes(command)));
assertThat(subject.execute("foo bar", source), is(42));
verify(command).run(any(CommandContext.class));
}
@Test
public void testExecuteInvalidSubcommand() {
subject.register(literal("foo").then(