diff --git a/build.gradle b/build.gradle index 6226324..0952e23 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.6' +version = '0.1.7' 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 c99b123..4973d01 100644 --- a/src/main/java/com/mojang/brigadier/CommandDispatcher.java +++ b/src/main/java/com/mojang/brigadier/CommandDispatcher.java @@ -86,6 +86,8 @@ public class CommandDispatcher { } int result = 0; + int successfulForks = 0; + boolean forked = false; boolean foundCommand = false; final Deque> contexts = new ArrayDeque<>(); contexts.add(parse.getContext()); @@ -102,6 +104,9 @@ public class CommandDispatcher { consumer.onCommandComplete(context, false, 0); return 0; } + if (results.size() > 1) { + forked = true; + } for (final S source : results) { contexts.add(child.copy().withSource(source)); } @@ -112,9 +117,12 @@ public class CommandDispatcher { final int value = builder.getCommand().run(context); result += value; consumer.onCommandComplete(context, true, value); + successfulForks++; } catch (final CommandSyntaxException ex) { consumer.onCommandComplete(context, false, 0); - throw ex; + if (!forked) { + throw ex; + } } } } @@ -124,7 +132,7 @@ public class CommandDispatcher { throw ERROR_UNKNOWN_COMMAND.createWithContext(parse.getReader()); } - return result; + return forked ? successfulForks : result; } public ParseResults parse(final String command, final S source) { diff --git a/src/test/java/com/mojang/brigadier/CommandDispatcherTest.java b/src/test/java/com/mojang/brigadier/CommandDispatcherTest.java index 1d32790..703bdb1 100644 --- a/src/test/java/com/mojang/brigadier/CommandDispatcherTest.java +++ b/src/test/java/com/mojang/brigadier/CommandDispatcherTest.java @@ -296,7 +296,7 @@ public class CommandDispatcherTest { assertThat(parent.getNodes().size(), is(2)); assertThat(parent.getSource(), is(source)); - assertThat(subject.execute(parse), is(84)); + assertThat(subject.execute(parse), is(2)); verify(command).run(argThat(hasProperty("source", is(source1)))); verify(command).run(argThat(hasProperty("source", is(source2)))); }