fix: nullptr in case where event has no listeners

This commit is contained in:
zaaarf 2024-06-02 17:11:06 +02:00
parent 755a8e3a91
commit 216159feec
No known key found for this signature in database
GPG key ID: C91CFF9E2262BBA1

View file

@ -6,6 +6,7 @@ import ftbsc.geb.api.IEventDispatcher;
import ftbsc.geb.api.IListener; import ftbsc.geb.api.IListener;
import java.util.Map; import java.util.Map;
import java.util.Optional;
import java.util.ServiceLoader; import java.util.ServiceLoader;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
@ -69,6 +70,8 @@ public class GEB implements IBus {
*/ */
@Override @Override
public boolean handleEvent(IEvent event) { 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);
} }
} }