https://github.com/kvdpxne/thrivi
A simple library that allows you to easily and effectively create an event management architecture.
https://github.com/kvdpxne/thrivi
event event-driven event-handler event-listener java java-library library
Last synced: 12 months ago
JSON representation
A simple library that allows you to easily and effectively create an event management architecture.
- Host: GitHub
- URL: https://github.com/kvdpxne/thrivi
- Owner: kvdpxne
- License: mit
- Created: 2024-01-01T15:47:48.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2024-01-09T17:51:16.000Z (about 2 years ago)
- Last Synced: 2025-01-21T15:13:21.718Z (about 1 year ago)
- Topics: event, event-driven, event-handler, event-listener, java, java-library, library
- Language: Java
- Homepage:
- Size: 76.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## Usage
Create your own event by extending the ``Event`` or ``CancellableEvent``
object if you want your event to be cancelable.
```java
import me.kvdpxne.thrivi.CancellableEvent;
public class OurEvent extends CancellableEvent {
private final String projectName;
public OurEvent(final String projectName) {
this.projectName = projectName;
}
public String getProjectName() {
return this.projectName;
}
}
```
Create a listener for your event or events. It does not matter whether there
will be 1 or more event handlers in one object.
```java
import me.kvdpxne.thrivi.EventHandler;
import me.kvdpxne.thrivi.EventListener;
public class OurEventListener implements EventListener {
// Access modifiers doesn't matter.
final EventHandler ourEventHandler = this.handler(event -> {
final String name = event.getProjectName();
System.out.printf("The name of this project is: %s%n", name);
if (name.equals("thrivi")) {
System.out.printf("Yes, our project name is %s%n", name);
}
});
}
```
Register your previously created event and event listener.
```java
import me.kvdpxne.thrivi.BuiltInEventManager;
public final class Main {
public static void main(final String[] args) {
// 1. Register event.
BuiltInEventManager.INSTANCE.addEvent(OurEvent.class);
// 2. Register event listener.
// The easiest way to register the listener of our event in this case will
// be to simply initialize the object.
new OurEventListener();
// 3. trigger the registered event whenever and wherever you want.
final String[] names = {
"event",
"event-listener",
"thrivi"
};
for (final String name : names) {
BuiltInEventManager.INSTANCE.callEvent(new OurEvent(name));
}
}
}
```