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