Skip to content

Commit

Permalink
fix: Resume event execution in case any exception occurs
Browse files Browse the repository at this point in the history
  • Loading branch information
4drian3d committed May 18, 2023
1 parent f7dde89 commit 2c50e86
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ public final class ChatListener implements RegulatorExecutor<PlayerChatEvent> {
.exceptionally(ex -> {
logger.error("An error occurred while checking chat", ex);
return CheckResult.allowed();
})
.thenAccept(checkResult -> {
}).thenAccept(checkResult -> {
if (checkResult.isDenied()) {
final CheckResult.DeniedCheckresult deniedResult = (CheckResult.DeniedCheckresult) checkResult;
eventManager.fireAndForget(new ChatInfractionEvent(player, deniedResult.infractionType(), checkResult, event.getMessage()));
Expand All @@ -85,12 +84,12 @@ public final class ChatListener implements RegulatorExecutor<PlayerChatEvent> {
finalMessage = Replacer.applyFormat(finalMessage, configuration);
event.setResult(ChatResult.message(finalMessage));
}
player.getChain(SourceType.CHAT).executed(finalMessage);
player.getChain(SourceType.CHAT).executed(event.getMessage());
continuation.resume();
}
})
.exceptionally(ex -> {
}).exceptionally(ex -> {
logger.error("An error occurred while setting chat result", ex);
continuation.resume();
return null;
});
});
Expand All @@ -103,6 +102,6 @@ public Class<PlayerChatEvent> eventClass() {

@Override
public PostOrder postOrder() {
return PostOrder.FIRST;
return PostOrder.EARLY;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ private boolean checkIfCanCheck(final String command) {
.exceptionally(ex -> {
logger.error("An error occurred while checking initial command checks", ex);
return CheckResult.allowed();
})
.thenCompose(checkResult -> {
}).thenCompose(checkResult -> {
if (checkResult.isDenied()) {
return CompletableFuture.completedFuture(checkResult);
}
Expand Down Expand Up @@ -124,7 +123,11 @@ private boolean checkIfCanCheck(final String command) {
continuation.resume();
}
return null;
});
}).exceptionally(ex -> {
logger.error("An error occurred while setting chat result", ex);
continuation.resume();
return null;
});
});
}

Expand All @@ -135,6 +138,6 @@ public Class<CommandExecuteEvent> eventClass() {

@Override
public PostOrder postOrder() {
return PostOrder.FIRST;
return PostOrder.EARLY;
}
}

0 comments on commit 2c50e86

Please sign in to comment.