diff options
author | syeyoung <cyoung06@naver.com> | 2023-01-17 18:01:21 +0900 |
---|---|---|
committer | syeyoung <cyoung06@naver.com> | 2023-01-17 18:01:21 +0900 |
commit | 33ecb692b2b6d672ff231547a5fed4750034e490 (patch) | |
tree | c9c5a8347159083d55cb956bfd3c435d4423b085 /mod/src/main/java/kr/syeyoung | |
parent | baa1b1476bbca91d1a5b6c89bd7b3c39a3efae15 (diff) | |
download | Skyblock-Dungeons-Guide-33ecb692b2b6d672ff231547a5fed4750034e490.tar.gz Skyblock-Dungeons-Guide-33ecb692b2b6d672ff231547a5fed4750034e490.tar.bz2 Skyblock-Dungeons-Guide-33ecb692b2b6d672ff231547a5fed4750034e490.zip |
- Fix infinite listener registration
Signed-off-by: syeyoung <cyoung06@naver.com>
Diffstat (limited to 'mod/src/main/java/kr/syeyoung')
-rw-r--r-- | mod/src/main/java/kr/syeyoung/dungeonsguide/mod/events/annotations/EventHandlerRegistry.java | 14 |
1 files 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<Event, IEventListener> registeredHandlers = new HashMap<>(); + private static Map<Class<? extends Event>, IEventListener> registeredHandlers = new HashMap<>(); public static void registerActualListeners() { for (Class<? extends Event> 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<Event, IEventListener> eventIEventListenerEntry : registeredHandlers.entrySet()) { - eventIEventListenerEntry.getKey().getListenerList().unregister(busID, eventIEventListenerEntry.getValue()); + for (Map.Entry<Class<? extends Event>, 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(); } |