mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-08 01:17:47 +01:00
propagate listener changes to parents
This commit is contained in:
parent
9594d848bc
commit
c930eed412
@ -114,7 +114,7 @@ public class EventNode<T extends Event> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final var listeners = entry.listeners;
|
final var listeners = entry.listeners;
|
||||||
if (listeners != null && !listeners.isEmpty()) {
|
if (!listeners.isEmpty()) {
|
||||||
for (EventListener<T> listener : listeners) {
|
for (EventListener<T> listener : listeners) {
|
||||||
final EventListener.Result result = listener.run(event);
|
final EventListener.Result result = listener.run(event);
|
||||||
if (result == EventListener.Result.EXPIRED) {
|
if (result == EventListener.Result.EXPIRED) {
|
||||||
@ -241,6 +241,9 @@ public class EventNode<T extends Event> {
|
|||||||
private void increaseChildListenerCount(Class<? extends T> eventClass, int count) {
|
private void increaseChildListenerCount(Class<? extends T> eventClass, int count) {
|
||||||
var entry = listenerMap.computeIfAbsent(eventClass, aClass -> new ListenerEntry<>());
|
var entry = listenerMap.computeIfAbsent(eventClass, aClass -> new ListenerEntry<>());
|
||||||
ListenerEntry.addAndGet(entry, count);
|
ListenerEntry.addAndGet(entry, count);
|
||||||
|
if (parent != null) {
|
||||||
|
parent.increaseChildListenerCount(eventClass, count);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void decreaseChildListenerCount(Class<? extends T> eventClass, int count) {
|
private void decreaseChildListenerCount(Class<? extends T> eventClass, int count) {
|
||||||
@ -251,6 +254,9 @@ public class EventNode<T extends Event> {
|
|||||||
} else if (result < 0) {
|
} else if (result < 0) {
|
||||||
throw new IllegalStateException("Something wrong happened, listener count: " + result);
|
throw new IllegalStateException("Something wrong happened, listener count: " + result);
|
||||||
}
|
}
|
||||||
|
if (parent != null) {
|
||||||
|
parent.decreaseChildListenerCount(eventClass, count);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class ListenerEntry<T extends Event> {
|
private static class ListenerEntry<T extends Event> {
|
||||||
|
Loading…
Reference in New Issue
Block a user