SpongePowered/Sponge — pull request #39 by Raphfrk (2014-09-14 20:49:03+00:00)
Title: Basic Event handler framework

This is a basic event handler system. Only 3 events are supported at the moment. Two are FMLEvents and one is a forge (cpw) event.

It demonstrates

* ASM Transforms
* Annotation scan for SpongeEventHandler
* FMLEvent registration
* Forge (cpw) events

### ASM Transform

An EventTransformer is registered.

It adds an interface to all matching events so that they count as implementations of the matching SpongeAPI event.

It also adds the .getGame() method.

### Annotation scan

The EventHandler scans objects for methods annotated with the SpongeEventHandler annotation.

There are three types of events

* FMLEvents - these are handled by a HashMap lookup
* Forge (cpw) Events - these are handled using the fast EventBus/ListenerList system
* Other/Custom - These are not handled yet

### FMLEvent Registration

The SpongeEventHandler registers itself to receive all FMLEvents. FMLEvents are pretty rare, so this shouldn't represent much overhead.

The SpongeEventHandler keeps a HashMap of Class to list mappings and passes the event on to subsequent listeners.

### Forge (cpw) Events

Forge events use the fast (ASM assisted) EventBus system. These events potentially happen a lot so speed is critical.

The PR contains a more general version of Forge's ASM listener generator. It can generate a Listener of any interface type, and pass the event to any method of a given class. This handles the conversion.

Listeners of Forge's IEventListener interface are generated and submitted directly to the ListenerLists. This has the same effect as submitting through the event bus.

Priority is not supported in this PR.

### Other/Custom Events

The SpongeEventHandler has a call method to allow events to be submitted. If they are already of one of the standard classes, then they can be forwarded onward.

Another option would be that the method is changed to take CustomEvent as its input to make it clear that it isn't for the standard events.