← Back to Home

SmeagleBus

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.

Installing

Add Jitpack to your build.gradle file:

maven { url 'https://jitpack.io' }

Then add SmeagleBus to your dependencies:

implementation 'com.github.strubium:SmeagleBus:1.0.0'

Usage

Getting the Event Bus

You can get the SmeagleBus instance like this:

SmeagleBus bus = SmeagleBus.getInstance();

Registering Listeners

You can register a listener for an event type by using the listen() method. You can also specify a custom priority (default is 5):


bus.listen(MyEvent.class)
   .priority(10)  // Optional: Set a custom priority
   .subscribe(event -> {
       System.out.println("Handling event with priority 10");
   });
    

Posting Events

To post an event to the bus, use the post() method:

bus.post(new MyEvent());

Events are just classes. To make an event cancelable, extend CancelableEvent.

GitHub: strubium/SmeagleBus