diff --git a/.gitignore b/.gitignore index 524f096..2aa78f0 100644 --- a/.gitignore +++ b/.gitignore @@ -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 \ No newline at end of file diff --git a/src/main/java/dev/zontreck/eventsbus/Cancellable.java b/src/main/java/dev/zontreck/eventsbus/Cancellable.java new file mode 100644 index 0000000..a653b8d --- /dev/null +++ b/src/main/java/dev/zontreck/eventsbus/Cancellable.java @@ -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 { +} diff --git a/src/main/java/dev/zontreck/eventsbus/Event.java b/src/main/java/dev/zontreck/eventsbus/Event.java index d902937..88eba26 100644 --- a/src/main/java/dev/zontreck/eventsbus/Event.java +++ b/src/main/java/dev/zontreck/eventsbus/Event.java @@ -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; + } } \ No newline at end of file diff --git a/src/main/java/dev/zontreck/eventsbus/Priority.java b/src/main/java/dev/zontreck/eventsbus/Priority.java new file mode 100644 index 0000000..040338f --- /dev/null +++ b/src/main/java/dev/zontreck/eventsbus/Priority.java @@ -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; +} diff --git a/src/main/java/dev/zontreck/eventsbus/PriorityLevel.java b/src/main/java/dev/zontreck/eventsbus/PriorityLevel.java new file mode 100644 index 0000000..ee79431 --- /dev/null +++ b/src/main/java/dev/zontreck/eventsbus/PriorityLevel.java @@ -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 +}