diff --git a/src/main/java/com/mojang/brigadier/context/CommandContextBuilder.java b/src/main/java/com/mojang/brigadier/context/CommandContextBuilder.java index 401c93d..19e0ab6 100644 --- a/src/main/java/com/mojang/brigadier/context/CommandContextBuilder.java +++ b/src/main/java/com/mojang/brigadier/context/CommandContextBuilder.java @@ -11,7 +11,6 @@ public class CommandContextBuilder { private final Map> arguments = Maps.newLinkedHashMap(); private final Map, String> nodes = Maps.newLinkedHashMap(); private final CommandDispatcher dispatcher; - private final StringBuilder input = new StringBuilder(); private S source; private Command command; private CommandContext parent; @@ -45,11 +44,7 @@ public class CommandContextBuilder { } public CommandContextBuilder withNode(final CommandNode node, final String raw) { - if (!nodes.isEmpty()) { - input.append(CommandDispatcher.ARGUMENT_SEPARATOR); - } nodes.put(node, raw); - input.append(raw); return this; } @@ -58,7 +53,6 @@ public class CommandContextBuilder { copy.command = command; copy.arguments.putAll(arguments); copy.nodes.putAll(nodes); - copy.input.append(input); copy.parent = parent; return copy; } @@ -75,7 +69,19 @@ public class CommandContextBuilder { } public String getInput() { - return input.toString(); + final StringBuilder result = new StringBuilder(); + boolean first = true; + for (final String node : nodes.values()) { + if (first) { + if (!node.isEmpty()) { + first = false; + } + } else { + result.append(CommandDispatcher.ARGUMENT_SEPARATOR); + } + result.append(node); + } + return result.toString(); } public Map, String> getNodes() { @@ -83,7 +89,7 @@ public class CommandContextBuilder { } public CommandContext build() { - return new CommandContext<>(source, arguments, command, nodes, input.toString(), parent); + return new CommandContext<>(source, arguments, command, nodes, getInput(), parent); } public CommandDispatcher getDispatcher() { diff --git a/src/test/java/com/mojang/brigadier/CommandDispatcherTest.java b/src/test/java/com/mojang/brigadier/CommandDispatcherTest.java index 3c07fc3..ec1eb9d 100644 --- a/src/test/java/com/mojang/brigadier/CommandDispatcherTest.java +++ b/src/test/java/com/mojang/brigadier/CommandDispatcherTest.java @@ -176,12 +176,12 @@ public class CommandDispatcherTest { final ParseResults parse = subject.parse("redirected redirected actual", source); assertThat(parse.getContext().getInput(), equalTo("actual")); - assertThat(parse.getContext().getNodes().size(), is(1)); + assertThat(parse.getContext().getNodes().size(), is(2)); final CommandContext parent1 = parse.getContext().getParent(); assertThat(parent1, is(notNullValue())); assertThat(parent1.getInput(), equalTo("redirected")); - assertThat(parent1.getNodes().size(), is(1)); + assertThat(parent1.getNodes().size(), is(2)); final CommandContext parent2 = parent1.getParent(); assertThat(parent2, is(notNullValue()));