From 33ecb692b2b6d672ff231547a5fed4750034e490 Mon Sep 17 00:00:00 2001 From: syeyoung Date: Tue, 17 Jan 2023 18:01:21 +0900 Subject: - Fix infinite listener registration Signed-off-by: syeyoung --- .../mod/events/annotations/EventHandlerRegistry.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/events/annotations/EventHandlerRegistry.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/events/annotations/EventHandlerRegistry.java index 914652b7..fecfa2fc 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/events/annotations/EventHandlerRegistry.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/events/annotations/EventHandlerRegistry.java @@ -110,7 +110,7 @@ public class EventHandlerRegistry { registerActualListeners(); } - private static Map registeredHandlers = new HashMap<>(); + private static Map, IEventListener> registeredHandlers = new HashMap<>(); public static void registerActualListeners() { for (Class aClass : targets.keySet()) { @@ -134,7 +134,7 @@ public class EventHandlerRegistry { } profiler.endSection(); }); - registeredHandlers.put(ev, registered); + registeredHandlers.put(aClass, registered); } catch (Exception e) { throw new RuntimeException("An error occured while registering listener for "+aClass.getName(), e); } @@ -142,8 +142,14 @@ public class EventHandlerRegistry { } public static void unregisterListeners() { - for (Map.Entry eventIEventListenerEntry : registeredHandlers.entrySet()) { - eventIEventListenerEntry.getKey().getListenerList().unregister(busID, eventIEventListenerEntry.getValue()); + for (Map.Entry, IEventListener> eventIEventListenerEntry : registeredHandlers.entrySet()) { + try { + Event ev = eventIEventListenerEntry.getKey().getConstructor().newInstance(); + ev.getListenerList().unregister(busID, eventIEventListenerEntry.getValue()); + } catch (InstantiationException | NoSuchMethodException | InvocationTargetException | + IllegalAccessException e) { + e.printStackTrace(); + } } registeredHandlers.clear(); } -- cgit