mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-16 21:21:22 +01:00
Ensure listeners being up to date
This commit is contained in:
parent
a75910fe3f
commit
0a3ad69e58
@ -273,8 +273,7 @@ class EventNodeImpl<T extends Event> implements EventNode<T> {
|
||||
|
||||
@Override
|
||||
public void call(@NotNull E event) {
|
||||
update();
|
||||
final Consumer<E>[] listeners = this.listeners;
|
||||
final Consumer<E>[] listeners = updatedListeners();
|
||||
if (listeners.length == 0) return;
|
||||
for (Consumer<E> listener : listeners) {
|
||||
listener.accept(event);
|
||||
@ -283,18 +282,19 @@ class EventNodeImpl<T extends Event> implements EventNode<T> {
|
||||
|
||||
@Override
|
||||
public boolean hasListener() {
|
||||
update();
|
||||
return listeners.length > 0;
|
||||
return updatedListeners().length > 0;
|
||||
}
|
||||
|
||||
void update() {
|
||||
if (updated) return;
|
||||
Consumer<E>[] updatedListeners() {
|
||||
if (updated) return listeners;
|
||||
synchronized (GLOBAL_CHILD_LOCK) {
|
||||
if (updated) return;
|
||||
if (updated) return listeners;
|
||||
this.listenersCache.clear();
|
||||
recursiveUpdate(node);
|
||||
this.listeners = listenersCache.toArray(Consumer[]::new);
|
||||
final Consumer<E>[] listenersArray = listenersCache.toArray(Consumer[]::new);
|
||||
this.listeners = listenersArray;
|
||||
this.updated = true;
|
||||
return listenersArray;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user