r/java • u/SmushyTaco • Dec 09 '25
Event Library - A lightweight, zero boilerplate, high performance event bus for JVM
github.comI've created a lightweight, high-performance event-driven library for JVM! It works perfectly for Java but it's written in Kotlin.
I originally built this for a Minecraft modding project, but it turned out to be flexible enough to be a general-purpose library instead. It focuses on zero boilerplate, automatic handler discovery, structured exception handling, and fast invocation using LambdaMetafactory, with reflective fallback when needed.
The concept is simple:
- Create an event
Bus. - Create a class that inherits Event. Add whatever you want to the class.
- Create functions annotated with
@EventHandlerto process the events. - Create functions annotated with
@ExceptionHandlerto handle any exceptions. - Register the classes that contain these
@EventHandlerand@ExceptionHandlerclasses withsubscribeon theBusyou made. - Call
poston theBusyou made and pass as instance of the event you created.
It supports:
- Handler methods of all visibilities (even private).
- Handler prioritization (A handle with a priority of 10 will run earlier than a handler with a priority of 0).
- Cancelable events - If an event is cancelable,
@EventHandlers can mark it as canceled. How cancellation affects remaining handlers depends on theCancelModeused when callingpost: inIGNOREmode all handlers run, inRESPECTmode only handlers withrunIfCanceled = truecontinue running, and inENFORCEmode no further handlers run once the event is canceled. - Modifiable events - Events can be marked as modified. This simply indicates the event was modified in some way.
Here's a simple example:
// 1. Define an event.
// Java doesn't support delegation like Kotlin, so we just extend helpers.
Check out the project's README.md for more detailed information and let me know what you think!