diff --git a/src/main/java/net/minestom/server/event/EventNodeImpl.java b/src/main/java/net/minestom/server/event/EventNodeImpl.java index 79395c0d7..6aec17cd9 100644 --- a/src/main/java/net/minestom/server/event/EventNodeImpl.java +++ b/src/main/java/net/minestom/server/event/EventNodeImpl.java @@ -238,15 +238,14 @@ class EventNodeImpl implements EventNode { } private void propagateEvent(Class eventClass) { - // Recursive event - forEachRecursive(eventType, recursiveClass -> propagateEvent((Class) recursiveClass)); - // Propagate - final var parent = this.parent; - if (parent == null) return; - Handle parentHandle = parent.handleMap.get(eventClass); - if (parentHandle == null) return; - parentHandle.updated = false; - parent.propagateEvent(eventClass); + forTargetEvents(eventClass, type -> { + final var parent = this.parent; + if (parent == null) return; + Handle parentHandle = parent.handleMap.get(type); + if (parentHandle == null) return; + parentHandle.updated = false; + parent.propagateEvent((Class) type); + }); } private ListenerEntry getEntry(Class type) { @@ -259,17 +258,14 @@ class EventNodeImpl implements EventNode { return nameCheck && typeCheck; } - private static boolean isRecursive(Class type) { - if (type == null) return false; - return RecursiveEvent.class.isAssignableFrom(type); - } - - private static void forEachRecursive(Class type, Consumer> consumer) { - if (isRecursive(type)) { + private static void forTargetEvents(Class type, Consumer> consumer) { + consumer.accept(type); + // Recursion + if (RecursiveEvent.class.isAssignableFrom(type)) { final var superclass = type.getSuperclass(); - if (isRecursive(superclass)) consumer.accept((Class) superclass); + if (superclass != null && RecursiveEvent.class.isAssignableFrom(superclass)) consumer.accept(superclass); for (var inter : type.getInterfaces()) { - if (isRecursive(inter)) consumer.accept((Class) inter); + if (RecursiveEvent.class.isAssignableFrom(inter)) consumer.accept(inter); } } } @@ -300,12 +296,9 @@ class EventNodeImpl implements EventNode { private void recursiveUpdate(EventNodeImpl targetNode) { final var handleType = eventType; - ListenerEntry entry = targetNode.listenerMap.get(handleType); - if (entry != null) appendEntry(listeners, entry, targetNode); - // Recursive event - forEachRecursive(eventType, recursiveClass -> { - ListenerEntry recursiveEntry = targetNode.listenerMap.get(recursiveClass); - if (recursiveEntry != null) appendEntry(listeners, recursiveEntry, targetNode); + forTargetEvents(handleType, type -> { + ListenerEntry entry = targetNode.listenerMap.get(type); + if (entry != null) appendEntry(listeners, entry, targetNode); }); // Add children final var children = targetNode.children;