SpongeAPI icon indicating copy to clipboard operation
SpongeAPI copied to clipboard

Add IgnoreCauseObject of sorts for event listeners

Open gabizou opened this issue 9 years ago • 2 comments

Basically, given this code:

@Listener
public void onSpawn(SpawnEntityEvent event, @Root SpawnCause cause) {
  if (event.getCause().first(myplugin.getClass()).isPresent()) {
    return;
  }
}

We could easily do this for people as well where plugins are inherently throwing events with their own objects for "flagging" essentially. This way plugins don't have the chance to catch their own entity spawns or whatever (since the inverse is already supported with @First).

gabizou avatar Feb 01 '16 05:02 gabizou

Could be implemented as `Class<?>[] excludeTypes() default {}; on all of the cause parameter filters.

Or perhaps more cleanly would be a method annotation @IgnoreCause which takes a set of classes and checks cause.contains. Not sure which would be more useful/friendly.

Deamon5550 avatar Feb 01 '16 08:02 Deamon5550

@Deamon5550 I'm pretty sure we added something for this already? or is it still planned?

gabizou avatar Apr 28 '16 18:04 gabizou