Closed jedediah closed 8 years ago
Change the way events are dispatched to allow handlers to be wrapped "around" the event, like so:
@EventHandler void onEvent(ThingsHappenEvent event) { // before things happen event.yield(); // after things happen }
For this to work, the code calling the event needs to provide the "body" of the event when calling it:
pluginManager.callEvent(new ThingsHappenEvent(), event -> { if(!event.isCancelled()) { // make things happen } });
If I did this right, then it's not a breaking change, and code using the old API will continue to function as it did before.
Also, some formerly internal methods used by the event system have been exposed, to make 3rd party extensions easier to implement.
Also, instead of this boilerplate in every Event subclass:
Event
private static final HandlerList handlers = new HandlerList(); @Override public HandlerList getHandlers() { return handlers; } public static HandlerList getHandlerList() { return handlers; }
you now only need this boilerplate:
private static final HandlerList handlers = new HandlerList();
Change the way events are dispatched to allow handlers to be wrapped "around" the event, like so:
For this to work, the code calling the event needs to provide the "body" of the event when calling it:
If I did this right, then it's not a breaking change, and code using the old API will continue to function as it did before.
Also, some formerly internal methods used by the event system have been exposed, to make 3rd party extensions easier to implement.
Also, instead of this boilerplate in every
Event
subclass:you now only need this boilerplate: