Executing forked commands should return the number of successes, and not fail on any errors
This commit is contained in:
+1
-1
@@ -3,7 +3,7 @@ import groovy.io.FileType
|
|||||||
apply plugin: 'java-library'
|
apply plugin: 'java-library'
|
||||||
apply plugin: 'maven'
|
apply plugin: 'maven'
|
||||||
|
|
||||||
version = '0.1.6'
|
version = '0.1.7'
|
||||||
group = 'com.mojang'
|
group = 'com.mojang'
|
||||||
|
|
||||||
task wrapper(type: Wrapper) {
|
task wrapper(type: Wrapper) {
|
||||||
|
|||||||
@@ -86,6 +86,8 @@ public class CommandDispatcher<S> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int result = 0;
|
int result = 0;
|
||||||
|
int successfulForks = 0;
|
||||||
|
boolean forked = false;
|
||||||
boolean foundCommand = false;
|
boolean foundCommand = false;
|
||||||
final Deque<CommandContextBuilder<S>> contexts = new ArrayDeque<>();
|
final Deque<CommandContextBuilder<S>> contexts = new ArrayDeque<>();
|
||||||
contexts.add(parse.getContext());
|
contexts.add(parse.getContext());
|
||||||
@@ -102,6 +104,9 @@ public class CommandDispatcher<S> {
|
|||||||
consumer.onCommandComplete(context, false, 0);
|
consumer.onCommandComplete(context, false, 0);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
if (results.size() > 1) {
|
||||||
|
forked = true;
|
||||||
|
}
|
||||||
for (final S source : results) {
|
for (final S source : results) {
|
||||||
contexts.add(child.copy().withSource(source));
|
contexts.add(child.copy().withSource(source));
|
||||||
}
|
}
|
||||||
@@ -112,19 +117,22 @@ public class CommandDispatcher<S> {
|
|||||||
final int value = builder.getCommand().run(context);
|
final int value = builder.getCommand().run(context);
|
||||||
result += value;
|
result += value;
|
||||||
consumer.onCommandComplete(context, true, value);
|
consumer.onCommandComplete(context, true, value);
|
||||||
|
successfulForks++;
|
||||||
} catch (final CommandSyntaxException ex) {
|
} catch (final CommandSyntaxException ex) {
|
||||||
consumer.onCommandComplete(context, false, 0);
|
consumer.onCommandComplete(context, false, 0);
|
||||||
|
if (!forked) {
|
||||||
throw ex;
|
throw ex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!foundCommand) {
|
if (!foundCommand) {
|
||||||
consumer.onCommandComplete(parse.getContext().build(), false, 0);
|
consumer.onCommandComplete(parse.getContext().build(), false, 0);
|
||||||
throw ERROR_UNKNOWN_COMMAND.createWithContext(parse.getReader());
|
throw ERROR_UNKNOWN_COMMAND.createWithContext(parse.getReader());
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return forked ? successfulForks : result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ParseResults<S> parse(final String command, final S source) {
|
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.getNodes().size(), is(2));
|
||||||
assertThat(parent.getSource(), is(source));
|
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(source1))));
|
||||||
verify(command).run(argThat(hasProperty("source", is(source2))));
|
verify(command).run(argThat(hasProperty("source", is(source2))));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user