Executing forked commands should return the number of successes, and not fail on any errors

This commit is contained in:
Nathan Adams 2017-11-09 12:11:08 +01:00
parent e97dd6bb79
commit b716f9a873
3 changed files with 12 additions and 4 deletions

View file

@ -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) {

View file

@ -86,6 +86,8 @@ public class CommandDispatcher<S> {
}
int result = 0;
int successfulForks = 0;
boolean forked = false;
boolean foundCommand = false;
final Deque<CommandContextBuilder<S>> contexts = new ArrayDeque<>();
contexts.add(parse.getContext());
@ -102,6 +104,9 @@ public class CommandDispatcher<S> {
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<S> {
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<S> {
throw ERROR_UNKNOWN_COMMAND.createWithContext(parse.getReader());
}
return result;
return forked ? successfulForks : result;
}
public ParseResults<S> parse(final String command, final S source) {

View file

@ -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))));
}