Giter VIP home page Giter VIP logo

wraith's Introduction

logo

Wraith

GitHub all releases GitHub release (latest SemVer)

Lightweight Java event library created and maintained by 7orivorian

Importing

Maven

  • Include JitPack in your maven build file
<repositories>
    <repository>
        <id>jitpack.io</id>
        <url>https://jitpack.io</url>
    </repository>
</repositories>
  • Add Wraith as a dependency
<dependency>
    <groupId>com.github.7orivorian</groupId>
    <artifactId>Wraith</artifactId>
    <version>3.3.0</version>
</dependency>

Gradle

  • Add JitPack to your root build.gradle at the end of repositories
repositories {
    maven {
        url 'https://jitpack.io'
    }
}
  • Add the dependency
dependencies {
    implementation 'com.github.7orivorian:Wraith:3.3.0'
}

Other

Download a .jar file from releases

Building

  • Clone this repository
  • Run mvn package

Packaged file can be found in the target/ directory.

Quick-Start Guide

While the code itself is thoroughly documented, here's a simple guide to help you get started with the latest features.

Subscribers

Details...

To define a subscriber, you have multiple options:

Extending the Subscriber class:

public class ExampleSubscriber extends Subscriber {
// ...
}

Implementing the ISubscriber interface:

public class ExampleSubscriber implements ISubscriber {
// ...
}

Once you've defined your subscriber, you can subscribe it to an event bus directly within the subscriber's constructor:

public class Consts {
    private static final IEventBus EVENT_BUS = new EventBus();
}

public class ExampleSubscriber extends Subscriber {

    public ExampleSubscriber() {
        Consts.EVENT_BUS.subscribe(this);
    }
}

Alternatively, you can subscribe a subscriber externally:

public class Example {
    private static final IEventBus EVENT_BUS = new EventBus();

    public static void main(String[] args) {
        EVENT_BUS.subscribe(new ExampleSubscriber());
    }
}

Defining Events

Details...

Any class can be used as an event. For instance:

public class ExampleEvent {
    private String message;

    public ExampleEvent(String message) {
        this.message = message;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }
}

Listeners

Details...

For class event listeners, you can define your listeners as follows:

public class ExampleListener extends EventListener<ExampleEvent> {

    public ExampleListener() {
        super(ExampleEvent.class);
    }

    @Override
    public void invoke(ExampleEvent event) {
        event.setMessage("Hello world!");
    }
}
public class ExampleSubscriber extends Subscriber {

    public ExampleSubscriber() {
        // Register the listener
        registerListener(new ExampleListener());
    }
}

Lambda event listeners provide a more concise way to achieve the same functionality:

public class ExampleSubscriber extends Subscriber {

    public ExampleSubscriber() {
        // Register the listener
        registerListener(
                new LambdaEventListener<>(ExampleEvent.class, event -> event.setMessage("Hello world!"))
        );
    }
}

Dispatching Events

Details...

To dispatch an event, call one of the dispatch methods defined in EventBus, passing your event as a parameter:

import me.tori.wraith.event.staged.EventStage;

public class Example {

    private static final IEventBus EVENT_BUS = new EventBus();

    public static void main(String[] args) {

        ExampleEvent event = new ExampleEvent("world greetings");

        EVENT_BUS.dispatch(event);

        System.out.println(event.getMessage());
    }
}

Please explore the example folder for even more Wraith implementations!

Contributing

Contributions are welcome! Feel free to open a pull request.

Guidelines

  • Utilize similar formatting and practises to the rest of the codebase
  • Do not include workspace files (such as an .idea/ or target/ directory) in your pull request
  • Include unit tests for any features you add

How to contribute

To make a contribution, follow these steps:

  1. Fork and clone this repository
  2. Make the changes to your fork
  3. Submit a pull request

License

Wraith is licensed under MIT

MIT License Summary:

The MIT License is a permissive open-source license that allows you to use, modify, and distribute the software for both personal and commercial purposes. You are not required to share your changes, but you must include the original copyright notice and disclaimer in your distribution. The software is provided "as is," without any warranties or conditions.

wraith's People

Contributors

7orivorian avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

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.