TurboEvents
A lightweight event library for Turbo's mods.
Installation
First things first, let's get the maven repo in your project.
repositories {
maven("https://maven.turbojax.org/releases")
}Then, we can add the dependency.
dependencies {
implementation("org.turbojax:events:1.0.1")
}Usage
EventManager
The EventManager is the class that actually handles registering/unregistering listeners, and it provides a function that is used to call an event.
All of EventManager's functions are static.
Event and Cancellable
Event is the common interface of all events. It contains no functions to override, so it's mostly just used to easily mark events.
The system also provides the Cancellable interface, which extends Event and provides Cancellable#isCancelled and Cancellable#setCancelled to let you control the end state of an event. (Though cancellation is actually interpreted by the code calling the event).
Listeners and @Subscribe
Listener is an interface that marks a class as having subscriber methods. These methods are captured by the EventManager when the Listener is registered.
All subscriber methods must have 1 parameter, that being the event to listen for, and also have the void return type.
To note a subscriber method, you must also use the @Subscribe annotation.
This annotation also has an ignoreCancelled parameter that allows your subscriber to still run after an event was cancelled.
Listener provides a function, owns(RegisteredSubscriber subscriber). This function is used when determining what subscribers should be removed when a EventManager#unregister is called. By default, this checks listener.equals(subscriber.owner()).
Links
Source: https://github.com/turbojax/turboevents
Javadocs: https://maven.turbojax.org/javadoc/releases/org/turbojax/events/1.0.1