You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
repositories {
// Other repos go here, eg. mavenCentral()
maven { url 'https://jitpack.io' }
}
Add the dependency
dependencies {
implementation 'com.github.AverseMoon:SimpleEventBus:VERSION'// replace VERSION with the version, eg. "v1.0"
}
Some example code to get you started:
importnet.simpleeventbus.EventBus;
importnet.simpleeventbus.event.Event;
importnet.simpleeventbus.Subscribe;
publicclassMain {
publicstaticvoidMain(String[] args) {
EventBusmybus = EventBus.createDefault(); // Create a basic event busmybus.registerEventType(MyEvent.class); // Register the custom eventmybus.register(Main.class); // Register any (static) @Subscribe annotations in this class, you can also replace `Main.class` with `this` in a non static contextmybus.post(newMyEvent("Hello World!"));
}
// Simple event listener that listens for all derived events, also remove static if it is in a non static context, you can leave static if you want though.@SubscribepublicstaticvoidonEvent(Eventevt) {
System.out.println("Event recieved!");
}
// Simple event listener that listens for only our custom event class (MyEvent)@SubscribepublicstaticvoidonMyEvent(MyEventevt) {
System.out.println("MyEvent recieved!");
System.out.println(evt.param);
}
}
publicclassMyEventextendsEvent {
publicStringparam;
publicMyEvent(Stringparam) {
this.param = param;
}
}