From 7f5cd1065d2c880f87c8dbf10dd95e3ea01471d1 Mon Sep 17 00:00:00 2001 From: KingRainbow44 Date: Tue, 26 Apr 2022 19:57:44 -0400 Subject: [PATCH] Fix handler invocation --- .../emu/grasscutter/plugin/PluginManager.java | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/main/java/emu/grasscutter/plugin/PluginManager.java b/src/main/java/emu/grasscutter/plugin/PluginManager.java index 82d71ca6c..b82cf6e90 100644 --- a/src/main/java/emu/grasscutter/plugin/PluginManager.java +++ b/src/main/java/emu/grasscutter/plugin/PluginManager.java @@ -140,13 +140,19 @@ public final class PluginManager { * @param event The event to invoke. */ public void invokeEvent(Event event) { - Stream handlers = this.listeners.stream() - .filter(handler -> handler.handles().isInstance(event)); - handlers.filter(handler -> handler.getPriority() == HandlerPriority.HIGH) - .toList().forEach(handler -> this.invokeHandler(event, handler)); - handlers.filter(handler -> handler.getPriority() == HandlerPriority.NORMAL) - .toList().forEach(handler -> this.invokeHandler(event, handler)); - handlers.filter(handler -> handler.getPriority() == HandlerPriority.LOW) + EnumSet.allOf(HandlerPriority.class) + .forEach(priority -> this.checkAndFilter(event, priority)); + } + + /** + * Check an event to handlers for the priority. + * @param event The event being called. + * @param priority The priority to call for. + */ + private void checkAndFilter(Event event, HandlerPriority priority) { + this.listeners.stream() + .filter(handler -> handler.handles().isInstance(event)) + .filter(handler -> handler.getPriority() == priority) .toList().forEach(handler -> this.invokeHandler(event, handler)); }