Git Product home page Git Product logo

eventlib's Introduction

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.

eventlib's People

Contributors

jkvn avatar swnck avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

swnck synclyn

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.