Skip to content

Commit

Permalink
Allow asynchronous SkriptEvent#check execution (#6201)
Browse files Browse the repository at this point in the history
  • Loading branch information
APickledWalrus authored Dec 1, 2023
1 parent f30f023 commit ac5ff5b
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/main/java/ch/njol/skript/SkriptEventHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,10 @@ private static void check(Event event, EventPriority priority) {
boolean hasTrigger = false;
for (Trigger trigger : triggers) {
SkriptEvent triggerEvent = trigger.getEvent();
if (triggerEvent.getEventPriority() == priority && Boolean.TRUE.equals(Task.callSync(() -> triggerEvent.check(event)))) {
if (
triggerEvent.getEventPriority() == priority
&& triggerEvent.canExecuteAsynchronously() ? triggerEvent.check(event) : Boolean.TRUE.equals(Task.callSync(() -> triggerEvent.check(event)))
) {
hasTrigger = true;
break;
}
Expand All @@ -130,7 +133,7 @@ private static void check(Event event, EventPriority priority) {

logEventStart(event);
}

boolean isCancelled = event instanceof Cancellable && ((Cancellable) event).isCancelled() && !listenCancelled.contains(event.getClass());
boolean isResultDeny = !(event instanceof PlayerInteractEvent && (((PlayerInteractEvent) event).getAction() == Action.LEFT_CLICK_AIR || ((PlayerInteractEvent) event).getAction() == Action.RIGHT_CLICK_AIR) && ((PlayerInteractEvent) event).useItemInHand() != Result.DENY);

Expand All @@ -155,15 +158,12 @@ private static void check(Event event, EventPriority priority) {
};

if (trigger.getEvent().canExecuteAsynchronously()) {
// check should be performed on the main thread
if (Boolean.FALSE.equals(Task.callSync(() -> triggerEvent.check(event))))
continue;
execute.run();
if (triggerEvent.check(event))
execute.run();
} else { // Ensure main thread
Task.callSync(() -> {
if (!triggerEvent.check(event))
return null;
execute.run();
if (triggerEvent.check(event))
execute.run();
return null; // we don't care about a return value
});
}
Expand Down

0 comments on commit ac5ff5b

Please sign in to comment.