diff options
Diffstat (limited to 'mod/src/main/java/moe/ymc/acron/cmd/CmdResConsumer.java')
-rw-r--r-- | mod/src/main/java/moe/ymc/acron/cmd/CmdResConsumer.java | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/mod/src/main/java/moe/ymc/acron/cmd/CmdResConsumer.java b/mod/src/main/java/moe/ymc/acron/cmd/CmdResConsumer.java index d22b77e..36f7605 100644 --- a/mod/src/main/java/moe/ymc/acron/cmd/CmdResConsumer.java +++ b/mod/src/main/java/moe/ymc/acron/cmd/CmdResConsumer.java @@ -16,6 +16,8 @@ public class CmdResConsumer implements ResultConsumer<ServerCommandSource> { private final @NotNull Channel channel; private final int id; + private boolean hasResult; + public CmdResConsumer(@NotNull Channel channel, int id) { this.channel = channel; @@ -28,6 +30,20 @@ public class CmdResConsumer implements ResultConsumer<ServerCommandSource> { id, success, result); - channel.writeAndFlush(Serializer.serialize(new EventCmdRes(id, success, result))); + // Ignore any failed results because CommandDispatcher#execute does not reliably send error + // results to the consumer. + // For example, fail results are either not sent at all (pre-processing errors), or + // sent before writing the result, which both violates the spec. + // We will send the failed results in a custom mixin. + if (success) { + hasResult = true; + channel.writeAndFlush(Serializer.serialize(new EventCmdRes(id, success, result))); + } + } + + public void sendResultIfNot() { + if (!hasResult) { + channel.writeAndFlush(Serializer.serialize(new EventCmdRes(id, false, -1))); + } } } |