aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsyeyoung <cyoung06@naver.com>2023-01-17 18:01:21 +0900
committersyeyoung <cyoung06@naver.com>2023-01-17 18:01:21 +0900
commit33ecb692b2b6d672ff231547a5fed4750034e490 (patch)
treec9c5a8347159083d55cb956bfd3c435d4423b085
parentbaa1b1476bbca91d1a5b6c89bd7b3c39a3efae15 (diff)
downloadSkyblock-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>
-rw-r--r--mod/src/main/java/kr/syeyoung/dungeonsguide/mod/events/annotations/EventHandlerRegistry.java14
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();
}