Events are the primary mechanism for initiating and handling actions in Terasology. Events can be generated by keyboard or mouse input, by console commands or interacting with UI elements, by the game world through collisions or npc actions, or on-demand by mods. When Systems register to handle events, they can access properties of the event, as well call methods to cancel or consume the event.
Each Event goes through a predictable lifecycle that contols which handers will have access to the event. First a qualification phase, where the event can be cancelled, then an execution phase where the event can be consumed, and finally a post-execution phase.
The qualification phase occurs "before" the event will occur. At this point the
The Event.cancel()
method can be invoked, and once the event is cancelled is
will no longer propogate through any further handlers.
The execution phase occurs while the event is occuring. At this point the
cancel
method is no longer available, and if invoked will throw an error. Any
event handler can however call the Event.consume()
method, indicating that the
action of the method has been accomplished and thus will not be processed by any
further execution handlers.
The post execution phase occurs after the event has occured. At this point
neither the cancel
nor the consume
method is available, and all
post-execution handlers are guaranteed to execute.