From 3dc755f0c7b2385daddea1563ba91c727b37a07b Mon Sep 17 00:00:00 2001 From: zaaarf Date: Tue, 4 Jun 2024 23:01:35 +0200 Subject: feat: isRegistered method on IBus --- src/main/java/ftbsc/geb/GEB.java | 6 ++++++ src/main/java/ftbsc/geb/api/IBus.java | 9 ++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/main/java/ftbsc/geb/GEB.java b/src/main/java/ftbsc/geb/GEB.java index 3a5adf0..969045f 100644 --- a/src/main/java/ftbsc/geb/GEB.java +++ b/src/main/java/ftbsc/geb/GEB.java @@ -63,6 +63,12 @@ public class GEB implements IBus { ); } + @Override + public boolean isRegistered(IListener listener) { + Set listeners = this.listenerMap.get(listener.getClass()); + return listeners != null && listeners.contains(listener); + } + /** * Dispatches an event, calling all of its listeners that are subscribed to this bus. * @param event the event to fire diff --git a/src/main/java/ftbsc/geb/api/IBus.java b/src/main/java/ftbsc/geb/api/IBus.java index 485cf74..867bf7a 100644 --- a/src/main/java/ftbsc/geb/api/IBus.java +++ b/src/main/java/ftbsc/geb/api/IBus.java @@ -13,11 +13,18 @@ public interface IBus { void registerListener(IListener listener); /** - * Unregister a listener from the bus. + * Unregisters a listener from the bus. * @param listener the listener */ void unregisterListener(IListener listener); + /** + * Tells you whether a listener is currently registered. + * Ideally this should be efficient. + * @return true if the listener is registered + */ + boolean isRegistered(IListener listener); + /** * Dispatches an event, calling all of its listeners that are subscribed to this bus. * @param event the event to fire -- cgit v1.2.3-56-ga3b1