From 4c8d2abf45c423d2f2a6c27cfc398321487424db Mon Sep 17 00:00:00 2001 From: Fortern Date: Tue, 13 Aug 2024 01:38:03 +0800 Subject: [PATCH] Allow for multiple spaces between arguments https://github.com/Mojang/brigadier/pull/136 --- .../java/com/mojang/brigadier/CommandDispatcher.java | 4 +++- .../java/com/mojang/brigadier/CommandDispatcherTest.java | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/mojang/brigadier/CommandDispatcher.java b/src/main/java/com/mojang/brigadier/CommandDispatcher.java index 69a2a83de..d2c40fde0 100644 --- a/src/main/java/com/mojang/brigadier/CommandDispatcher.java +++ b/src/main/java/com/mojang/brigadier/CommandDispatcher.java @@ -325,7 +325,9 @@ private ParseResults parseNodes(final CommandNode node, final StringReader 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 childContext = new CommandContextBuilder<>(this, source, child.getRedirect(), reader.getCursor()); final ParseResults parse = parseNodes(child.getRedirect(), reader, childContext); diff --git a/src/test/java/com/mojang/brigadier/CommandDispatcherTest.java b/src/test/java/com/mojang/brigadier/CommandDispatcherTest.java index ff81f41b7..1cd3f8867 100644 --- a/src/test/java/com/mojang/brigadier/CommandDispatcherTest.java +++ b/src/test/java/com/mojang/brigadier/CommandDispatcherTest.java @@ -449,6 +449,15 @@ public void parse_noSpaceSeparator() { } } + @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(