feat: generic IEventDispatcher

This commit is contained in:
zaaarf 2024-09-01 12:54:33 +02:00
parent 81968f1c16
commit 15fd1373ce
No known key found for this signature in database
GPG key ID: 102E445F4C3F829B
2 changed files with 6 additions and 4 deletions

View file

@ -7,19 +7,20 @@ import java.util.Set;
* The interface that the generated dispatchers will all use.
* This interface isn't really meant to be used by humans, but it should work if your
* use case requires it.
* @param <T> the event this is for
* @since 0.1.1
*/
public interface IEventDispatcher {
public interface IEventDispatcher<T extends IEvent> {
/**
* Calls all listeners for the given event.
* @param event the event to call
* @param listeners a map mapping each {@link IListener} class to its instances
* @return the value {@link IBus#handleEvent(IEvent)} will return for this
*/
boolean callListeners(IEvent event, Map<Class<? extends IListener>, Set<IListener>> listeners);
boolean callListeners(T event, Map<Class<? extends IListener>, Set<IListener>> listeners);
/**
* @return the {@link Class} representing the event this dispatcher works with
*/
Class<? extends IEvent> eventType();
Class<T> eventType();
}

View file

@ -11,7 +11,8 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Marks the method as a listener. Its parent must implement the {@link IListener} interface
* Marks the method as a listener.
* If the method is not static, its parent must implement the {@link IListener} interface
* and be registered an at least one GEB instance with {@link IBus#registerListener(IListener)}.
* The annotated method should only take a single input value, an instance of {@link IEvent} or
* {@link IEventCancelable}.