Welcome to EventLib, your user-friendly Java event library using sockets for seamless communication between various applications.
Add the following repository to your pom.xml
:
<repository>
<id>maven-releases</id>
<url>https://nexus.synclyn.com/repository/maven-public/</url>
</repository>
Then, include the dependency:
<dependency>
<groupId>at.jkvn.eventlib</groupId>
<artifactId>EventLib</artifactId>
<version>LATEST</version>
</dependency>
For Gradle, add this repository to your build.gradle
:
maven {
url = uri("https://nexus.synclyn.com/repository/maven-public/")
}
Then, include the dependency:
implementation("at.jkvn.eventlib:EventLib:LATEST")
Integrating EventLib into your project is straightforward:
EventLib.configure(Configuration.builder()
.type(ListenerRegistryType.AUTOMATIC)
.build());
No need to register listeners if you use ListenerRegistryType.AUTOMATIC. If you opt for ListenerRegistryType.MANUAL, implement your class with the Listener interface.
ListenerRegistryType.MANUAL
class MyListener implements Listener {
public void onStartup(StartupEvent event) {
System.out.println("Server started");
}
}
ListenerRegistryType.AUTOMATIC
class MyListenerNoRegistration {
@EventHandler
public void onStartup(StartupEvent event) {
System.out.println("Server started");
}
}
Then register your listeners:
EventLib.registerListener(new MyListener());
EventLib.registerListeners(new MyListener(), new YourFavoriteListener());
class StartupEvent extends Event {}
EventLib.call(new StartupEvent());
You can set the priority of an event with our built-in @Priority annotation. This tells you that the event with the HIGHEST priority is executed first and then the next and the next EventLib supports the following event priorities:
EventPriority.LOWEST
EventPriority.LOW
EventPriority.NORMAL
(default)EventPriority.HIGH
EventPriority.HIGHEST
@EventHandler
@Priority(EventPriority.HIGHEST)
public void onListenYourFavoriteEvent(YourFavoriteEvent event) {
System.out.print("This event is executed first");
}
@EventHandler
@Priority(EventPriority.HIGH)
public void onListenYourFavoriteEvent(YourFavoriteEvent event) {
System.out.print("This event is executed after the HIGHEST event");
}
@EventHandler
@Priority(EventPriority.NORMAL)
public void onListenYourFavoriteEvent(YourFavoriteEvent event) {
System.out.print("This event is executed after the HIGH event");
}
EventLib provides additional features such as event cancellation and resumption:
@EventHandler
public void onListenYourFavoriteEvent(YourFavoriteEvent event) {
int i = 0;
if (i > 0) {
event.cancel(); // Event is cancelled
}
System.out.print("All listeners of these event are stopped when i is bigger as 0");
}
To resume an event:
@EventHandler
public void onListenYourFavoriteEvent(YourFavoriteEvent event) {
int i = 0;
if (i > 0) {
event.cancel(); // Event is cancelled
if (event.isCancelled()) {
i = 0;
event.uncancel(); // Event is uncancelled because i = 0
}
}
}
- Asynchronous events
- Event cancellation
- Event listener registration
- Event listener deregistration
- Event listener priority
- Socket connection
- Socket authentication (password, private key, etc.)
The contents of this repository are licensed under the Apache License, version 2.0.