Home Commands Examples Getting Started With Scripts Global Keywords

EventManager

Manages the registration and handling of custom handlers for the various events of the game.

You can register event handlers for pretty much everything, but make sure that the class you are referencing is documented as an event, otherwise you’re in for a nasty surprise.

Importing the class

It might be required for you to import the package if you encounter any issues (like casting an Array), so better be safe than sorry and add the import at the very top of the file.

script.zs
import crafttweaker.api.events.EventManager;

Methods

Registers a new event listener.

script.zs
EventManager.register<T : Object>(consumer as Consumer<T>)
ParameterTypeDescription
Parameter
consumer
Type
Consumer<T>
Description
The event handler.
Parameter
T
Type
Object
Description
The type of the event.

Registers a new event listener that can listen to cancelled events.

script.zs
EventManager.register<T : Object>(listenToCanceled as boolean, consumer as Consumer<T>)
ParameterTypeDescription
Parameter
listenToCanceled
Type
boolean
Description
Whether cancelled events should also be listened to or not.
Parameter
consumer
Type
Consumer<T>
Description
The event handler.
Parameter
T
Type
Object
Description
The type of the event.

Registers a new event listener for the specified EventPhase.

script.zs
EventManager.register<T : Object>(phase as EventPhase, consumer as Consumer<T>)
ParameterTypeDescription
Parameter
phase
Type
EventPhase
Description
The phase on which the event should be registered.
Parameter
consumer
Type
Consumer<T>
Description
The event handler.
Parameter
T
Type
Object
Description
The type of the event.

Registers a new event listener for the specified EventPhase that can listen to cancelled events.

script.zs
EventManager.register<T : Object>(phase as EventPhase, listenToCanceled as boolean, consumer as Consumer<T>)
ParameterTypeDescription
Parameter
phase
Type
EventPhase
Description
The phase on which the event should be registered.
Parameter
listenToCanceled
Type
boolean
Description
Whether cancelled events should also be listened to or not.
Parameter
consumer
Type
Consumer<T>
Description
The event handler.
Parameter
T
Type
Object
Description
The type of the event.