Skip to content
/ EventLib Public

A simple event library using sockets written in java

License

Notifications You must be signed in to change notification settings

jkvn/EventLib

Repository files navigation

EventLib

⚠️ UNDER DEVELOPMENT ⚠️

Welcome to EventLib, your user-friendly Java event library using sockets for seamless communication between various applications.

Quick Start 🚀

Maven

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>

Gradle

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")

Integration 🛠️

Integrating EventLib into your project is straightforward:

Configuration:

EventLib.configure(Configuration.builder()
                .type(ListenerRegistryType.AUTOMATIC)
                .build());

Listener Registration:

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());

Example Event

class StartupEvent extends Event {}

Triggering Events:

EventLib.call(new StartupEvent());

Extras & Features 🎉

Priorities

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");
}

Cancellation

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
        }
    }
}

Future Plans 🛌

  • Asynchronous events
  • Event cancellation
  • Event listener registration
  • Event listener deregistration
  • Event listener priority
  • Socket connection
  • Socket authentication (password, private key, etc.)

License 📜

The contents of this repository are licensed under the Apache License, version 2.0.

About

A simple event library using sockets written in java

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages