SpigotMC/BungeeCord — pull request #609 by daboross (2013-09-06 05:20:21+00:00)
Title: Add priorities to BungeeCord EventBus (Based on #562 & #563)

Reasoning for this request
--------------------------------------
* This pull request attempts to add EventPriorities to the BungeeCord event system without sacrificing performance when calling events.
* It was originally based on #562 and #563, though I've looked at the problems in those pull requests' * code and I believe this pull request fixes / does not have them.
* This allows the same flexibility in registering and ordering events that is in the Bukkit system.

Overview of changes
------------------------------
* Add EventPriority enum with 6 priorities.
* Change EventHandler's ```Map, Map>``` into two maps.
* Add EventHandlerMethod - A wrapper class containing a method and the listener for that method.
** The first map, ```Map>> byListenerAndPriority``` will be used for keeping track of what listeners are registered, ordered by priority.
** The second map, ```Map byEventBaked``` contains one array of EventHandlerMethods that is ordered by priority. This map will be used when an event is called, and will be updated whenever byListenerAndPriority is updated.
* EventPriorityTest - This test tests that events are called in order of priority with two separate listeners.
* UnregisterListenerTest - This test tests that the EventBus correctly unregisters listeners.

Speed differences
--------------------------
* The EventBus loops through only one array gotten from byEventBaked which is already in order of priority. This shouldn't be any slower (may even be faster) than looping through one array for each listener.
* This will slow down registering listeners because the EventHandlerMethod[] in byEventBaked is recreated for every event that the plugin registers. Though I'm thinking that this won't be an issue because plugins mainly register listeners on load / not very frequently.