Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mooziii/alert
🚨Alert is a really simple and blazing fast event listening api
https://github.com/mooziii/alert
events listening
Last synced: 11 days ago
JSON representation
🚨Alert is a really simple and blazing fast event listening api
- Host: GitHub
- URL: https://github.com/mooziii/alert
- Owner: mooziii
- License: mit
- Created: 2022-03-30T12:54:57.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-05-05T15:50:09.000Z (over 1 year ago)
- Last Synced: 2024-08-02T05:13:06.836Z (3 months ago)
- Topics: events, listening
- Language: Java
- Homepage:
- Size: 113 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
- awesome-blazingly-fast - alert - 🚨Alert is a really simple and blazing fast event listening api (Java)
README
# 🚨 alert
Alert is a really simple, easy to use and blazing fast event listening utility.
## Tutorial
### Add the dependency
The project is available on maven central.
Just add the dependency like this:#### Gradle (Kotlin)
```kotlin
implementation("me.obsilabor:alert:1.0.8")
```#### Gradle (Groovy)
```groovy
implementation 'me.obsilabor:alert:1.0.8'
```
*To shade the dependency into your jar, you probably want to use the shadow gradle plugin*#### Maven
```xml
me.obsilabor
alert
1.0.8```
*For maven you probably have to use any plugin that does the same as shadow, I have no idea how maven works*Kotlin Tutorial
### Create a event
Create a event by extending from `Event` (or if the event should be cancellable extend from `Cancellable`)
Example:
```kotlin
class RabbitJumpEvent(val rabbit: Rabbit) : Cancellable() {}
```Trigger the event using `EventManager.callEvent`. If you want to procces the event e.g. if it can be cancelled, you must store the event as a variable.
Example:
```kotlin
fun handleRabbitJumping(rabbit: Rabbit) {
val event = EventManager.callEvent(RabbitJumpEvent(this))
if(event.isCancelled) {
return
}
rabbit.jump()
}
```### Listen to a event
Create a listener just by creating a new class and in the init method, you can use the listen function just like in this example:
```kotlin
class RabbitJumpListener {
init {
subscribeToEvent {
//TODO: Do something cool :)
}
}
}
```*To prioritize subscriptions, you can change the priority parameter.*
```kotlin
class RabbitJumpListener {init {
subscribeToEvent(priority = EventPriority.HIGHEST) {
//TODO: Do something cool :)
}
}
}```
Triggering events in kotlin is just the same as in java
Java Tutorial
### Create a event
Create a event by extending from `Event` (or if the event should be cancellable extend from `Cancellable`)
Example:
```java
public class RabbitJumpEvent extends Cancellable {
private final Rabbit rabbit;
public RabbitJumpEvent(Rabbit rabbit) {
this.rabbit = rabbit;
}
public Rabbit getRabbit() {
return this.rabbit;
}
}
```Trigger the event using `EventManager.callEvent`. If you want to procces the event e.g. if it can be cancelled, you must store the event as a variable.
Example:
```java
public void handleRabbitJumping(Rabbit rabbit) {
RabbitJumpEvent event = EventManager.callEvent(event);
if(event.isCancelled()) {
return;
}
rabbit.jump();
}
```### Listen to a event
Create a listener just by creating a new class and a method annotated with @Subscribe. Add the event you want to listen to as an parameter.
```java
public class RabbitJumpListener {
@Subscribe
public void onRabbitJump(RabbitJumpEvent event) {
//TODO: Do something cool :)
}
}
```*To prioritize subscriptions, just set the priority value of the @Subscribe annotation*
```java
public class RabbitJumpListener {
@Subscribe(priority = EventPriority.HIGHEST)
public void onRabbitJump(RabbitJumpEvent event) {
//TODO: Do something cool :)
}
}
```