Listener annotations on classes implementing EventListener?
Listener annotations / filtering annotations should ideally have an API exposed method of accomplishing the same goals as annotating classes with @Listener
At the moment it doesn't seem possible to filter cancellation status of classes implementing EventHandler.
Not sure if this is an API design issue, or an implementation issue at this stage.
@wolfizen
Yea. I have a use case where I want to both use Event Filters (@IsCancelled specifically) and dynamic registration registerListener(plugin, T.class, EventListener<T>). This should of course be extended to any filtering annotation, not just cancellation.
An example of how I think this would work:
class MyEventListener<T extends Event> implements EventListener<T> {
@Override
@IsCancelled(Tristate.UNDEFINED)
public void handle(T event) throws Exception {
// do something, like log the event
Sponge.getServer().getConsole().sendMessage(Text.of(event.getCause()));
}
}
Sponge.getEventManager().registerListener(plugin, SomeEvent.class, new MyEventListener<>())
Sponge.getEventManager().registerListener(plugin, AnotherEvent.class, new MyEventListener<>())
...
Any annotation on the implemented interface method handle() would be treated the same as an annotation on a @Listener method.
We could definitely support the method level annotations like @IsCancelled but I'm not sure how we could/should support parameter annotations in a clean way?
I see the point. Since the goal of an EventListener is to provide an interface, supporting arbitrary method parameters would prevent that. Looks like if this does get implemented it will have to be for method annotations only.