Bug fixes

This commit is contained in:
Finn
2026-01-19 22:27:20 +01:00
parent ee790659b5
commit 8f9d101801
2 changed files with 15 additions and 5 deletions

View File

@@ -6,7 +6,7 @@
<groupId>dev.unlegitdqrk</groupId>
<artifactId>unlegitlibrary</artifactId>
<version>1.7.0</version>
<version>1.7.1</version>
<url>https://unlegitdqrk.dev/</url>
<description>Just a big library</description>

View File

@@ -18,9 +18,20 @@ public final class EventManager extends DefaultMethodsOverrider {
public void registerListener(Class<? extends EventListener> listenerClass) throws Exception {
if (isListenerRegistered(listenerClass)) return;
Object instance = listenerClass.getDeclaredConstructor().newInstance();
EventListener instance = listenerClass.getDeclaredConstructor().newInstance();
registerListenerInstance(instance);
}
for (Method method : listenerClass.getDeclaredMethods()) {
public void registerListener(EventListener listenerInstance) {
if (listenerInstance == null) throw new IllegalArgumentException("Listener instance cannot be null");
Class<? extends EventListener> listenerClass = listenerInstance.getClass();
if (isListenerRegistered(listenerClass)) return;
registerListenerInstance(listenerInstance);
}
private void registerListenerInstance(Object instance) {
for (Method method : instance.getClass().getDeclaredMethods()) {
Listener listenerAnnotation = method.getAnnotation(Listener.class);
if (listenerAnnotation == null || method.getParameterCount() != 1) continue;
@@ -37,7 +48,7 @@ public final class EventManager extends DefaultMethodsOverrider {
.put(instance, method);
}
eventListeners.put(listenerClass, instance);
eventListeners.put((Class<? extends EventListener>) instance.getClass(), instance);
}
public synchronized void unregisterListener(Class<? extends EventListener> listenerClass) {
@@ -51,7 +62,6 @@ public final class EventManager extends DefaultMethodsOverrider {
}
}
// Clean up empty entries
registeredListener.entrySet().removeIf(e ->
e.getValue().values().stream().allMatch(Map::isEmpty));