SmeagleBus is a simple event bus implementation. It allows you to easily register listeners, post events, and handles events in priority order. It supports cancelable events, so if an event is canceled, further processing will stop.
Add Jitpack to your build.gradle file
maven { url 'https://jitpack.io' }
Add SmeagleBus to your dependencies block
implementation 'com.github.strubium:SmeagleBus:1.0.0'
You can get the SmeagleBus instance like this
SmeagleBus bus = SmeagleBus.getInstance();
You can register a listener for an event type by using the listen() method. You can also specify a custom priority, the default is 5.
bus.listen(MyEvent.class)
.priority(10) // Optional: Set a custom priority
.subscribe(event -> {
System.out.println("Handling event with priority 10");
});
To post an event to the bus, simply use the post() method:
bus.post(new MyEvent());
Events are just classes, and if you want them to be cancelable, have them extend CancelableEvent