diff --git a/src/main/java/net/minestom/server/event/EventNode.java b/src/main/java/net/minestom/server/event/EventNode.java index 029571d0c..018f60ec4 100644 --- a/src/main/java/net/minestom/server/event/EventNode.java +++ b/src/main/java/net/minestom/server/event/EventNode.java @@ -214,24 +214,6 @@ public class EventNode { this.mappedNode = mapCache.asMap(); } - /** - * Condition to enter the node. - * - * @param event the called event - * @return true to enter the node, false otherwise - */ - protected boolean condition(@NotNull T event) { - if (predicate == null) - return true; - final var value = filter.getHandler(event); - try { - return predicate.test(event, value); - } catch (Exception e) { - MinecraftServer.getExceptionManager().handleException(e); - return false; - } - } - /** * Executes the given event on this node. The event must pass all conditions before * it will be forwarded to the listeners. @@ -243,13 +225,16 @@ public class EventNode { */ public void call(@NotNull T event) { final var eventClass = event.getClass(); - if (!eventType.isAssignableFrom(eventClass)) { - // Invalid event type - return; - } - if (!condition(event)) { - // Cancelled by superclass - return; + if (!eventType.isAssignableFrom(eventClass)) return; // Invalid event type + // Conditions + if (predicate != null) { + try { + final var value = filter.getHandler(event); + if (!predicate.test(event, value)) return; + } catch (Exception e) { + MinecraftServer.getExceptionManager().handleException(e); + return; + } } // Event interfaces if (!interfaces.isEmpty()) { @@ -269,10 +254,7 @@ public class EventNode { } // Process listener list final var entry = listenerMap.get(eventClass); - if (entry == null) { - // No listener nor children - return; - } + if (entry == null) return; // No listener nor children final var listeners = entry.listeners; if (!listeners.isEmpty()) { @@ -352,9 +334,7 @@ public class EventNode { */ @Contract(pure = true) public @NotNull List> findChildren(@NotNull String name, Class eventType) { - if (children.isEmpty()) { - return Collections.emptyList(); - } + if (children.isEmpty()) return Collections.emptyList(); synchronized (GLOBAL_CHILD_LOCK) { List> result = new ArrayList<>(); for (EventNode child : children) { @@ -388,9 +368,7 @@ public class EventNode { * @param eventNode The replacement node */ public void replaceChildren(@NotNull String name, @NotNull Class eventType, @NotNull EventNode eventNode) { - if (children.isEmpty()) { - return; - } + if (children.isEmpty()) return; synchronized (GLOBAL_CHILD_LOCK) { for (EventNode child : children) { if (EventNode.equals(child, name, eventType)) { @@ -422,9 +400,7 @@ public class EventNode { * @param eventType The node type to filter for */ public void removeChildren(@NotNull String name, @NotNull Class eventType) { - if (children.isEmpty()) { - return; - } + if (children.isEmpty()) return; synchronized (GLOBAL_CHILD_LOCK) { for (EventNode child : children) { if (EventNode.equals(child, name, eventType)) { @@ -463,8 +439,7 @@ public class EventNode { synchronized (lock) { child.listenerMap.forEach((eventClass, eventListeners) -> { final var entry = child.listenerMap.get(eventClass); - if (entry == null) - return; + if (entry == null) return; final int childCount = entry.listeners.size() + entry.childCount; increaseChildListenerCount(eventClass, childCount); }); @@ -526,8 +501,7 @@ public class EventNode { synchronized (GLOBAL_CHILD_LOCK) { final var eventType = listener.getEventType(); var entry = listenerMap.get(eventType); - if (entry == null) - return this; + if (entry == null) return this; var listeners = entry.listeners; final boolean removed = listeners.remove(listener); if (removed && parent != null) {