Skip to content

Commit

Permalink
Merge pull request #6 from 7orivorian/4.0.0
Browse files Browse the repository at this point in the history
4.0.0
  • Loading branch information
7orivorian authored Aug 24, 2024
2 parents f3bdcb9 + 05584d8 commit 194c6c7
Show file tree
Hide file tree
Showing 48 changed files with 1,970 additions and 1,793 deletions.
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
### Wraith Specifics
developer-docs

### Java template
# Compiled class file
*.class
Expand Down Expand Up @@ -668,3 +665,6 @@ bh_unicode_properties.cache
# Sublime-github package stores a github token in this file
# https://packagecontrol.io/packages/sublime-github
GitHub.sublime-settings

### Project Specific ###
developer-docs/
12 changes: 12 additions & 0 deletions .run/test in Wraith.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="test in Wraith" type="JUnit" factoryName="JUnit" nameIsGenerated="true">
<module name="Wraith" />
<option name="MAIN_CLASS_NAME" value="" />
<option name="METHOD_NAME" value="" />
<option name="TEST_OBJECT" value="directory" />
<dir value="$PROJECT_DIR$/src/main/test" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
</component>
239 changes: 48 additions & 191 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,31 @@

# Wraith

![GitHub all releases](https://img.shields.io/github/downloads/7orivorian/Wraith/total?style=flat-square)
![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/7orivorian/Wraith?style=flat-square)
[![](https://jitci.com/gh/7orivorian/Wraith/svg)](https://jitci.com/gh/7orivorian/Wraith)
![GitHub all releases](https://img.shields.io/github/downloads/7orivorian/Wraith/total?style=flat)
![GitHub Release](https://img.shields.io/github/v/release/7orivorian/Wraith?sort=semver&style=flat&link=https%3A%2F%2Fgit.luolix.top%2F7orivorian%2FWraith%2Freleases%2Flatest)
![JitPack Release](https://jitpack.io/v/dev.7ori/Wraith.svg?style=flat)
[![JitCI](https://jitci.com/gh/7orivorian/Wraith/svg)](https://jitci.com/gh/7orivorian/Wraith)
![GitHub License](https://img.shields.io/github/license/7orivorian/Wraith?color=blue)

Lightweight Java event library created and maintained by [7orivorian](https://github.com/7orivorian)
Capable, versatile, and easy to use Java event library.

# Importing
## Key Features

### Maven
- Easily define your own events, listeners, & event buses.
- Out-of-the-box support for any scenario.
- Performant.
- Fully documented.

* Include JitPack in your maven build file
## Usage

Click [here](https://docs.7ori.dev/wraith/importing) to learn how to import Wraith into your own project.
For more information, please see the Wraith [documentation](https://docs.7ori.dev/wraith/).

## Import with Build Automation

<details>
<summary>Maven</summary>
Include JitPack in your maven build file.

```xml

Expand All @@ -24,228 +38,71 @@ Lightweight Java event library created and maintained by [7orivorian](https://gi
</repositories>
```

* Add Wraith as a dependency
Add the dependency.

```xml

<dependency>
<groupId>com.github.7orivorian</groupId>
<artifactId>Wraith</artifactId>
<version>3.3.0</version>
<version>4.0.0</version>
</dependency>
```

### Gradle

* Add JitPack to your root `build.gradle` at the end of repositories
</details>
<details>
<summary>Gradle</summary>
Add JitPack to your root `build.gradle` at the end of repositories.

```gradle
```groovy
repositories {
//...
maven {
url 'https://jitpack.io'
}
}
```

* Add the dependency
Add the dependency.

```gradle
```groovy
dependencies {
implementation 'com.github.7orivorian:Wraith:3.3.0'
}
```

### Other

Download a `.jar` file from [releases](https://github.com/7orivorian/Wraith/releases/tag/3.3.0)

# 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>
<summary><i>Details...</i></summary>

To define a subscriber, you have multiple options:

Extending the Subscriber class:

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

Implementing the ISubscriber interface:

```java
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:

```java
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:

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

public static void main(String[] args) {
EVENT_BUS.subscribe(new ExampleSubscriber());
}
implementation 'com.github.7orivorian:Wraith:4.0.0'
}
```

</details>

### Defining Events

<details>
<summary><i>Details...</i></summary>
<summary>Gradle (Kotlin)</summary>
Add JitPack to your root `build.gradle.kts` at the end of repositories.

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

```java
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;
}
}
```

</details>

### Listeners

<details>
<summary><i>Details...</i></summary>

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

```java
public class ExampleListener extends EventListener<ExampleEvent> {

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

@Override
public void invoke(ExampleEvent event) {
event.setMessage("Hello world!");
}
}
```

```java
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:

```java
public class ExampleSubscriber extends Subscriber {

public ExampleSubscriber() {
// Register the listener
registerListener(
new LambdaEventListener<>(ExampleEvent.class, event -> event.setMessage("Hello world!"))
);
```groovy
repositories {
//...
maven {
url = uri("https://jitpack.io")
}
}
```

</details>

### Dispatching Events

<details>
<summary><i>Details...</i></summary>

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

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

public class Example {

private static final IEventBus EVENT_BUS = new EventBus();
Add the dependency.

public static void main(String[] args) {

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

EVENT_BUS.dispatch(event);

System.out.println(event.getMessage());
}
```groovy
dependencies {
implementation("com.github.7orivorian:Wraith:4.0.0")
}
```

</details>

Please explore the [example folder](./examples/java/me/tori/example) for _even more_ Wraith implementations!

# Contributing

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

### Guidelines

* Utilize similar [formatting](.editorconfig) 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:
## Download a Jar

1. Fork and clone this repository
2. Make the changes to your fork
3. Submit a pull request
Wraith and its sources can be downloaded
[here](https://github.com/7orivorian/Wraith/releases/latest).

# License
## License

[Wraith is licensed under MIT](./LICENSE)
[Wraith is licensed under MIT.](./LICENSE)

### MIT License Summary:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@
* THE SOFTWARE.
*/

package me.tori.example.persistence;
package dev.tori.example.persistence;

import me.tori.wraith.bus.EventBus;
import me.tori.wraith.bus.IEventBus;
import me.tori.wraith.listener.LambdaEventListener;
import me.tori.wraith.subscriber.Subscriber;
import dev.tori.wraith.bus.EventBus;
import dev.tori.wraith.bus.IEventBus;
import dev.tori.wraith.event.Target;
import dev.tori.wraith.listener.LambdaEventListener;
import dev.tori.wraith.subscriber.Subscriber;

/**
* A simple example of listener persistence.
Expand All @@ -40,7 +41,7 @@ class PersistenceExample {
private static final Subscriber SUBSCRIBER = new Subscriber() {{
// Register a listener that prints a single
// String event & is then removed from the event bus
registerListener(new LambdaEventListener<>(String.class, null, IEventBus.DEFAULT_PRIORITY, 1, System.out::println));
registerListener(new LambdaEventListener<String>(Target.fine(String.class), IEventBus.DEFAULT_PRIORITY, 1, System.out::println));
}};

public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@
* THE SOFTWARE.
*/

package me.tori.example.simple;
package dev.tori.example.simple;

import me.tori.wraith.bus.EventBus;
import me.tori.wraith.event.status.StatusEvent;
import me.tori.wraith.listener.LambdaEventListener;
import me.tori.wraith.subscriber.Subscriber;
import dev.tori.wraith.bus.EventBus;
import dev.tori.wraith.event.Target;
import dev.tori.wraith.event.status.StatusEvent;
import dev.tori.wraith.listener.LambdaEventListener;
import dev.tori.wraith.subscriber.Subscriber;

/**
* One-class example.
Expand All @@ -44,7 +45,7 @@ public static void main(String[] args) {
bus.subscribe(subscriber);

// Create a simple event
SimpleEvent event = new SimpleEvent("Pie is delicious <3");
StringEvent event = new StringEvent("Pie is delicious <3");

// Dispatch our event
bus.dispatch(event);
Expand All @@ -54,16 +55,16 @@ private static final class SimpleSubscriber extends Subscriber {

public SimpleSubscriber() {
registerListener(
new LambdaEventListener<>(SimpleEvent.class, event -> System.out.println(event.getMessage()))
new LambdaEventListener<StringEvent>(Target.fine(StringEvent.class), event -> System.out.println(event.getMessage()))
);
}
}

private static final class SimpleEvent extends StatusEvent {
private static final class StringEvent extends StatusEvent {

private final String message;

public SimpleEvent(String message) {
public StringEvent(String message) {
this.message = message;
}

Expand Down
Loading

0 comments on commit 194c6c7

Please sign in to comment.