Bug fixes
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>dev.unlegitdqrk</groupId>
|
<groupId>dev.unlegitdqrk</groupId>
|
||||||
<artifactId>unlegitlibrary</artifactId>
|
<artifactId>unlegitlibrary</artifactId>
|
||||||
<version>1.7.0</version>
|
<version>1.7.1</version>
|
||||||
<url>https://unlegitdqrk.dev/</url>
|
<url>https://unlegitdqrk.dev/</url>
|
||||||
<description>Just a big library</description>
|
<description>Just a big library</description>
|
||||||
|
|
||||||
|
|||||||
@@ -18,9 +18,20 @@ public final class EventManager extends DefaultMethodsOverrider {
|
|||||||
public void registerListener(Class<? extends EventListener> listenerClass) throws Exception {
|
public void registerListener(Class<? extends EventListener> listenerClass) throws Exception {
|
||||||
if (isListenerRegistered(listenerClass)) return;
|
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);
|
Listener listenerAnnotation = method.getAnnotation(Listener.class);
|
||||||
|
|
||||||
if (listenerAnnotation == null || method.getParameterCount() != 1) continue;
|
if (listenerAnnotation == null || method.getParameterCount() != 1) continue;
|
||||||
@@ -37,7 +48,7 @@ public final class EventManager extends DefaultMethodsOverrider {
|
|||||||
.put(instance, method);
|
.put(instance, method);
|
||||||
}
|
}
|
||||||
|
|
||||||
eventListeners.put(listenerClass, instance);
|
eventListeners.put((Class<? extends EventListener>) instance.getClass(), instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void unregisterListener(Class<? extends EventListener> listenerClass) {
|
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 ->
|
registeredListener.entrySet().removeIf(e ->
|
||||||
e.getValue().values().stream().allMatch(Map::isEmpty));
|
e.getValue().values().stream().allMatch(Map::isEmpty));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user