CTEventManager
Link to cteventmanager
The event Manager is your go-to point if you want to register custom event handlers.
You can register EventHandlers for everything that derives from Event. Make sure to tell ZC of the type you are using, so that you can access the event's properties.
Importing the class
Link to 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.
ZenScript Copyimport crafttweaker.api.events.CTEventManager;
Static Methods
Link to static-methods
Name: register
Registers a new Event listener.
ZenScript Copy// CTEventManager.register<T : Event>(consumer as Consumer<T>)
CTEventManager.register<crafttweaker.api.event.entity.player.MCAnvilRepairEvent>((event) => {
var player = event.player;
var result = event.itemResult;
println("Player '" + player.name + "' crafted " + result.commandString);
});
CTEventManager.register<crafttweaker.api.event.MCEvent>((event) => {
//Don't actually register a consumer for every event
println("Some Event was captured");
});
Parameter | Type | Description |
---|---|---|
Parameter consumer | Type Consumer<T> | Description The event handler as consumer |
Parameter T | Type Event | Description The type of the event |
Name: register
Registers a new Event listener.
ZenScript Copy// CTEventManager.register<T : Event>(listenToCancelled as boolean, consumer as Consumer<T>)
CTEventManager.register<crafttweaker.api.event.entity.player.MCAnvilRepairEvent>(true, (event) => {
var player = event.player;
var result = event.itemResult;
println("Player '" + player.name + "' crafted " + result.commandString);
});
Parameter | Type | Description |
---|---|---|
Parameter listenToCancelled | Type boolean | Description should the event listen to cancelled events |
Parameter consumer | Type Consumer<T> | Description The event handler as consumer |
Parameter T | Type Event | Description The type of the event |
Name: register
Registers a new Event listener with a specific priority.
ZenScript Copy// CTEventManager.register<T : Event>(priority as EventPriority, consumer as Consumer<T>)
CTEventManager.register<crafttweaker.api.event.entity.player.MCAnvilRepairEvent>(EventPriority.HIGHEST, (event) => {
var player = event.player;
var result = event.itemResult;
println("Player '" + player.name + "' crafted " + result.commandString);
});
Parameter | Type | Description |
---|---|---|
Parameter priority | Type EventPriority | Description priority for this listener |
Parameter consumer | Type Consumer<T> | Description The event handler as consumer |
Parameter T | Type Event | Description The type of the event |
Name: register
Registers a new Event listener with a specific priority.
ZenScript Copy// CTEventManager.register<T : Event>(listenToCancelled as boolean, priority as EventPriority, consumer as Consumer<T>)
CTEventManager.register<crafttweaker.api.event.entity.player.MCAnvilRepairEvent>(true, EventPriority.HIGHEST, (event) => {
var player = event.player;
var result = event.itemResult;
println("Player '" + player.name + "' crafted " + result.commandString);
});
Parameter | Type | Description |
---|---|---|
Parameter listenToCancelled | Type boolean | Description should the event listen to cancelled events |
Parameter priority | Type EventPriority | Description priority for this listener |
Parameter consumer | Type Consumer<T> | Description The event handler as consumer |
Parameter T | Type Event | Description The type of the event |