Skip to content
Univise edited this page Apr 28, 2017 · 3 revisions

What is the Event Subsystem?

The Event Subsystem implements a framework to pass system-wide events anonymously allowing classes to be decoupled. Whenever an important event has occurred (informing event), or is about to happen (interactive event) the system in question may broadcast this information and all listeners registered may act accordingly. If the event is called before an actual action is taken, it is even possible for listeners to modify the event's data and the event caller may continue its task with the overridden data.

An example use case would be this: Consider an arrow class which just hit a player and now needs to apply damage. Using the system, an event containing information on the arrow in question, the player damage will be applied to, and the actual damage that will be applied may be called BEFORE the damage is actually applied. Listeners can then override this damage and when all listeners have been run, the arrow class uses the damage that was set in the event. Why do this? It allows the arrow class to be simple: the arrow no longer needs to know the logic that is behind how much damage must be applied - it can simply set a default value and a system of arbitrary complexity can determine the damage.

This system first originated in Bukkit, an old set of server hosting software that used to run the majority of Minecraft servers at the time; it is a proven system that was used to make thousands of plug-ins.

Clone this wiki locally