1
0
Fork 0
mirror of https://github.com/xHyroM/lighteco.git synced 2024-11-25 00:01:05 +01:00

feat(api): add some basic event interfaces

This commit is contained in:
xHyroM 2023-08-04 16:14:45 +02:00
parent 7b6db1b887
commit 7913bbe8e6
No known key found for this signature in database
GPG key ID: BE0423F386C436AA
5 changed files with 66 additions and 0 deletions

View file

@ -0,0 +1,11 @@
package dev.xhyrom.lighteco.api.event;
import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.function.Consumer;
public interface EventBus {
<T extends LightEcoEvent> @NonNull EventSubscription<T> subscribe(@NonNull Class<T> eventClass, @NonNull Consumer<? super T> subscriber);
<T extends LightEcoEvent> @NonNull EventSubscription<T> subscribe(Object plugin, @NonNull Class<T> eventClass, @NonNull Consumer<? super T> subscriber);
}

View file

@ -0,0 +1,13 @@
package dev.xhyrom.lighteco.api.event;
import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.function.Consumer;
public interface EventSubscription<T extends LightEcoEvent> extends AutoCloseable {
@NonNull Class<T> getEventClass();
boolean isActive();
@NonNull Consumer<? super T> getHandler();
}

View file

@ -0,0 +1,10 @@
package dev.xhyrom.lighteco.api.event;
import dev.xhyrom.lighteco.api.LightEco;
import org.checkerframework.checker.nullness.qual.NonNull;
public interface LightEcoEvent {
@NonNull LightEco getLightEco();
@NonNull Class<? extends LightEcoEvent> getEventClass();
}

View file

@ -0,0 +1,11 @@
package dev.xhyrom.lighteco.api.event.currency;
import dev.xhyrom.lighteco.api.event.LightEcoEvent;
import dev.xhyrom.lighteco.api.event.util.Position;
import dev.xhyrom.lighteco.api.model.currency.Currency;
import org.checkerframework.checker.nullness.qual.NonNull;
public interface CurrencyRegisterEvent extends LightEcoEvent {
@Position(0)
@NonNull Currency<?> getCurrency();
}

View file

@ -0,0 +1,21 @@
package dev.xhyrom.lighteco.api.event.util;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Represents the position (index) of a parameter within an event.
* Used for information purposes only.
*/
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.SOURCE)
public @interface Position {
/**
* Represents the position (index) of a parameter.
*
* @return the position (index)
*/
int value();
}