diff --git a/event-loop/src/main/java/mc/core/events/async/AsyncEventLoop.java b/event-loop/src/main/java/mc/core/events/async/AsyncEventLoop.java index b4a4356..4a6a1e6 100644 --- a/event-loop/src/main/java/mc/core/events/async/AsyncEventLoop.java +++ b/event-loop/src/main/java/mc/core/events/async/AsyncEventLoop.java @@ -27,10 +27,13 @@ public class AsyncEventLoop extends AdvancedEventLoop { // Submit all defined preprocessing methods as async tasks for (int i = 0; i < handlerList.size(); i++) { if (handlerList.get(i).getPreprocessMethod() == null) { + // We have already "allocated" a space for this task in CountDownLatch, + // but since there is no actual preprocess method defined for this handler + // we just skip it by ticking the latch down manually latch.countDown(); - continue; + } else { + preEventExecutor.submit(new PreprocessTask(i, eventBatch, latch, handlerList.get(i), event)); } - preEventExecutor.submit(new PreprocessTask(i, eventBatch, latch, handlerList.get(i), event)); } // Await for them to complete @@ -44,16 +47,15 @@ public class AsyncEventLoop extends AdvancedEventLoop { // data obtained from EventBatch for (int i = 0; i < handlerList.size(); i++) { ExecutorLink link = handlerList.get(i); - if (link.isIgnoreCancelled() && event.isCanceled()) - continue; - - try { - if (link.getResultInjection() != null) - link.getMethod().invoke(link.getObject(), event, eventBatch.getInjectionObject(i)); - else - link.getMethod().invoke(link.getObject(), event); - } catch (IllegalAccessException | InvocationTargetException e) { - log.error("Exception caught while attempting to dispatch {}.", eventType.getSimpleName(), e); + if (!link.isIgnoreCancelled() || !event.isCanceled()) { + try { + if (link.getResultInjection() != null) + link.getMethod().invoke(link.getObject(), event, eventBatch.getInjectionObject(i)); + else + link.getMethod().invoke(link.getObject(), event); + } catch (IllegalAccessException | InvocationTargetException e) { + log.error("Exception caught while attempting to dispatch {}.", eventType.getSimpleName(), e); + } } } }