mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-02 22:47:49 +01:00
Prevent node update from being called multiple times
Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
parent
909c42c8d0
commit
5c9c57439a
@ -273,7 +273,7 @@ class EventNodeImpl<T extends Event> implements EventNode<T> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void call(@NotNull E event) {
|
public void call(@NotNull E event) {
|
||||||
if (!updated) update();
|
update();
|
||||||
final Consumer<E>[] listeners = this.listeners;
|
final Consumer<E>[] listeners = this.listeners;
|
||||||
if (listeners.length == 0) return;
|
if (listeners.length == 0) return;
|
||||||
for (Consumer<E> listener : listeners) {
|
for (Consumer<E> listener : listeners) {
|
||||||
@ -283,12 +283,14 @@ class EventNodeImpl<T extends Event> implements EventNode<T> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasListener() {
|
public boolean hasListener() {
|
||||||
if (!updated) update();
|
update();
|
||||||
return listeners.length > 0;
|
return listeners.length > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void update() {
|
void update() {
|
||||||
|
if (updated) return;
|
||||||
synchronized (GLOBAL_CHILD_LOCK) {
|
synchronized (GLOBAL_CHILD_LOCK) {
|
||||||
|
if (updated) return;
|
||||||
this.listenersCache.clear();
|
this.listenersCache.clear();
|
||||||
recursiveUpdate(node);
|
recursiveUpdate(node);
|
||||||
this.listeners = listenersCache.toArray(Consumer[]::new);
|
this.listeners = listenersCache.toArray(Consumer[]::new);
|
||||||
@ -338,7 +340,7 @@ class EventNodeImpl<T extends Event> implements EventNode<T> {
|
|||||||
final Object handler = filter.castHandler(event);
|
final Object handler = filter.castHandler(event);
|
||||||
final Handle<E> handle = handlers.get(handler);
|
final Handle<E> handle = handlers.get(handler);
|
||||||
if (handle != null) { // Run the listeners of the mapped node
|
if (handle != null) { // Run the listeners of the mapped node
|
||||||
if (!handle.updated) handle.update();
|
handle.update();
|
||||||
for (Consumer<E> listener : handle.listeners) {
|
for (Consumer<E> listener : handle.listeners) {
|
||||||
listener.accept(event);
|
listener.accept(event);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user