SpongePowered/SpongeAPI — pull request #232 by sk89q (2014-11-26 05:38:34+00:00)
Title: Event callbacks

**This PR is merely for discussion and is not currently being considered for addition yet.**

This idea was proposed by Kobata to fix:

1. The duplication of Result and Cancellable.
2. The need for plugins to be able to disable vanilla behavior.
3. The need for plugins to be able to disable behavior added by other plugins.
4. To tweak properties of added behavior.

The basic tenants of this idea are:

* Each event would have a list of "callbacks" that would represent behavior.
* Callbacks could be cancelled individually.
* Properties on each callback could be changed (i.e. `callback.setYield(x)` for an explosion).
* Vanilla behavior would be added to the list of callbacks.
* After the dispatch of an event has completed, the callbacks would be executed, with the last-added callbacks executed first (LIFO).
* Vanilla would be the first callback added, so it would always run last. It would not be possible to reorder callbacks.

Unfortunately, the current proposal makes it pretty ugly:

```java
@Subscribe(order = Order.LAST)
public void onCommandEvent(final CommandEvent event) {
if (containsAlias(event.getCommand())) {
event.getCallbacks().add(new AbstractCallback() {
@Override
public void run() {
try {
call(event.getSource(), event.getCommand() + " " + event.getArguments(), Collections.emptyList());
} catch (CommandException e) {
log.warn("Failed to execute a command", e);
}
}
});

event.getCallbacks().cancelBaseGame();
}
}
```

Though it's extensible. You could cancel behavior added by another plugin.