From 216159feecf779d86484764943495ec47c5a8ced Mon Sep 17 00:00:00 2001 From: zaaarf Date: Sun, 2 Jun 2024 17:11:06 +0200 Subject: [PATCH] fix: nullptr in case where event has no listeners --- src/main/java/ftbsc/geb/GEB.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/ftbsc/geb/GEB.java b/src/main/java/ftbsc/geb/GEB.java index 86e9be5..3a5adf0 100644 --- a/src/main/java/ftbsc/geb/GEB.java +++ b/src/main/java/ftbsc/geb/GEB.java @@ -6,6 +6,7 @@ import ftbsc.geb.api.IEventDispatcher; import ftbsc.geb.api.IListener; import java.util.Map; +import java.util.Optional; import java.util.ServiceLoader; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; @@ -69,6 +70,8 @@ public class GEB implements IBus { */ @Override public boolean handleEvent(IEvent event) { - return this.dispatchMap.get(event.getClass()).callListeners(event, this.listenerMap); + return Optional.ofNullable(this.dispatchMap.get(event.getClass())) + .map(dispatcher -> dispatcher.callListeners(event, this.listenerMap)) + .orElse(true); } }