From 5c9c57439ac121cc3713df455c05ea0b76249332 Mon Sep 17 00:00:00 2001 From: TheMode Date: Fri, 27 Aug 2021 09:51:36 +0200 Subject: [PATCH] Prevent node update from being called multiple times Signed-off-by: TheMode --- .../java/net/minestom/server/event/EventNodeImpl.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/minestom/server/event/EventNodeImpl.java b/src/main/java/net/minestom/server/event/EventNodeImpl.java index f9e77546b..ebd882c15 100644 --- a/src/main/java/net/minestom/server/event/EventNodeImpl.java +++ b/src/main/java/net/minestom/server/event/EventNodeImpl.java @@ -273,7 +273,7 @@ class EventNodeImpl implements EventNode { @Override public void call(@NotNull E event) { - if (!updated) update(); + update(); final Consumer[] listeners = this.listeners; if (listeners.length == 0) return; for (Consumer listener : listeners) { @@ -283,12 +283,14 @@ class EventNodeImpl implements EventNode { @Override public boolean hasListener() { - if (!updated) update(); + update(); return listeners.length > 0; } void update() { + if (updated) return; synchronized (GLOBAL_CHILD_LOCK) { + if (updated) return; this.listenersCache.clear(); recursiveUpdate(node); this.listeners = listenersCache.toArray(Consumer[]::new); @@ -338,7 +340,7 @@ class EventNodeImpl implements EventNode { final Object handler = filter.castHandler(event); final Handle handle = handlers.get(handler); if (handle != null) { // Run the listeners of the mapped node - if (!handle.updated) handle.update(); + handle.update(); for (Consumer listener : handle.listeners) { listener.accept(event); }