propagate listener changes to parents

This commit is contained in:
TheMode 2021-06-06 07:55:30 +02:00
parent 9594d848bc
commit c930eed412

View File

@ -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> {