Very simple event emitter library made in java
It creates "channels" which can be fired events upon. You can assign each callback a priority and cancel it during the callback (Callbacks already fired will not be reversed somehow). Events can be anything as long as they extend the Event class.
dependencies {
implementation 'io.github.phoenixorigin:eventemitter:1.0.0'
}
dependencies {
implementation("io.github.phoenixorigin:eventemitter:1.0.0")
}
EventEmitter<? extends Event> eventEmitter = new EventEmitter<>();
Handling Event
eventEmitter.on("channel", ((channel, event) -> {
CustomEvent event = (CustomEvent) event;
// Handle event
}));
Emitting Events
eventEmitter.emit("channel", new CustomEvent());
EventEmitter<CustomEvent> eventEmitter = new EventEmitter<>();
Handling Event
eventEmitter.on("channel", ((channel, event) -> {
// Handle event. Event will be an instance of whatever was set in EventEmitter instance.
// In this case, event will be an instance of CustomEvent
}));
Emitting Events
// Same as normal.
eventEmitter.emit("channel", new CustomEvent());
If you need to give certain events priorities over others, you can do
eventEmitter.on("channel", ((channel, event) -> {
System.out.println(event.e);
}), EventEmitter.Priority.LOW);
// Options are TOP, HIGH, MEDIUM, LOW (Low is default)
If you need to cancel an event for whatever reason, you can just do
eventEmitter.on("channel", ((channel, event) -> {
event.cancel();
}));
// Record the UUID of the eventhandler instance
String eventHandlerUUID = eventEmitter.on("channel", ((channel, event) -> {
// Whatever
}));
// Unregister the instance
eventEmitter.off(eventHandlerUUID);