Executing forked commands should return the number of successes, and not fail on any errors
This commit is contained in:
parent
e97dd6bb79
commit
b716f9a873
3 changed files with 12 additions and 4 deletions
|
@ -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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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))));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue