Start adding implementation

This commit is contained in:
Zontreck 2023-10-12 13:31:27 -07:00
parent 5872c2f913
commit b7c272ca09
5 changed files with 73 additions and 3 deletions

5
.gitignore vendored
View file

@ -22,3 +22,8 @@
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
replay_pid*
.gradle
build

View file

@ -0,0 +1,11 @@
package dev.zontreck.eventsbus;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Retention(value = RetentionPolicy.RUNTIME)
@Target(value = ElementType.TYPE)
public @interface Cancellable {
}

View file

@ -1,7 +1,37 @@
package dev.zontreck.eventsbus;
public class Event {
private boolean cancelled = false;
public class Event
{
/**
* Checks if the event can be cancelled.
*
* @see Cancellable
* @return True if the cancellation annotation is present.
*/
public boolean IsCancellable() {
Class<?> Current = this.getClass();
return Current.isAnnotationPresent(Cancellable.class);
}
/**
* Checks if the event is cancelled.
*
* @return False if the event cannot be cancelled, or returns the current status
* for the event.
*/
public boolean isCancelled() {
if (!IsCancellable())
return false;
return cancelled;
}
/**
* Sets the cancelled status for the event
*
* @param cancel Whether the event should be marked as cancelled or not.
*/
public void setCancelled(boolean cancel) {
cancelled = cancel;
}
}

View file

@ -0,0 +1,9 @@
package dev.zontreck.eventsbus;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@Retention(value = RetentionPolicy.RUNTIME)
public @interface Priority {
public PriorityLevel Level = PriorityLevel.LOW;
}

View file

@ -0,0 +1,15 @@
package dev.zontreck.eventsbus;
/**
* Event priority level.
*
* The higher the priority, the sooner it gets executed. High is executed after
* Highest.
*/
public enum PriorityLevel {
HIGHEST,
HIGH,
MEDIUM,
LOW,
LOWEST
}