From 1c9d91f871bb57eebab39a06dd2caf8a439517be Mon Sep 17 00:00:00 2001 From: 7orivorian <7orivorian+github@gmail.com> Date: Sat, 22 Jun 2024 02:25:31 -0400 Subject: [PATCH 01/26] Add comments to TaskExecutorTest.java Signed-off-by: 7orivorian <7orivorian+github@gmail.com> --- .../wraith/taskexecutor/TaskExecutorTest.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/main/test/me/tori/wraith/taskexecutor/TaskExecutorTest.java b/src/main/test/me/tori/wraith/taskexecutor/TaskExecutorTest.java index 8b18593..d80cb1f 100644 --- a/src/main/test/me/tori/wraith/taskexecutor/TaskExecutorTest.java +++ b/src/main/test/me/tori/wraith/taskexecutor/TaskExecutorTest.java @@ -42,28 +42,42 @@ public void run() { @Test public void testDelayedSingleExecution() { TaskExecutor executor = new TaskExecutor(); - executor.schedule(new ScheduledTask(TargetEvent.class, 1) { // Skip 1 event + + // Schedule a task to execute after skipping 1 event + executor.schedule(new ScheduledTask(TargetEvent.class, 1) { @Override public void run() { } }); + // This event should be skipped Assertions.assertFalse(executor.onEvent(new TargetEvent())); + + // Tasks should be executed on this event Assertions.assertTrue(executor.onEvent(new TargetEvent())); + + // This event should be skipped Assertions.assertFalse(executor.onEvent(new TargetEvent())); - executor.schedule(new ScheduledTask(TargetEvent.class, 3) { // Skip 3 events + + // Schedule a task to execute after skipping 3 events + executor.schedule(new ScheduledTask(TargetEvent.class, 3) { @Override public void run() { } }); + // These events should be skipped Assertions.assertFalse(executor.onEvent(new TargetEvent())); Assertions.assertFalse(executor.onEvent(new TargetEvent())); Assertions.assertFalse(executor.onEvent(new TargetEvent())); + + // Tasks should be executed on this event Assertions.assertTrue(executor.onEvent(new TargetEvent())); + + // This event should be skipped Assertions.assertFalse(executor.onEvent(new TargetEvent())); } From cdfbf71a09662696dc1088ac46a19aea40a8dfcb Mon Sep 17 00:00:00 2001 From: 7orivorian <7orivorian+github@gmail.com> Date: Sat, 22 Jun 2024 02:25:48 -0400 Subject: [PATCH 02/26] Update TaskExecutor.java Signed-off-by: 7orivorian <7orivorian+github@gmail.com> --- src/main/java/me/tori/wraith/task/TaskExecutor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/me/tori/wraith/task/TaskExecutor.java b/src/main/java/me/tori/wraith/task/TaskExecutor.java index 2311015..864af78 100644 --- a/src/main/java/me/tori/wraith/task/TaskExecutor.java +++ b/src/main/java/me/tori/wraith/task/TaskExecutor.java @@ -34,7 +34,7 @@ public TaskExecutor() { */ public boolean onEvent(Object event) { ArrayList queue = tasks.get(event.getClass()); - if (queue != null) { + if ((queue != null) && !queue.isEmpty()) { boolean executed = false; for (int i = 0; i < queue.size(); ) { ScheduledTask task = queue.get(i); From ae8a8f68651d037463ef6cac2f759562eb6f589b Mon Sep 17 00:00:00 2001 From: 7orivorian <7orivorian+github@gmail.com> Date: Sat, 22 Jun 2024 02:28:58 -0400 Subject: [PATCH 03/26] Impl optional listener persistence (default behavior remains unchanged) Signed-off-by: 7orivorian <7orivorian+github@gmail.com> --- .../java/me/tori/wraith/bus/EventBus.java | 142 ++++++++++++------ .../tori/wraith/listener/EventListener.java | 43 ++++++ .../me/tori/wraith/listener/Listener.java | 27 ++++ .../wraith/persistency/PersistencyTest.java | 59 ++++++++ 4 files changed, 229 insertions(+), 42 deletions(-) create mode 100644 src/main/test/me/tori/wraith/persistency/PersistencyTest.java diff --git a/src/main/java/me/tori/wraith/bus/EventBus.java b/src/main/java/me/tori/wraith/bus/EventBus.java index 7100c65..5b582c1 100644 --- a/src/main/java/me/tori/wraith/bus/EventBus.java +++ b/src/main/java/me/tori/wraith/bus/EventBus.java @@ -10,6 +10,8 @@ import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.CopyOnWriteArrayList; +import java.util.function.Consumer; +import java.util.function.Predicate; /** * Default implementation of {@link IEventBus}, {@link TargetableEventBus}, and {@link InvertableEventBus}. @@ -83,8 +85,13 @@ public static int getInstanceCount() { @Override public void subscribe(ISubscriber subscriber) { Objects.requireNonNull(subscriber, "Cannot subscribe null to event bus " + id + "!"); - for (Listener listener : subscriber.getListeners()) { - register(listener); + Collection> listeners = subscriber.getListeners(); + if (listeners.size() == 1) { + register(listeners.iterator().next()); + } else { + for (Listener listener : listeners) { + register(listener); + } } subscribers.add(subscriber); } @@ -100,8 +107,13 @@ public void subscribe(ISubscriber subscriber) { @Override public void unsubscribe(ISubscriber subscriber) { Objects.requireNonNull(subscriber, "Cannot unsubscribe null from event bus " + id + "!"); - for (Listener listener : subscriber.getListeners()) { - unregister(listener); + Collection> listeners = subscriber.getListeners(); + if (listeners.size() == 1) { + unregister(listeners.iterator().next()); + } else { + for (Listener listener : listeners) { + unregister(listener); + } } subscribers.remove(subscriber); } @@ -155,10 +167,13 @@ public boolean dispatch(Object event) { } else { taskExecutor.onEvent(event); - List listeners = this.listeners.get(event.getClass()); - if (listeners != null) { - listeners.forEach(listener -> listener.invoke(event)); - } + forEachListener( + this.listeners.get(event.getClass()), + listener -> true, + listener -> listener.invoke(event), + false + ); + if (event instanceof ICancelableEvent cancelable) { return cancelable.isCanceled(); } @@ -186,12 +201,13 @@ public boolean dispatch(Object event, Class type) { } else { taskExecutor.onEvent(event); - List listeners = this.listeners.get(event.getClass()); - if (listeners != null) { - listeners.stream() - .filter(listener -> (listener.getType() == null) || (listener.getType() == type)) - .forEach(listener -> listener.invoke(event)); - } + forEachListener( + this.listeners.get(event.getClass()), + listener -> (type == null) || (listener.getType() == null) || (listener.getType() == type), + listener -> listener.invoke(event), + false + ); + if (event instanceof ICancelableEvent cancelable) { return cancelable.isCanceled(); } @@ -215,12 +231,13 @@ public boolean dispatchTargeted(IClassTargetingEvent event) { } else { taskExecutor.onEvent(event); - List listeners = this.listeners.get(event.getClass()); - if (listeners != null) { - listeners.stream() - .filter(listener -> listener.getClass().equals(event.getTargetClass())) - .forEach(listener -> listener.invoke(event)); - } + forEachListener( + this.listeners.get(event.getClass()), + listener -> listener.getClass().equals(event.getTargetClass()), + listener -> listener.invoke(event), + false + ); + if (event instanceof ICancelableEvent cancelable) { return cancelable.isCanceled(); } @@ -248,13 +265,14 @@ public boolean dispatchTargeted(IClassTargetingEvent event, Class type) { } else { taskExecutor.onEvent(event); - List listeners = this.listeners.get(event.getClass()); - if (listeners != null) { - listeners.stream() - .filter(listener -> (listener.getType() == null) || (listener.getType() == type)) - .filter(listener -> listener.getClass().equals(event.getTargetClass())) - .forEach(listener -> listener.invoke(event)); - } + forEachListener( + this.listeners.get(event.getClass()), + listener -> ((type == null) || (listener.getType() == null) || (listener.getType() == type)) + && listener.getClass().equals(event.getTargetClass()), + listener -> listener.invoke(event), + false + ); + if (event instanceof ICancelableEvent cancelable) { return cancelable.isCanceled(); } @@ -279,13 +297,13 @@ public boolean dispatchInverted(Object event) { } else { taskExecutor.onEvent(event); - List listeners = this.listeners.get(event.getClass()); - if (listeners != null) { - ListIterator iterator = listeners.listIterator(listeners.size()); - while (iterator.hasPrevious()) { - iterator.previous().invoke(event); - } - } + forEachListener( + this.listeners.get(event.getClass()), + listener -> true, + listener -> listener.invoke(event), + true + ); + if (event instanceof ICancelableEvent cancelable) { return cancelable.isCanceled(); } @@ -314,21 +332,61 @@ public boolean dispatchInverted(Object event, Class type) { } else { taskExecutor.onEvent(event); - List listeners = this.listeners.get(event.getClass()); - if (listeners != null) { + forEachListener( + this.listeners.get(event.getClass()), + listener -> (type == null) || (listener.getType() == null) || (listener.getType() == type), + listener -> listener.invoke(event), + true + ); + + if (event instanceof ICancelableEvent cancelable) { + return cancelable.isCanceled(); + } + } + return false; + } + + /** + * Applies a given action to each {@linkplain Listener} in a list that matches a specified predicate. + * Listeners are processed either in normal order or in reverse order based on the + * {@code invertPriority} flag. + * Listeners that should not persist are removed from the list after the action is applied. + * + * @param listeners the list of listeners to be processed + * @param predicate the condition that each listener must satisfy to have the action applied + * @param action the action to be performed on each listener that satisfies the predicate + * @param invertPriority if {@code true}, listeners are processed in reverse order; otherwise, + * they are processed in normal order + * @since 3.1.0 + */ + private void forEachListener(List listeners, Predicate predicate, Consumer action, boolean invertPriority) { + if (listeners != null && !listeners.isEmpty()) { + if (invertPriority) { ListIterator iterator = listeners.listIterator(listeners.size()); while (iterator.hasPrevious()) { Listener listener = iterator.previous(); - if ((listener.getType() == null) || (listener.getType() == type)) { - listener.invoke(event); + if (!predicate.test(listener)) { + continue; + } + action.accept(listener); + if (!listener.shouldPersist()) { + listeners.remove(listener); + } + } + } else { + Iterator iterator = listeners.listIterator(0); + while (iterator.hasNext()) { + Listener listener = iterator.next(); + if (!predicate.test(listener)) { + continue; + } + action.accept(listener); + if (!listener.shouldPersist()) { + listeners.remove(listener); } } - } - if (event instanceof ICancelableEvent cancelable) { - return cancelable.isCanceled(); } } - return false; } /** diff --git a/src/main/java/me/tori/wraith/listener/EventListener.java b/src/main/java/me/tori/wraith/listener/EventListener.java index 1f200fa..891676c 100644 --- a/src/main/java/me/tori/wraith/listener/EventListener.java +++ b/src/main/java/me/tori/wraith/listener/EventListener.java @@ -18,6 +18,8 @@ */ public abstract class EventListener implements Listener { + protected int persists; + protected final boolean persistent; protected final int priority; protected final @Nullable Class type; protected final @NotNull Class target; @@ -63,10 +65,25 @@ public EventListener(@NotNull Class target, @Nullable Class type) * @throws NullPointerException if {@code target} is {@code null}. */ public EventListener(@NotNull Class target, int priority, @Nullable Class type) { + this(target, type, priority, -1); + } + + /** + * Constructs an event listener with a specified priority and type. + * + * @param target The target class that this listener is designed to handle events for. + * @param type The type of events that this listener can handle. + * @param priority The priority level of this listener for event handling. + * @param persists How many events this listener should handle before being killed. + * @throws NullPointerException if {@code target} is {@code null}. + */ + public EventListener(@NotNull Class target, @Nullable Class type, int priority, int persists) { Objects.requireNonNull(target); this.priority = priority; this.target = target; this.type = type; + this.persists = persists; + this.persistent = persists <= 0; } /** @@ -101,6 +118,32 @@ public Class getTarget() { return target; } + /** + * Determines whether this listener should persist after being invoked. + * The listener persists if it is inherently persistent (as determined by {@link #isPersistent()}) + * or if the {@linkplain EventListener#persists internal persistence counter} is greater than zero + * after being decremented. + * + * @return {@code true} if the listener should persist, {@code false} otherwise + * @since 3.1.0 + */ + @Override + public boolean shouldPersist() { + return isPersistent() || ((--persists) > 0); + } + + /** + * Indicates whether this listener is inherently persistent. + * A listener is considered inherently persistent if the {@linkplain #persistent} flag is set to {@code true}. + * + * @return {@code true} if the listener is inherently persistent, {@code false} otherwise + * @since 3.1.0 + */ + @Override + public boolean isPersistent() { + return persistent; + } + @Override public boolean equals(Object o) { if (this == o) { diff --git a/src/main/java/me/tori/wraith/listener/Listener.java b/src/main/java/me/tori/wraith/listener/Listener.java index 3ea8909..22bc4bc 100644 --- a/src/main/java/me/tori/wraith/listener/Listener.java +++ b/src/main/java/me/tori/wraith/listener/Listener.java @@ -1,5 +1,11 @@ package me.tori.wraith.listener; +import me.tori.wraith.bus.EventBus; + +import java.util.List; +import java.util.function.Consumer; +import java.util.function.Predicate; + /** * An interface representing an event listener with priority, type, and target class information. * @@ -31,4 +37,25 @@ public interface Listener extends Invokable { * @return The target class that this listener is designed to handle events for. */ Class getTarget(); + + /** + * Determines whether this listener should persist after being invoked. + * + * @return {@code true} if the listener should persist, {@code false} otherwise + * @see EventBus#forEachListener(List, Predicate, Consumer, boolean) + * @since 3.1.0 + */ + default boolean shouldPersist() { + return isPersistent(); + } + + /** + * Indicates whether this listener is inherently persistent. + * + * @return {@code true} if the listener is inherently persistent, {@code false} otherwise + * @since 3.1.0 + */ + default boolean isPersistent() { + return true; + } } \ No newline at end of file diff --git a/src/main/test/me/tori/wraith/persistency/PersistencyTest.java b/src/main/test/me/tori/wraith/persistency/PersistencyTest.java new file mode 100644 index 0000000..e5ae29b --- /dev/null +++ b/src/main/test/me/tori/wraith/persistency/PersistencyTest.java @@ -0,0 +1,59 @@ +package me.tori.wraith.persistency; + +import me.tori.wraith.bus.EventBus; +import me.tori.wraith.event.cancelable.CancelableEvent; +import me.tori.wraith.listener.EventListener; +import me.tori.wraith.subscriber.Subscriber; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +/** + * @author 7orivorian + * @since 3.1.0 + */ +public class PersistencyTest { + + @Test + public void testEventPersistency() { + final EventBus bus = new EventBus(); + + bus.subscribe(new Subscriber() {{ + registerListener(new MyListener(3)); + }}); + + Assertions.assertTrue(bus.dispatch(new MyEvent())); + Assertions.assertTrue(bus.dispatch(new MyEvent())); + Assertions.assertTrue(bus.dispatch(new MyEvent())); + + Assertions.assertFalse(bus.dispatch(new MyEvent())); + } + + @Test + public void testIndefiniteEvent() { + final EventBus bus = new EventBus(); + + bus.subscribe(new Subscriber() {{ + registerListener(new MyListener(0)); // <= 0 means persist indefinitely + }}); + + for (int i = 0; i < 1_000_000; i++) { + Assertions.assertTrue(bus.dispatch(new MyEvent())); + } + } + + public static class MyListener extends EventListener { + + public MyListener(int persists) { + super(MyEvent.class, null, 0, persists); + } + + @Override + public void invoke(MyEvent event) { + event.cancel(); + } + } + + public static class MyEvent extends CancelableEvent { + + } +} \ No newline at end of file From d9c179bdbe91778ba3482b6645dec9c904fa6b62 Mon Sep 17 00:00:00 2001 From: 7orivorian <7orivorian+github@gmail.com> Date: Sat, 22 Jun 2024 02:29:38 -0400 Subject: [PATCH 04/26] Impl JMH benchmarking Signed-off-by: 7orivorian <7orivorian+github@gmail.com> --- pom.xml | 10 ++ .../tori/wraith/benchmarking/MyBenchmark.java | 95 +++++++++++++++++++ 2 files changed, 105 insertions(+) create mode 100644 src/main/test/me/tori/wraith/benchmarking/MyBenchmark.java diff --git a/pom.xml b/pom.xml index d5a640a..08a4abd 100644 --- a/pom.xml +++ b/pom.xml @@ -19,6 +19,16 @@ RELEASE compile + + org.openjdk.jmh + jmh-core + 1.37 + + + org.openjdk.jmh + jmh-generator-annprocess + 1.37 + 3.1.0 diff --git a/src/main/test/me/tori/wraith/benchmarking/MyBenchmark.java b/src/main/test/me/tori/wraith/benchmarking/MyBenchmark.java new file mode 100644 index 0000000..ef96b41 --- /dev/null +++ b/src/main/test/me/tori/wraith/benchmarking/MyBenchmark.java @@ -0,0 +1,95 @@ +package me.tori.wraith.benchmarking; + +import me.tori.wraith.bus.EventBus; +import me.tori.wraith.listener.EventListener; +import me.tori.wraith.subscriber.Subscriber; +import org.openjdk.jmh.Main; +import org.openjdk.jmh.annotations.*; + +import java.util.concurrent.TimeUnit; + +/** + * @author 7orivorian + * @since 3.0.0 + */ +public class MyBenchmark { + + public static void main(String[] args) throws Exception { + Main.main(args); + } + + @State(Scope.Thread) + public static class BenchmarkState { + MyListener myListener; + MySubscriber mySubscriber; + EventBus bus; + + @Setup(Level.Trial) + public void setup() { + bus = new EventBus(); + mySubscriber = new MySubscriber(); + myListener = new MyListener(); + } + } + + @Benchmark + @BenchmarkMode(Mode.AverageTime) + @OutputTimeUnit(TimeUnit.MILLISECONDS) + @Warmup(iterations = 1, time = 2) + @Measurement(iterations = 2, time = 2) + @Fork(5) + public void testMethod(BenchmarkState state) { + for (int i = 0; i < 1_000; i++) { + state.bus.register(state.myListener); + } + } + + public static class MySubscriber extends Subscriber { + + public MySubscriber() { + registerListener( + new MyListener() + ); + } + } + + public static class MyListener extends EventListener { + + public MyListener() { + super(MyEvent.class); + } + + @Override + public void invoke(MyEvent event) { + System.out.println(event.content()); + } + + @Override + public boolean shouldPersist() { + return false; + } + } + + public static final class MyEvent { + + private String content; + + public MyEvent(String content) { + this.content = content; + } + + public String content() { + return content; + } + + public void setContent(String content) { + this.content = content; + } + + @Override + public String toString() { + return "MyEvent[" + + "content=" + content + ']'; + } + } +} \ No newline at end of file From f085b6da793ddd6b2245a34ab2c09faa80679bf7 Mon Sep 17 00:00:00 2001 From: 7orivorian <7orivorian+github@gmail.com> Date: Sat, 22 Jun 2024 02:29:51 -0400 Subject: [PATCH 05/26] Add ListenerBuilder.java Signed-off-by: 7orivorian <7orivorian+github@gmail.com> --- .../tori/wraith/listener/ListenerBuilder.java | 139 ++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 src/main/java/me/tori/wraith/listener/ListenerBuilder.java diff --git a/src/main/java/me/tori/wraith/listener/ListenerBuilder.java b/src/main/java/me/tori/wraith/listener/ListenerBuilder.java new file mode 100644 index 0000000..0be1ce9 --- /dev/null +++ b/src/main/java/me/tori/wraith/listener/ListenerBuilder.java @@ -0,0 +1,139 @@ +package me.tori.wraith.listener; + +import me.tori.wraith.bus.IEventBus; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.Objects; + +/** + * A builder class for creating instances of {@link EventListener}. + * + *

This builder allows configuring various properties of an {@link EventListener}, + * including the target class, type, priority, persistence, and the invokable action. + * + *

Usage Example: + *

+ * {@code
+ * EventListener listener = new ListenerBuilder()
+ *     .target(MyEvent.class)
+ *     .type(SomeSpecificType.class)
+ *     .priority(5)
+ *     .persists(10)
+ *     .invokable(event -> handleEvent(event))
+ *     .build();
+ * }
+ * 
+ * + * @param the type of event this listener handles + * @author 7orivorian + * @see EventListener + * @since 3.1.0 + */ +public class ListenerBuilder { + + private Class target = null; + private @Nullable Class type = null; + private int priority = IEventBus.DEFAULT_PRIORITY; + private int persists = -1; + private boolean persistent = true; + private Invokable invokable = null; + + /** + * Sets the target class for this listener. + * + * @param target the class of the event this listener will handle + * @return this {@code ListenerBuilder} instance + */ + public ListenerBuilder target(@NotNull Class target) { + this.target = target; + return this; + } + + /** + * Sets the specific type for this listener. + * + * @param type the specific type of event this listener will handle + * @return this {@code ListenerBuilder} instance + */ + public ListenerBuilder type(@Nullable Class type) { + this.type = type; + return this; + } + + /** + * Sets the priority for this listener. + * + * @param priority the priority of the listener + * @return this {@code ListenerBuilder} instance + */ + public ListenerBuilder priority(int priority) { + this.priority = priority; + return this; + } + + /** + * Sets the number of times this listener should persist. + *

+ * Overrides {@link #persistent}. + * + * @param persists the number of events this listener should handle before being removed + * @return this {@code ListenerBuilder} instance + */ + public ListenerBuilder persists(int persists) { + this.persists = persists; + this.persistent = persists <= 0; + return this; + } + + /** + * Sets whether this listener is inherently persistent. + *

+ * Overrides {@link #persists}. + * + * @param persistent {@code true} if the listener should be persistent, {@code false} otherwise + * @return this {@code ListenerBuilder} instance + */ + public ListenerBuilder persistent(boolean persistent) { + this.persistent = persistent; + if (persistent) { + return persists(0); + } + return this; + } + + /** + * Sets the invokable action for this listener. + * + * @param invokable the action to be invoked when an event is handled + * @return this {@code ListenerBuilder} instance + */ + public ListenerBuilder invokable(@NotNull Invokable invokable) { + this.invokable = invokable; + return this; + } + + /** + * Builds and returns an {@link EventListener} with the configured properties. + * + * @return a new {@link EventListener} instance + * @throws NullPointerException if the target or invokable is not set + * @throws IllegalArgumentException if there is a mismatch between persistence settings + */ + @NotNull + public EventListener build() { + Objects.requireNonNull(target, "target must not be null"); + Objects.requireNonNull(invokable, "invokable must not be null"); + if ((persistent && (persists > 0)) || (!persistent && (persists <= 0))) { + throw new IllegalArgumentException( + "Persistency missmatch. persistent=" + persistent + " and persists>" + persists + " is not allowed." + ); + } + return new EventListener<>(target, type, priority, persists) { + @Override + public void invoke(T event) { + invokable.invoke(event); + } + }; + } +} \ No newline at end of file From 64425de1b687bca9db42ce5731921e1d014122f3 Mon Sep 17 00:00:00 2001 From: 7orivorian <7orivorian+github@gmail.com> Date: Sat, 22 Jun 2024 02:30:57 -0400 Subject: [PATCH 06/26] Suppress Javadoc error in Listener.java Signed-off-by: 7orivorian <7orivorian+github@gmail.com> --- src/main/java/me/tori/wraith/listener/Listener.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/me/tori/wraith/listener/Listener.java b/src/main/java/me/tori/wraith/listener/Listener.java index 22bc4bc..5a0bc2c 100644 --- a/src/main/java/me/tori/wraith/listener/Listener.java +++ b/src/main/java/me/tori/wraith/listener/Listener.java @@ -45,6 +45,7 @@ public interface Listener extends Invokable { * @see EventBus#forEachListener(List, Predicate, Consumer, boolean) * @since 3.1.0 */ + @SuppressWarnings("JavadocReference") default boolean shouldPersist() { return isPersistent(); } From 4127d8cda4c0e3052c3db2d0ab73484fe0285690 Mon Sep 17 00:00:00 2001 From: 7orivorian <7orivorian+github@gmail.com> Date: Sun, 23 Jun 2024 19:42:39 -0400 Subject: [PATCH 07/26] Fix incorrect version labeling Signed-off-by: 7orivorian <7orivorian+github@gmail.com> --- src/main/java/me/tori/wraith/bus/EventBus.java | 2 +- src/main/java/me/tori/wraith/listener/EventListener.java | 5 +++-- src/main/java/me/tori/wraith/listener/Listener.java | 6 +++--- src/main/java/me/tori/wraith/listener/ListenerBuilder.java | 2 +- src/main/test/me/tori/wraith/benchmarking/MyBenchmark.java | 2 +- .../test/me/tori/wraith/persistency/PersistencyTest.java | 2 +- 6 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/main/java/me/tori/wraith/bus/EventBus.java b/src/main/java/me/tori/wraith/bus/EventBus.java index 5b582c1..75c5bc1 100644 --- a/src/main/java/me/tori/wraith/bus/EventBus.java +++ b/src/main/java/me/tori/wraith/bus/EventBus.java @@ -357,7 +357,7 @@ public boolean dispatchInverted(Object event, Class type) { * @param action the action to be performed on each listener that satisfies the predicate * @param invertPriority if {@code true}, listeners are processed in reverse order; otherwise, * they are processed in normal order - * @since 3.1.0 + * @since 3.2.0 */ private void forEachListener(List listeners, Predicate predicate, Consumer action, boolean invertPriority) { if (listeners != null && !listeners.isEmpty()) { diff --git a/src/main/java/me/tori/wraith/listener/EventListener.java b/src/main/java/me/tori/wraith/listener/EventListener.java index 891676c..5d63513 100644 --- a/src/main/java/me/tori/wraith/listener/EventListener.java +++ b/src/main/java/me/tori/wraith/listener/EventListener.java @@ -76,6 +76,7 @@ public EventListener(@NotNull Class target, int priority, @Nullable C * @param priority The priority level of this listener for event handling. * @param persists How many events this listener should handle before being killed. * @throws NullPointerException if {@code target} is {@code null}. + * @since 3.2.0 */ public EventListener(@NotNull Class target, @Nullable Class type, int priority, int persists) { Objects.requireNonNull(target); @@ -125,7 +126,7 @@ public Class getTarget() { * after being decremented. * * @return {@code true} if the listener should persist, {@code false} otherwise - * @since 3.1.0 + * @since 3.2.0 */ @Override public boolean shouldPersist() { @@ -137,7 +138,7 @@ public boolean shouldPersist() { * A listener is considered inherently persistent if the {@linkplain #persistent} flag is set to {@code true}. * * @return {@code true} if the listener is inherently persistent, {@code false} otherwise - * @since 3.1.0 + * @since 3.2.0 */ @Override public boolean isPersistent() { diff --git a/src/main/java/me/tori/wraith/listener/Listener.java b/src/main/java/me/tori/wraith/listener/Listener.java index 5a0bc2c..a808597 100644 --- a/src/main/java/me/tori/wraith/listener/Listener.java +++ b/src/main/java/me/tori/wraith/listener/Listener.java @@ -27,7 +27,7 @@ public interface Listener extends Invokable { /** * Gets the type of events that this listener can handle. * - * @return The type of events that this listener can handle, or null if no type is specified. + * @return The type of events that this listener can handle, or {@code null} if no type is specified. */ Class getType(); @@ -43,7 +43,7 @@ public interface Listener extends Invokable { * * @return {@code true} if the listener should persist, {@code false} otherwise * @see EventBus#forEachListener(List, Predicate, Consumer, boolean) - * @since 3.1.0 + * @since 3.2.0 */ @SuppressWarnings("JavadocReference") default boolean shouldPersist() { @@ -54,7 +54,7 @@ default boolean shouldPersist() { * Indicates whether this listener is inherently persistent. * * @return {@code true} if the listener is inherently persistent, {@code false} otherwise - * @since 3.1.0 + * @since 3.2.0 */ default boolean isPersistent() { return true; diff --git a/src/main/java/me/tori/wraith/listener/ListenerBuilder.java b/src/main/java/me/tori/wraith/listener/ListenerBuilder.java index 0be1ce9..cc77d0e 100644 --- a/src/main/java/me/tori/wraith/listener/ListenerBuilder.java +++ b/src/main/java/me/tori/wraith/listener/ListenerBuilder.java @@ -28,7 +28,7 @@ * @param the type of event this listener handles * @author 7orivorian * @see EventListener - * @since 3.1.0 + * @since 3.2.0 */ public class ListenerBuilder { diff --git a/src/main/test/me/tori/wraith/benchmarking/MyBenchmark.java b/src/main/test/me/tori/wraith/benchmarking/MyBenchmark.java index ef96b41..63f45bc 100644 --- a/src/main/test/me/tori/wraith/benchmarking/MyBenchmark.java +++ b/src/main/test/me/tori/wraith/benchmarking/MyBenchmark.java @@ -10,7 +10,7 @@ /** * @author 7orivorian - * @since 3.0.0 + * @since 3.2.0 */ public class MyBenchmark { diff --git a/src/main/test/me/tori/wraith/persistency/PersistencyTest.java b/src/main/test/me/tori/wraith/persistency/PersistencyTest.java index e5ae29b..8016a43 100644 --- a/src/main/test/me/tori/wraith/persistency/PersistencyTest.java +++ b/src/main/test/me/tori/wraith/persistency/PersistencyTest.java @@ -9,7 +9,7 @@ /** * @author 7orivorian - * @since 3.1.0 + * @since 3.2.0 */ public class PersistencyTest { From ad795c2a3046434d473f097fe58f2a7dcf969f58 Mon Sep 17 00:00:00 2001 From: 7orivorian <7orivorian+github@gmail.com> Date: Sun, 23 Jun 2024 19:43:13 -0400 Subject: [PATCH 08/26] Update MyBenchmark.java main exception Signed-off-by: 7orivorian <7orivorian+github@gmail.com> --- src/main/test/me/tori/wraith/benchmarking/MyBenchmark.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/test/me/tori/wraith/benchmarking/MyBenchmark.java b/src/main/test/me/tori/wraith/benchmarking/MyBenchmark.java index 63f45bc..ca0621a 100644 --- a/src/main/test/me/tori/wraith/benchmarking/MyBenchmark.java +++ b/src/main/test/me/tori/wraith/benchmarking/MyBenchmark.java @@ -6,6 +6,7 @@ import org.openjdk.jmh.Main; import org.openjdk.jmh.annotations.*; +import java.io.IOException; import java.util.concurrent.TimeUnit; /** @@ -14,7 +15,7 @@ */ public class MyBenchmark { - public static void main(String[] args) throws Exception { + public static void main(String[] args) throws IOException { Main.main(args); } From d38d5c83eddd836f190d708ae3f210494f774d21 Mon Sep 17 00:00:00 2001 From: 7orivorian <7orivorian+github@gmail.com> Date: Sun, 23 Jun 2024 19:44:40 -0400 Subject: [PATCH 09/26] Add persistence compatability to LambdaEventListener.java Signed-off-by: 7orivorian <7orivorian+github@gmail.com> --- .../wraith/listener/LambdaEventListener.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/main/java/me/tori/wraith/listener/LambdaEventListener.java b/src/main/java/me/tori/wraith/listener/LambdaEventListener.java index 8d2adb0..3127640 100644 --- a/src/main/java/me/tori/wraith/listener/LambdaEventListener.java +++ b/src/main/java/me/tori/wraith/listener/LambdaEventListener.java @@ -73,6 +73,22 @@ public LambdaEventListener(@NotNull Class target, int priority, @Null this.invokable = invokable; } + /** + * Constructs a new {@code LambdaEventListener} with the given target class, priority, type, and invokable action. + * + * @param target The target class of the event. + * @param type The type of the event. + * @param priority The priority of this listener. + * @param persists How many events this listener should handle before being killed. + * @param invokable The invokable action to be executed when the event is dispatched. + * @throws NullPointerException if {@code target} is {@code null}. + */ + public LambdaEventListener(@NotNull Class target, @Nullable Class type, int priority, int persists, @NotNull Invokable invokable) { + super(target, type, priority, persists); + Objects.requireNonNull(invokable); + this.invokable = invokable; + } + /** * Invokes the wrapped invokable action with the provided event. * From 42a6cefb40c9ed3e4893b9a6b565d80819c386a1 Mon Sep 17 00:00:00 2001 From: 7orivorian <7orivorian+github@gmail.com> Date: Sun, 23 Jun 2024 19:45:00 -0400 Subject: [PATCH 10/26] Add PersistenceExample.java Signed-off-by: 7orivorian <7orivorian+github@gmail.com> --- .../persistence/PersistenceExample.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 examples/java/me/tori/example/persistence/PersistenceExample.java diff --git a/examples/java/me/tori/example/persistence/PersistenceExample.java b/examples/java/me/tori/example/persistence/PersistenceExample.java new file mode 100644 index 0000000..b565816 --- /dev/null +++ b/examples/java/me/tori/example/persistence/PersistenceExample.java @@ -0,0 +1,32 @@ +package me.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; + +/** + * @author 7orivorian + * @since 3.2.0 + */ +class PersistenceExample { + + private static final IEventBus EVENT_BUS = new EventBus(); + 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)); + }}; + + public static void main(String[] args) { + // Subscribe our subscriber. This will never be removed from the event bus. + EVENT_BUS.subscribe(SUBSCRIBER); + + // After this event is dispatched, and it's listener invoked, + // the listener will be removed since it's set to only persist once. + EVENT_BUS.dispatch("Hello world!"); + + // You can still dispatch events to remaining listeners. + EVENT_BUS.dispatch("I wont be printed :("); + } +} \ No newline at end of file From c0c3c7192e52da885d7d7bd283fc60da86a952af Mon Sep 17 00:00:00 2001 From: 7orivorian <7orivorian+github@gmail.com> Date: Sun, 23 Jun 2024 20:52:10 -0400 Subject: [PATCH 11/26] Javadoc and method name refactoring Signed-off-by: 7orivorian <7orivorian+github@gmail.com> --- .../tori/wraith/listener/EventListener.java | 46 +++++++++++-------- .../wraith/listener/LambdaEventListener.java | 16 ++++--- .../me/tori/wraith/listener/Listener.java | 4 +- 3 files changed, 39 insertions(+), 27 deletions(-) diff --git a/src/main/java/me/tori/wraith/listener/EventListener.java b/src/main/java/me/tori/wraith/listener/EventListener.java index 5d63513..2c99116 100644 --- a/src/main/java/me/tori/wraith/listener/EventListener.java +++ b/src/main/java/me/tori/wraith/listener/EventListener.java @@ -18,11 +18,11 @@ */ public abstract class EventListener implements Listener { - protected int persists; - protected final boolean persistent; - protected final int priority; - protected final @Nullable Class type; protected final @NotNull Class target; + protected final @Nullable Class type; + protected final int priority; + protected final boolean indefinitePersistence; + protected int persists; /** * Constructs an event listener with default priority and no specified type. @@ -49,7 +49,7 @@ public EventListener(@NotNull Class target, int priority) { * Constructs an event listener with default priority and a specified type. * * @param target The target class that this listener is designed to handle events for. - * @param type The type of events that this listener can handle. + * @param type The type of events that this listener can handle. Can be {@code null}. * @throws NullPointerException if {@code target} is {@code null}. */ public EventListener(@NotNull Class target, @Nullable Class type) { @@ -61,20 +61,21 @@ public EventListener(@NotNull Class target, @Nullable Class type) * * @param target The target class that this listener is designed to handle events for. * @param priority The priority level of this listener for event handling. - * @param type The type of events that this listener can handle. + * @param type The type of events that this listener can handle. Can be {@code null}. * @throws NullPointerException if {@code target} is {@code null}. */ public EventListener(@NotNull Class target, int priority, @Nullable Class type) { - this(target, type, priority, -1); + this(target, type, priority, 0); } /** * Constructs an event listener with a specified priority and type. * * @param target The target class that this listener is designed to handle events for. - * @param type The type of events that this listener can handle. + * @param type The type of events that this listener can handle. Can be {@code null}. * @param priority The priority level of this listener for event handling. * @param persists How many events this listener should handle before being killed. + * A value {@code <= 0} will flag this listener to {@linkplain #indefinitePersistence persist indefinitely}. * @throws NullPointerException if {@code target} is {@code null}. * @since 3.2.0 */ @@ -84,7 +85,7 @@ public EventListener(@NotNull Class target, @Nullable Class type, this.target = target; this.type = type; this.persists = persists; - this.persistent = persists <= 0; + this.indefinitePersistence = persists <= 0; } /** @@ -121,7 +122,7 @@ public Class getTarget() { /** * Determines whether this listener should persist after being invoked. - * The listener persists if it is inherently persistent (as determined by {@link #isPersistent()}) + * The listener persists if it is inherently persistent (as determined by {@link #hasIndefinitePersistence()}) * or if the {@linkplain EventListener#persists internal persistence counter} is greater than zero * after being decremented. * @@ -130,19 +131,19 @@ public Class getTarget() { */ @Override public boolean shouldPersist() { - return isPersistent() || ((--persists) > 0); + return hasIndefinitePersistence() || ((--persists) > 0); } /** * Indicates whether this listener is inherently persistent. - * A listener is considered inherently persistent if the {@linkplain #persistent} flag is set to {@code true}. + * A listener is considered inherently persistent if the {@linkplain #indefinitePersistence} flag is set to {@code true}. * * @return {@code true} if the listener is inherently persistent, {@code false} otherwise * @since 3.2.0 */ @Override - public boolean isPersistent() { - return persistent; + public boolean hasIndefinitePersistence() { + return indefinitePersistence; } @Override @@ -158,6 +159,9 @@ public boolean equals(Object o) { if (priority != that.priority) { return false; } + if (indefinitePersistence != that.indefinitePersistence) { + return false; + } if (!Objects.equals(type, that.type)) { return false; } @@ -166,18 +170,22 @@ public boolean equals(Object o) { @Override public int hashCode() { - int result = priority; - result = (31 * result) + ((type != null) ? type.hashCode() : 0); - result = (31 * result) + target.hashCode(); + int result = target.hashCode(); + result = 31 * result + Objects.hashCode(type); + result = 31 * result + priority; + result = 31 * result + Boolean.hashCode(indefinitePersistence); + result = 31 * result + persists; return result; } @Override public String toString() { return "EventListener{" + - "priority=" + priority + + "target=" + target + ", type=" + type + - ", target=" + target + + ", priority=" + priority + + ", indefinitePersistence=" + indefinitePersistence + + ", persists=" + persists + '}'; } } \ No newline at end of file diff --git a/src/main/java/me/tori/wraith/listener/LambdaEventListener.java b/src/main/java/me/tori/wraith/listener/LambdaEventListener.java index 3127640..45a672d 100644 --- a/src/main/java/me/tori/wraith/listener/LambdaEventListener.java +++ b/src/main/java/me/tori/wraith/listener/LambdaEventListener.java @@ -79,7 +79,8 @@ public LambdaEventListener(@NotNull Class target, int priority, @Null * @param target The target class of the event. * @param type The type of the event. * @param priority The priority of this listener. - * @param persists How many events this listener should handle before being killed. + * @param persists How many events this listener should handle before being killed. + * A value {@code <= 0} will flag this listener to {@linkplain #indefinitePersistence persist indefinitely}. * @param invokable The invokable action to be executed when the event is dispatched. * @throws NullPointerException if {@code target} is {@code null}. */ @@ -104,12 +105,13 @@ public boolean equals(Object o) { if (this == o) { return true; } - if (o == null || getClass() != o.getClass()) { + if ((o == null) || (getClass() != o.getClass())) { return false; } if (!super.equals(o)) { return false; } + LambdaEventListener that = (LambdaEventListener) o; return invokable.equals(that.invokable); } @@ -117,17 +119,19 @@ public boolean equals(Object o) { @Override public int hashCode() { int result = super.hashCode(); - result = 31 * result + invokable.hashCode(); + result = (31 * result) + invokable.hashCode(); return result; } @Override public String toString() { return "LambdaEventListener{" + - "invokable=" + invokable + - ", priority=" + priority + + "target=" + target + ", type=" + type + - ", target=" + target + + ", priority=" + priority + + ", indefinitePersistence=" + indefinitePersistence + + ", persists=" + persists + + ", invokable=" + invokable + '}'; } } \ No newline at end of file diff --git a/src/main/java/me/tori/wraith/listener/Listener.java b/src/main/java/me/tori/wraith/listener/Listener.java index a808597..885c5a1 100644 --- a/src/main/java/me/tori/wraith/listener/Listener.java +++ b/src/main/java/me/tori/wraith/listener/Listener.java @@ -47,7 +47,7 @@ public interface Listener extends Invokable { */ @SuppressWarnings("JavadocReference") default boolean shouldPersist() { - return isPersistent(); + return hasIndefinitePersistence(); } /** @@ -56,7 +56,7 @@ default boolean shouldPersist() { * @return {@code true} if the listener is inherently persistent, {@code false} otherwise * @since 3.2.0 */ - default boolean isPersistent() { + default boolean hasIndefinitePersistence() { return true; } } \ No newline at end of file From 4f971b45a8f7313ce968cafb52b524012810fd3e Mon Sep 17 00:00:00 2001 From: 7orivorian <7orivorian+github@gmail.com> Date: Sun, 23 Jun 2024 21:35:03 -0400 Subject: [PATCH 12/26] Add copyright text to all java files Signed-off-by: 7orivorian <7orivorian+github@gmail.com> --- .../tori/example/expanded/ExampleEvent.java | 21 +++++++++++++++++++ .../example/expanded/ExampleListener.java | 21 +++++++++++++++++++ .../me/tori/example/expanded/ExampleMain.java | 21 +++++++++++++++++++ .../example/expanded/ExampleSubscriber.java | 21 +++++++++++++++++++ .../persistence/PersistenceExample.java | 21 +++++++++++++++++++ .../me/tori/example/simple/SimpleExample.java | 21 +++++++++++++++++++ .../java/me/tori/wraith/bus/EventBus.java | 21 +++++++++++++++++++ .../java/me/tori/wraith/bus/IEventBus.java | 21 +++++++++++++++++++ .../tori/wraith/bus/InvertableEventBus.java | 21 +++++++++++++++++++ .../tori/wraith/bus/TargetableEventBus.java | 21 +++++++++++++++++++ .../event/cancelable/CancelableEvent.java | 21 +++++++++++++++++++ .../event/cancelable/ICancelableEvent.java | 21 +++++++++++++++++++ .../tori/wraith/event/staged/EventStage.java | 21 +++++++++++++++++++ .../wraith/event/staged/IStagedEvent.java | 21 +++++++++++++++++++ .../tori/wraith/event/staged/StagedEvent.java | 21 +++++++++++++++++++ .../event/targeted/ClassTargetingEvent.java | 21 +++++++++++++++++++ .../event/targeted/IClassTargetingEvent.java | 21 +++++++++++++++++++ .../tori/wraith/listener/EventListener.java | 21 +++++++++++++++++++ .../me/tori/wraith/listener/Invokable.java | 21 +++++++++++++++++++ .../wraith/listener/LambdaEventListener.java | 21 +++++++++++++++++++ .../me/tori/wraith/listener/Listener.java | 21 +++++++++++++++++++ .../tori/wraith/listener/ListenerBuilder.java | 21 +++++++++++++++++++ .../tori/wraith/subscriber/ISubscriber.java | 21 +++++++++++++++++++ .../me/tori/wraith/subscriber/Subscriber.java | 21 +++++++++++++++++++ .../me/tori/wraith/task/ScheduledTask.java | 21 +++++++++++++++++++ .../me/tori/wraith/task/TaskExecutor.java | 21 +++++++++++++++++++ .../tori/wraith/benchmarking/MyBenchmark.java | 21 +++++++++++++++++++ .../wraith/persistency/PersistencyTest.java | 21 +++++++++++++++++++ .../wraith/targetedevent/InvalidListener.java | 21 +++++++++++++++++++ .../targetedevent/TargetedEventTest.java | 21 +++++++++++++++++++ .../tori/wraith/targetedevent/TestEvent.java | 21 +++++++++++++++++++ .../wraith/targetedevent/TestSubsciber.java | 21 +++++++++++++++++++ .../wraith/targetedevent/ValidListener.java | 21 +++++++++++++++++++ .../wraith/taskexecutor/TaskExecutorTest.java | 21 +++++++++++++++++++ 34 files changed, 714 insertions(+) diff --git a/examples/java/me/tori/example/expanded/ExampleEvent.java b/examples/java/me/tori/example/expanded/ExampleEvent.java index 56f9448..686219f 100644 --- a/examples/java/me/tori/example/expanded/ExampleEvent.java +++ b/examples/java/me/tori/example/expanded/ExampleEvent.java @@ -1,3 +1,24 @@ +/* + * Copyright (c) 2021-2024 7orivorian. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package me.tori.example.expanded; import me.tori.wraith.event.cancelable.CancelableEvent; diff --git a/examples/java/me/tori/example/expanded/ExampleListener.java b/examples/java/me/tori/example/expanded/ExampleListener.java index a6b952d..c3de8fc 100644 --- a/examples/java/me/tori/example/expanded/ExampleListener.java +++ b/examples/java/me/tori/example/expanded/ExampleListener.java @@ -1,3 +1,24 @@ +/* + * Copyright (c) 2021-2024 7orivorian. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package me.tori.example.expanded; import me.tori.wraith.event.staged.EventStage; diff --git a/examples/java/me/tori/example/expanded/ExampleMain.java b/examples/java/me/tori/example/expanded/ExampleMain.java index 6156f7e..310be01 100644 --- a/examples/java/me/tori/example/expanded/ExampleMain.java +++ b/examples/java/me/tori/example/expanded/ExampleMain.java @@ -1,3 +1,24 @@ +/* + * Copyright (c) 2021-2024 7orivorian. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package me.tori.example.expanded; import me.tori.wraith.bus.EventBus; diff --git a/examples/java/me/tori/example/expanded/ExampleSubscriber.java b/examples/java/me/tori/example/expanded/ExampleSubscriber.java index 82ddb4d..a8dae62 100644 --- a/examples/java/me/tori/example/expanded/ExampleSubscriber.java +++ b/examples/java/me/tori/example/expanded/ExampleSubscriber.java @@ -1,3 +1,24 @@ +/* + * Copyright (c) 2021-2024 7orivorian. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package me.tori.example.expanded; import me.tori.wraith.event.staged.EventStage; diff --git a/examples/java/me/tori/example/persistence/PersistenceExample.java b/examples/java/me/tori/example/persistence/PersistenceExample.java index b565816..765dcd4 100644 --- a/examples/java/me/tori/example/persistence/PersistenceExample.java +++ b/examples/java/me/tori/example/persistence/PersistenceExample.java @@ -1,3 +1,24 @@ +/* + * Copyright (c) 2021-2024 7orivorian. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package me.tori.example.persistence; import me.tori.wraith.bus.EventBus; diff --git a/examples/java/me/tori/example/simple/SimpleExample.java b/examples/java/me/tori/example/simple/SimpleExample.java index 6796491..0c8214f 100644 --- a/examples/java/me/tori/example/simple/SimpleExample.java +++ b/examples/java/me/tori/example/simple/SimpleExample.java @@ -1,3 +1,24 @@ +/* + * Copyright (c) 2021-2024 7orivorian. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package me.tori.example.simple; import me.tori.wraith.bus.EventBus; diff --git a/src/main/java/me/tori/wraith/bus/EventBus.java b/src/main/java/me/tori/wraith/bus/EventBus.java index 75c5bc1..d061846 100644 --- a/src/main/java/me/tori/wraith/bus/EventBus.java +++ b/src/main/java/me/tori/wraith/bus/EventBus.java @@ -1,3 +1,24 @@ +/* + * Copyright (c) 2021-2024 7orivorian. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package me.tori.wraith.bus; import me.tori.wraith.event.cancelable.ICancelableEvent; diff --git a/src/main/java/me/tori/wraith/bus/IEventBus.java b/src/main/java/me/tori/wraith/bus/IEventBus.java index 3a4d404..21f0be9 100644 --- a/src/main/java/me/tori/wraith/bus/IEventBus.java +++ b/src/main/java/me/tori/wraith/bus/IEventBus.java @@ -1,3 +1,24 @@ +/* + * Copyright (c) 2021-2024 7orivorian. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package me.tori.wraith.bus; import me.tori.wraith.event.cancelable.ICancelableEvent; diff --git a/src/main/java/me/tori/wraith/bus/InvertableEventBus.java b/src/main/java/me/tori/wraith/bus/InvertableEventBus.java index 3120c6d..ba5270d 100644 --- a/src/main/java/me/tori/wraith/bus/InvertableEventBus.java +++ b/src/main/java/me/tori/wraith/bus/InvertableEventBus.java @@ -1,3 +1,24 @@ +/* + * Copyright (c) 2021-2024 7orivorian. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package me.tori.wraith.bus; import me.tori.wraith.event.cancelable.ICancelableEvent; diff --git a/src/main/java/me/tori/wraith/bus/TargetableEventBus.java b/src/main/java/me/tori/wraith/bus/TargetableEventBus.java index 5b6776c..abbbce9 100644 --- a/src/main/java/me/tori/wraith/bus/TargetableEventBus.java +++ b/src/main/java/me/tori/wraith/bus/TargetableEventBus.java @@ -1,3 +1,24 @@ +/* + * Copyright (c) 2021-2024 7orivorian. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package me.tori.wraith.bus; import me.tori.wraith.event.cancelable.ICancelableEvent; diff --git a/src/main/java/me/tori/wraith/event/cancelable/CancelableEvent.java b/src/main/java/me/tori/wraith/event/cancelable/CancelableEvent.java index 1a1798f..1558a53 100644 --- a/src/main/java/me/tori/wraith/event/cancelable/CancelableEvent.java +++ b/src/main/java/me/tori/wraith/event/cancelable/CancelableEvent.java @@ -1,3 +1,24 @@ +/* + * Copyright (c) 2021-2024 7orivorian. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package me.tori.wraith.event.cancelable; /** diff --git a/src/main/java/me/tori/wraith/event/cancelable/ICancelableEvent.java b/src/main/java/me/tori/wraith/event/cancelable/ICancelableEvent.java index ddbb4b5..36feebf 100644 --- a/src/main/java/me/tori/wraith/event/cancelable/ICancelableEvent.java +++ b/src/main/java/me/tori/wraith/event/cancelable/ICancelableEvent.java @@ -1,3 +1,24 @@ +/* + * Copyright (c) 2021-2024 7orivorian. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package me.tori.wraith.event.cancelable; /** diff --git a/src/main/java/me/tori/wraith/event/staged/EventStage.java b/src/main/java/me/tori/wraith/event/staged/EventStage.java index b8dd23b..10cbdda 100644 --- a/src/main/java/me/tori/wraith/event/staged/EventStage.java +++ b/src/main/java/me/tori/wraith/event/staged/EventStage.java @@ -1,3 +1,24 @@ +/* + * Copyright (c) 2021-2024 7orivorian. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package me.tori.wraith.event.staged; /** diff --git a/src/main/java/me/tori/wraith/event/staged/IStagedEvent.java b/src/main/java/me/tori/wraith/event/staged/IStagedEvent.java index 9d9a3d4..870843e 100644 --- a/src/main/java/me/tori/wraith/event/staged/IStagedEvent.java +++ b/src/main/java/me/tori/wraith/event/staged/IStagedEvent.java @@ -1,3 +1,24 @@ +/* + * Copyright (c) 2021-2024 7orivorian. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package me.tori.wraith.event.staged; /** diff --git a/src/main/java/me/tori/wraith/event/staged/StagedEvent.java b/src/main/java/me/tori/wraith/event/staged/StagedEvent.java index 958f543..6183216 100644 --- a/src/main/java/me/tori/wraith/event/staged/StagedEvent.java +++ b/src/main/java/me/tori/wraith/event/staged/StagedEvent.java @@ -1,3 +1,24 @@ +/* + * Copyright (c) 2021-2024 7orivorian. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package me.tori.wraith.event.staged; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/me/tori/wraith/event/targeted/ClassTargetingEvent.java b/src/main/java/me/tori/wraith/event/targeted/ClassTargetingEvent.java index 33d2505..bff8530 100644 --- a/src/main/java/me/tori/wraith/event/targeted/ClassTargetingEvent.java +++ b/src/main/java/me/tori/wraith/event/targeted/ClassTargetingEvent.java @@ -1,3 +1,24 @@ +/* + * Copyright (c) 2021-2024 7orivorian. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package me.tori.wraith.event.targeted; import me.tori.wraith.listener.Listener; diff --git a/src/main/java/me/tori/wraith/event/targeted/IClassTargetingEvent.java b/src/main/java/me/tori/wraith/event/targeted/IClassTargetingEvent.java index b69bf5d..5700c91 100644 --- a/src/main/java/me/tori/wraith/event/targeted/IClassTargetingEvent.java +++ b/src/main/java/me/tori/wraith/event/targeted/IClassTargetingEvent.java @@ -1,3 +1,24 @@ +/* + * Copyright (c) 2021-2024 7orivorian. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package me.tori.wraith.event.targeted; import me.tori.wraith.listener.Listener; diff --git a/src/main/java/me/tori/wraith/listener/EventListener.java b/src/main/java/me/tori/wraith/listener/EventListener.java index 2c99116..3b428a4 100644 --- a/src/main/java/me/tori/wraith/listener/EventListener.java +++ b/src/main/java/me/tori/wraith/listener/EventListener.java @@ -1,3 +1,24 @@ +/* + * Copyright (c) 2021-2024 7orivorian. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package me.tori.wraith.listener; import me.tori.wraith.bus.IEventBus; diff --git a/src/main/java/me/tori/wraith/listener/Invokable.java b/src/main/java/me/tori/wraith/listener/Invokable.java index 1d2cb3d..d8594ff 100644 --- a/src/main/java/me/tori/wraith/listener/Invokable.java +++ b/src/main/java/me/tori/wraith/listener/Invokable.java @@ -1,3 +1,24 @@ +/* + * Copyright (c) 2021-2024 7orivorian. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package me.tori.wraith.listener; /** diff --git a/src/main/java/me/tori/wraith/listener/LambdaEventListener.java b/src/main/java/me/tori/wraith/listener/LambdaEventListener.java index 45a672d..a6b89ee 100644 --- a/src/main/java/me/tori/wraith/listener/LambdaEventListener.java +++ b/src/main/java/me/tori/wraith/listener/LambdaEventListener.java @@ -1,3 +1,24 @@ +/* + * Copyright (c) 2021-2024 7orivorian. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package me.tori.wraith.listener; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/me/tori/wraith/listener/Listener.java b/src/main/java/me/tori/wraith/listener/Listener.java index 885c5a1..cfdb508 100644 --- a/src/main/java/me/tori/wraith/listener/Listener.java +++ b/src/main/java/me/tori/wraith/listener/Listener.java @@ -1,3 +1,24 @@ +/* + * Copyright (c) 2021-2024 7orivorian. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package me.tori.wraith.listener; import me.tori.wraith.bus.EventBus; diff --git a/src/main/java/me/tori/wraith/listener/ListenerBuilder.java b/src/main/java/me/tori/wraith/listener/ListenerBuilder.java index cc77d0e..bf576c0 100644 --- a/src/main/java/me/tori/wraith/listener/ListenerBuilder.java +++ b/src/main/java/me/tori/wraith/listener/ListenerBuilder.java @@ -1,3 +1,24 @@ +/* + * Copyright (c) 2021-2024 7orivorian. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package me.tori.wraith.listener; import me.tori.wraith.bus.IEventBus; diff --git a/src/main/java/me/tori/wraith/subscriber/ISubscriber.java b/src/main/java/me/tori/wraith/subscriber/ISubscriber.java index 08b5b4a..1936bd6 100644 --- a/src/main/java/me/tori/wraith/subscriber/ISubscriber.java +++ b/src/main/java/me/tori/wraith/subscriber/ISubscriber.java @@ -1,3 +1,24 @@ +/* + * Copyright (c) 2021-2024 7orivorian. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package me.tori.wraith.subscriber; import me.tori.wraith.listener.Listener; diff --git a/src/main/java/me/tori/wraith/subscriber/Subscriber.java b/src/main/java/me/tori/wraith/subscriber/Subscriber.java index 1c26936..a0faa12 100644 --- a/src/main/java/me/tori/wraith/subscriber/Subscriber.java +++ b/src/main/java/me/tori/wraith/subscriber/Subscriber.java @@ -1,3 +1,24 @@ +/* + * Copyright (c) 2021-2024 7orivorian. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package me.tori.wraith.subscriber; import me.tori.wraith.listener.Listener; diff --git a/src/main/java/me/tori/wraith/task/ScheduledTask.java b/src/main/java/me/tori/wraith/task/ScheduledTask.java index 1198fee..d257077 100644 --- a/src/main/java/me/tori/wraith/task/ScheduledTask.java +++ b/src/main/java/me/tori/wraith/task/ScheduledTask.java @@ -1,3 +1,24 @@ +/* + * Copyright (c) 2021-2024 7orivorian. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package me.tori.wraith.task; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/me/tori/wraith/task/TaskExecutor.java b/src/main/java/me/tori/wraith/task/TaskExecutor.java index 864af78..e2beb99 100644 --- a/src/main/java/me/tori/wraith/task/TaskExecutor.java +++ b/src/main/java/me/tori/wraith/task/TaskExecutor.java @@ -1,3 +1,24 @@ +/* + * Copyright (c) 2021-2024 7orivorian. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package me.tori.wraith.task; import java.util.ArrayList; diff --git a/src/main/test/me/tori/wraith/benchmarking/MyBenchmark.java b/src/main/test/me/tori/wraith/benchmarking/MyBenchmark.java index ca0621a..b7d3660 100644 --- a/src/main/test/me/tori/wraith/benchmarking/MyBenchmark.java +++ b/src/main/test/me/tori/wraith/benchmarking/MyBenchmark.java @@ -1,3 +1,24 @@ +/* + * Copyright (c) 2021-2024 7orivorian. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package me.tori.wraith.benchmarking; import me.tori.wraith.bus.EventBus; diff --git a/src/main/test/me/tori/wraith/persistency/PersistencyTest.java b/src/main/test/me/tori/wraith/persistency/PersistencyTest.java index 8016a43..1fd050e 100644 --- a/src/main/test/me/tori/wraith/persistency/PersistencyTest.java +++ b/src/main/test/me/tori/wraith/persistency/PersistencyTest.java @@ -1,3 +1,24 @@ +/* + * Copyright (c) 2021-2024 7orivorian. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package me.tori.wraith.persistency; import me.tori.wraith.bus.EventBus; diff --git a/src/main/test/me/tori/wraith/targetedevent/InvalidListener.java b/src/main/test/me/tori/wraith/targetedevent/InvalidListener.java index 04cb61d..5de9566 100644 --- a/src/main/test/me/tori/wraith/targetedevent/InvalidListener.java +++ b/src/main/test/me/tori/wraith/targetedevent/InvalidListener.java @@ -1,3 +1,24 @@ +/* + * Copyright (c) 2021-2024 7orivorian. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package me.tori.wraith.targetedevent; import me.tori.wraith.listener.EventListener; diff --git a/src/main/test/me/tori/wraith/targetedevent/TargetedEventTest.java b/src/main/test/me/tori/wraith/targetedevent/TargetedEventTest.java index 0ed9b61..4813fd2 100644 --- a/src/main/test/me/tori/wraith/targetedevent/TargetedEventTest.java +++ b/src/main/test/me/tori/wraith/targetedevent/TargetedEventTest.java @@ -1,3 +1,24 @@ +/* + * Copyright (c) 2021-2024 7orivorian. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package me.tori.wraith.targetedevent; import me.tori.wraith.bus.EventBus; diff --git a/src/main/test/me/tori/wraith/targetedevent/TestEvent.java b/src/main/test/me/tori/wraith/targetedevent/TestEvent.java index 3a074e7..6cbad3b 100644 --- a/src/main/test/me/tori/wraith/targetedevent/TestEvent.java +++ b/src/main/test/me/tori/wraith/targetedevent/TestEvent.java @@ -1,3 +1,24 @@ +/* + * Copyright (c) 2021-2024 7orivorian. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package me.tori.wraith.targetedevent; import me.tori.wraith.event.cancelable.CancelableEvent; diff --git a/src/main/test/me/tori/wraith/targetedevent/TestSubsciber.java b/src/main/test/me/tori/wraith/targetedevent/TestSubsciber.java index 59041a9..5b2db18 100644 --- a/src/main/test/me/tori/wraith/targetedevent/TestSubsciber.java +++ b/src/main/test/me/tori/wraith/targetedevent/TestSubsciber.java @@ -1,3 +1,24 @@ +/* + * Copyright (c) 2021-2024 7orivorian. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package me.tori.wraith.targetedevent; import me.tori.wraith.subscriber.Subscriber; diff --git a/src/main/test/me/tori/wraith/targetedevent/ValidListener.java b/src/main/test/me/tori/wraith/targetedevent/ValidListener.java index dd9d401..e23be63 100644 --- a/src/main/test/me/tori/wraith/targetedevent/ValidListener.java +++ b/src/main/test/me/tori/wraith/targetedevent/ValidListener.java @@ -1,3 +1,24 @@ +/* + * Copyright (c) 2021-2024 7orivorian. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package me.tori.wraith.targetedevent; import me.tori.wraith.listener.EventListener; diff --git a/src/main/test/me/tori/wraith/taskexecutor/TaskExecutorTest.java b/src/main/test/me/tori/wraith/taskexecutor/TaskExecutorTest.java index d80cb1f..a735a2d 100644 --- a/src/main/test/me/tori/wraith/taskexecutor/TaskExecutorTest.java +++ b/src/main/test/me/tori/wraith/taskexecutor/TaskExecutorTest.java @@ -1,3 +1,24 @@ +/* + * Copyright (c) 2021-2024 7orivorian. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package me.tori.wraith.taskexecutor; import me.tori.wraith.task.ScheduledTask; From 4d033cd6c139e840c70ad0c1313961e91419255f Mon Sep 17 00:00:00 2001 From: 7orivorian <7orivorian+github@gmail.com> Date: Mon, 24 Jun 2024 00:48:44 -0400 Subject: [PATCH 13/26] Update Javadoc for PersistenceExample.java & SimpleExample.java Signed-off-by: 7orivorian <7orivorian+github@gmail.com> --- .../java/me/tori/example/persistence/PersistenceExample.java | 4 ++++ examples/java/me/tori/example/simple/SimpleExample.java | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/examples/java/me/tori/example/persistence/PersistenceExample.java b/examples/java/me/tori/example/persistence/PersistenceExample.java index 765dcd4..b6cbc6f 100644 --- a/examples/java/me/tori/example/persistence/PersistenceExample.java +++ b/examples/java/me/tori/example/persistence/PersistenceExample.java @@ -27,6 +27,10 @@ import me.tori.wraith.subscriber.Subscriber; /** + * A simple example of listener persistence. + *

+ * Last updated for version 3.1.0 + * * @author 7orivorian * @since 3.2.0 */ diff --git a/examples/java/me/tori/example/simple/SimpleExample.java b/examples/java/me/tori/example/simple/SimpleExample.java index 0c8214f..b346f28 100644 --- a/examples/java/me/tori/example/simple/SimpleExample.java +++ b/examples/java/me/tori/example/simple/SimpleExample.java @@ -28,7 +28,8 @@ /** * One-class example - *

Last updated for version 3.1.0 + *

+ * Last updated for version 3.1.0 * * @author 7orivorian */ From 981b1541b25e23fd7ae6e1870956b9d6cf4a155b Mon Sep 17 00:00:00 2001 From: 7orivorian <7orivorian+github@gmail.com> Date: Mon, 24 Jun 2024 00:49:22 -0400 Subject: [PATCH 14/26] Add TaskExecutorExample.java Signed-off-by: 7orivorian <7orivorian+github@gmail.com> --- .../taskexecutor/TaskExecutorExample.java | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 examples/java/me/tori/example/taskexecutor/TaskExecutorExample.java diff --git a/examples/java/me/tori/example/taskexecutor/TaskExecutorExample.java b/examples/java/me/tori/example/taskexecutor/TaskExecutorExample.java new file mode 100644 index 0000000..2c4e9d3 --- /dev/null +++ b/examples/java/me/tori/example/taskexecutor/TaskExecutorExample.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2024 7orivorian. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package me.tori.example.taskexecutor; + +import me.tori.wraith.bus.EventBus; +import me.tori.wraith.task.ScheduledTask; +import me.tori.wraith.task.TaskExecutor; + +/** + * A simple example showing how to use the {@link TaskExecutor} + * + * @author 7orivorian + * @since 3.2.0 + */ +public class TaskExecutorExample { + + private static final EventBus EVENT_BUS = new EventBus(); + + public static void main(final String[] args) { + // Schedule a task to run when the next String event is dispatched + EVENT_BUS.scheduleTask(new ScheduledTask(String.class, 3) { + @Override + public void run() { + System.out.println("Hello World!"); + } + }); + + // This event will trigger the previously scheduled task. + // Note that scheduled tasks will be run before any listeners + // are invoked, regardless of listener priority. + EVENT_BUS.dispatch("just a string event"); + } +} \ No newline at end of file From 9ba137b70ff5f24c2e662e2378729f8d9f92496d Mon Sep 17 00:00:00 2001 From: 7orivorian <7orivorian+github@gmail.com> Date: Mon, 24 Jun 2024 01:13:53 -0400 Subject: [PATCH 15/26] Fix README.md formatting Signed-off-by: 7orivorian <7orivorian+github@gmail.com> --- README.md | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 4cc101e..74277fa 100644 --- a/README.md +++ b/README.md @@ -71,6 +71,7 @@ Packaged file can be found in the `target/` directory. While the code itself is thoroughly documented, here's a simple guide to help you get started with the latest features. ### Subscribers +

Details... @@ -115,9 +116,11 @@ public class Example { } } ``` +
### Defining Events +
Details... @@ -158,9 +161,11 @@ public class CancelableEvent implements ICancelable { // ... } ``` +
### Listeners +
Details... @@ -209,13 +214,15 @@ public class ExampleSubscriber extends Subscriber { } } ``` +
### Dispatching Events +
Details... -To dispatch an event to an event bus, simply call one of the `dispatch` methods defined in any `IEventBus` +To dispatch an event to an event bus, call one of the `dispatch` methods defined in any `IEventBus` implementation, passing your event as a parameter: ```java @@ -237,9 +244,10 @@ public class Example { } } ``` +
-Feel free to explore the [example folder](examples/java/me/tori/example) for more Wraith implementations. +Feel free to explore the [example folder](./examples/java/me/tori/example) for more Wraith implementations. # Contributing @@ -261,7 +269,7 @@ To make a contribution, follow these steps: # License -[Wraith is licensed under MIT](src/main/resources/LICENSE.md) +[Wraith is licensed under MIT](./LICENSE) ### MIT License Summary: From 057ecf09902e9a33de8b3aa46e9779dfe733aa73 Mon Sep 17 00:00:00 2001 From: 7orivorian <7orivorian+github@gmail.com> Date: Mon, 24 Jun 2024 01:15:21 -0400 Subject: [PATCH 16/26] Update LICENSE year Signed-off-by: 7orivorian <7orivorian+github@gmail.com> --- LICENSE | 2 +- src/main/resources/{LICENSE.md => LICENSE} | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename src/main/resources/{LICENSE.md => LICENSE} (96%) diff --git a/LICENSE b/LICENSE index f186ace..06c5e4d 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2023 7orivorian +Copyright (c) 2021-2023 7orivorian Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/src/main/resources/LICENSE.md b/src/main/resources/LICENSE similarity index 96% rename from src/main/resources/LICENSE.md rename to src/main/resources/LICENSE index f186ace..06c5e4d 100644 --- a/src/main/resources/LICENSE.md +++ b/src/main/resources/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2023 7orivorian +Copyright (c) 2021-2023 7orivorian Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal From 66cf517fc37b7b297e0b642bc2292dfc26a93896 Mon Sep 17 00:00:00 2001 From: 7orivorian <7orivorian+github@gmail.com> Date: Tue, 25 Jun 2024 00:52:07 -0400 Subject: [PATCH 17/26] Deprecate cancelable events & replace them with StatusEvent Signed-off-by: 7orivorian <7orivorian+github@gmail.com> --- .../java/me/tori/wraith/bus/EventBus.java | 203 +++++++----------- .../java/me/tori/wraith/bus/IEventBus.java | 8 +- .../tori/wraith/bus/InvertableEventBus.java | 8 +- .../tori/wraith/bus/TargetableEventBus.java | 8 +- .../event/cancelable/CancelableEvent.java | 38 +--- .../event/cancelable/ICancelableEvent.java | 37 ++-- .../wraith/event/status/IStatusEvent.java | 128 +++++++++++ .../tori/wraith/event/status/StatusEvent.java | 101 +++++++++ .../wraith/statusevent/StatusEventTest.java | 87 ++++++++ .../wraith/targetedevent/TestSubsciber.java | 37 ---- 10 files changed, 435 insertions(+), 220 deletions(-) create mode 100644 src/main/java/me/tori/wraith/event/status/IStatusEvent.java create mode 100644 src/main/java/me/tori/wraith/event/status/StatusEvent.java create mode 100644 src/main/test/me/tori/wraith/statusevent/StatusEventTest.java delete mode 100644 src/main/test/me/tori/wraith/targetedevent/TestSubsciber.java diff --git a/src/main/java/me/tori/wraith/bus/EventBus.java b/src/main/java/me/tori/wraith/bus/EventBus.java index d061846..3ef51c9 100644 --- a/src/main/java/me/tori/wraith/bus/EventBus.java +++ b/src/main/java/me/tori/wraith/bus/EventBus.java @@ -21,7 +21,7 @@ package me.tori.wraith.bus; -import me.tori.wraith.event.cancelable.ICancelableEvent; +import me.tori.wraith.event.status.IStatusEvent; import me.tori.wraith.event.targeted.IClassTargetingEvent; import me.tori.wraith.listener.Listener; import me.tori.wraith.subscriber.ISubscriber; @@ -31,7 +31,6 @@ import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.CopyOnWriteArrayList; -import java.util.function.Consumer; import java.util.function.Predicate; /** @@ -176,30 +175,14 @@ public void unregister(Listener listener) { * Dispatches an event to listeners. * * @param event the event to be dispatched - * @return {@code true} if the given event is {@linkplain ICancelableEvent cancelable} and canceled, {@code false} otherwise + * @return {@code true} if the given event is {@linkplain IStatusEvent suppressed or terminated} by any listener, + * {@code false} otherwise * @throws NullPointerException if the given event is {@code null} * @throws UnsupportedOperationException if this event bus is {@link #shutdown} */ @Override public boolean dispatch(Object event) { - Objects.requireNonNull(event, "Cannot dispatch a null event to event bus " + id + "!"); - if (isShutdown()) { - throw new UnsupportedOperationException("Dispatcher " + id + " is shutdown!"); - } else { - taskExecutor.onEvent(event); - - forEachListener( - this.listeners.get(event.getClass()), - listener -> true, - listener -> listener.invoke(event), - false - ); - - if (event instanceof ICancelableEvent cancelable) { - return cancelable.isCanceled(); - } - } - return false; + return dispatch(event, null); } /** @@ -210,7 +193,8 @@ public boolean dispatch(Object event) { * * @param event the event to be dispatched * @param type the type of listener to invoke (can be {@code null}) - * @return {@code true} if the given event is {@linkplain ICancelableEvent cancelable} and canceled, {@code false} otherwise + * @return {@code true} if the given event is {@linkplain IStatusEvent suppressed or terminated} by any listener, + * {@code false} otherwise * @throws NullPointerException if the given event is {@code null} * @throws UnsupportedOperationException if this event bus is {@link #shutdown} */ @@ -222,15 +206,15 @@ public boolean dispatch(Object event, Class type) { } else { taskExecutor.onEvent(event); - forEachListener( + dispatchToEachListener( + event, this.listeners.get(event.getClass()), listener -> (type == null) || (listener.getType() == null) || (listener.getType() == type), - listener -> listener.invoke(event), false ); - if (event instanceof ICancelableEvent cancelable) { - return cancelable.isCanceled(); + if (event instanceof IStatusEvent e) { + return e.isSuppressed() || e.isTerminated(); } } return false; @@ -240,30 +224,14 @@ public boolean dispatch(Object event, Class type) { * Dispatches the given event to the target listener class * * @param event the {@linkplain IClassTargetingEvent} to be dispatched - * @return {@code true} if the given event was {@linkplain ICancelableEvent cancelable} and canceled, {@code false} otherwise + * @return {@code true} if the given event was {@linkplain IStatusEvent suppressed or terminated} by any listener, + * {@code false} otherwise * @throws NullPointerException if the given event is {@code null} * @throws UnsupportedOperationException if this event bus is {@link #shutdown} */ @Override public boolean dispatchTargeted(IClassTargetingEvent event) { - Objects.requireNonNull(event, "Cannot dispatch a null event to event bus " + id + "!"); - if (isShutdown()) { - throw new UnsupportedOperationException("Dispatcher " + id + " is shutdown!"); - } else { - taskExecutor.onEvent(event); - - forEachListener( - this.listeners.get(event.getClass()), - listener -> listener.getClass().equals(event.getTargetClass()), - listener -> listener.invoke(event), - false - ); - - if (event instanceof ICancelableEvent cancelable) { - return cancelable.isCanceled(); - } - } - return false; + return dispatchTargeted(event, null); } /** @@ -274,7 +242,8 @@ public boolean dispatchTargeted(IClassTargetingEvent event) { * * @param event the {@linkplain IClassTargetingEvent} to be dispatched * @param type the type of listener to invoke (can be {@code null}) - * @return {@code true} if the given event is {@linkplain ICancelableEvent cancelable} and canceled, {@code false} otherwise + * @return {@code true} if the given event is {@linkplain IStatusEvent suppressed or terminated} by any listener, + * {@code false} otherwise * @throws NullPointerException if the given event is {@code null} * @throws UnsupportedOperationException if this event bus is {@link #shutdown} */ @@ -286,62 +255,47 @@ public boolean dispatchTargeted(IClassTargetingEvent event, Class type) { } else { taskExecutor.onEvent(event); - forEachListener( + dispatchToEachListener( + event, this.listeners.get(event.getClass()), listener -> ((type == null) || (listener.getType() == null) || (listener.getType() == type)) && listener.getClass().equals(event.getTargetClass()), - listener -> listener.invoke(event), false ); - if (event instanceof ICancelableEvent cancelable) { - return cancelable.isCanceled(); + if (event instanceof IStatusEvent e) { + return e.isSuppressed() || e.isTerminated(); } } return false; } /** - * Dispatches an event to listeners in order of inverse-priority. E.g. the lowest priority listeners will be - * invoked before the highest priority listeners. + * Dispatches an event to listeners in order of inverse-priority. + * E.g., the lowest priority listeners will be invoked before the highest priority listeners. * * @param event the event to be dispatched - * @return {@code true} if the given event is {@linkplain ICancelableEvent cancelable} and canceled, {@code false} otherwise + * @return {@code true} if the given event is {@linkplain IStatusEvent suppressed or terminated} by any listener, + * {@code false} otherwise * @throws NullPointerException if the given event is {@code null} * @throws UnsupportedOperationException if this event bus is {@link #shutdown} */ @Override public boolean dispatchInverted(Object event) { - Objects.requireNonNull(event, "Cannot dispatch a null event to event bus " + id + "!"); - if (isShutdown()) { - throw new UnsupportedOperationException("Dispatcher " + id + " is shutdown!"); - } else { - taskExecutor.onEvent(event); - - forEachListener( - this.listeners.get(event.getClass()), - listener -> true, - listener -> listener.invoke(event), - true - ); - - if (event instanceof ICancelableEvent cancelable) { - return cancelable.isCanceled(); - } - } - return false; + return dispatchInverted(event, null); } /** - * Dispatches an event to listeners in order of inverse-priority. E.g. the lowest priority listeners will be - * invoked before the highest priority listeners. + * Dispatches an event to listeners in order of inverse-priority. + * E.g., the lowest priority listeners will be invoked before the highest priority listeners. * *

The {@code type} parameter serves as a filtering mechanism for listeners, enabling you to selectively invoke * listeners based on their type, allowing for more targeted event handling. * * @param event the event to be dispatched * @param type the type of listener to invoke (can be {@code null}) - * @return {@code true} if the given event is {@linkplain ICancelableEvent cancelable} and canceled, {@code false} otherwise + * @return {@code true} if the given event is {@linkplain IStatusEvent suppressed or terminated} by any listener, + * {@code false} otherwise * @throws NullPointerException if the given event is {@code null} * @throws UnsupportedOperationException if this event bus is {@link #shutdown} */ @@ -353,63 +307,20 @@ public boolean dispatchInverted(Object event, Class type) { } else { taskExecutor.onEvent(event); - forEachListener( + dispatchToEachListener( + event, this.listeners.get(event.getClass()), listener -> (type == null) || (listener.getType() == null) || (listener.getType() == type), - listener -> listener.invoke(event), true ); - if (event instanceof ICancelableEvent cancelable) { - return cancelable.isCanceled(); + if (event instanceof IStatusEvent e) { + return e.isSuppressed() || e.isTerminated(); } } return false; } - /** - * Applies a given action to each {@linkplain Listener} in a list that matches a specified predicate. - * Listeners are processed either in normal order or in reverse order based on the - * {@code invertPriority} flag. - * Listeners that should not persist are removed from the list after the action is applied. - * - * @param listeners the list of listeners to be processed - * @param predicate the condition that each listener must satisfy to have the action applied - * @param action the action to be performed on each listener that satisfies the predicate - * @param invertPriority if {@code true}, listeners are processed in reverse order; otherwise, - * they are processed in normal order - * @since 3.2.0 - */ - private void forEachListener(List listeners, Predicate predicate, Consumer action, boolean invertPriority) { - if (listeners != null && !listeners.isEmpty()) { - if (invertPriority) { - ListIterator iterator = listeners.listIterator(listeners.size()); - while (iterator.hasPrevious()) { - Listener listener = iterator.previous(); - if (!predicate.test(listener)) { - continue; - } - action.accept(listener); - if (!listener.shouldPersist()) { - listeners.remove(listener); - } - } - } else { - Iterator iterator = listeners.listIterator(0); - while (iterator.hasNext()) { - Listener listener = iterator.next(); - if (!predicate.test(listener)) { - continue; - } - action.accept(listener); - if (!listener.shouldPersist()) { - listeners.remove(listener); - } - } - } - } - } - /** * Schedules a task to be executed. * @@ -461,6 +372,56 @@ public int getId() { return id; } + /** + * Applies a given action to each {@linkplain Listener} in a list that matches a specified predicate. + * Listeners are processed either in normal order or in reverse order based on the + * {@code invertPriority} flag. + * Listeners that should not persist are removed from the list after the action is applied. + * + * @param event the event to be handled by each listener that satisfies the predicate + * @param listeners the list of listeners to be processed + * @param predicate the condition that each listener must satisfy to have the action applied + * @param invertPriority if {@code true}, listeners are processed in reverse order; otherwise, + * they are processed in normal order + * @since 3.2.0 + */ + @SuppressWarnings("DuplicatedCode") + private void dispatchToEachListener(Object event, List listeners, Predicate predicate, boolean invertPriority) { + if (listeners != null && !listeners.isEmpty()) { + if (invertPriority) { + ListIterator iterator = listeners.listIterator(listeners.size()); + while (iterator.hasPrevious()) { + Listener listener = iterator.previous(); + if (!predicate.test(listener)) { + continue; + } + listener.invoke(event); + if ((event instanceof IStatusEvent e) && e.isTerminated()) { + break; + } + if (!listener.shouldPersist()) { + listeners.remove(listener); + } + } + } else { + Iterator iterator = listeners.listIterator(0); + while (iterator.hasNext()) { + Listener listener = iterator.next(); + if (!predicate.test(listener)) { + continue; + } + listener.invoke(event); + if ((event instanceof IStatusEvent e) && e.isTerminated()) { + break; + } + if (!listener.shouldPersist()) { + listeners.remove(listener); + } + } + } + } + } + /** * Checks if this event bus is equal to another object. *

If the given object is an event bus, it is only considered equal if {@code this.id == that.id}. diff --git a/src/main/java/me/tori/wraith/bus/IEventBus.java b/src/main/java/me/tori/wraith/bus/IEventBus.java index 21f0be9..6e905e4 100644 --- a/src/main/java/me/tori/wraith/bus/IEventBus.java +++ b/src/main/java/me/tori/wraith/bus/IEventBus.java @@ -21,7 +21,7 @@ package me.tori.wraith.bus; -import me.tori.wraith.event.cancelable.ICancelableEvent; +import me.tori.wraith.event.status.IStatusEvent; import me.tori.wraith.listener.EventListener; import me.tori.wraith.listener.Listener; import me.tori.wraith.subscriber.ISubscriber; @@ -64,14 +64,16 @@ public interface IEventBus { /** * @param event the event to be dispatched - * @return {@code true} if the given event is {@linkplain ICancelableEvent cancelable} and canceled, {@code false} otherwise + * @return {@code true} if the given event is {@linkplain IStatusEvent suppressed or terminated} by any listener, + * {@code false} otherwise */ boolean dispatch(Object event); /** * @param event the event to be dispatched * @param type the type of listener to invoke (can be {@code null}) - * @return {@code true} if the given event is {@linkplain ICancelableEvent cancelable} and canceled, {@code false} otherwise + * @return {@code true} if the given event is {@linkplain IStatusEvent suppressed or terminated} by any listener, + * {@code false} otherwise */ boolean dispatch(Object event, Class type); diff --git a/src/main/java/me/tori/wraith/bus/InvertableEventBus.java b/src/main/java/me/tori/wraith/bus/InvertableEventBus.java index ba5270d..b1e51a2 100644 --- a/src/main/java/me/tori/wraith/bus/InvertableEventBus.java +++ b/src/main/java/me/tori/wraith/bus/InvertableEventBus.java @@ -21,7 +21,7 @@ package me.tori.wraith.bus; -import me.tori.wraith.event.cancelable.ICancelableEvent; +import me.tori.wraith.event.status.IStatusEvent; /** * @author 7orivorian @@ -31,7 +31,8 @@ public interface InvertableEventBus extends IEventBus { /** * @param event the event to be dispatched - * @return {@code true} if the given event is {@linkplain ICancelableEvent cancelable} and canceled, {@code false} otherwise + * @return {@code true} if the given event is {@linkplain IStatusEvent suppressed or terminated} by any listener, + * {@code false} otherwise * @see EventBus#dispatchInverted(Object) */ boolean dispatchInverted(Object event); @@ -39,7 +40,8 @@ public interface InvertableEventBus extends IEventBus { /** * @param event the event to be dispatched * @param type the type of listener to invoke (can be {@code null}) - * @return {@code true} if the given event is {@linkplain ICancelableEvent cancelable} and canceled, {@code false} otherwise + * @return {@code true} if the given event is {@linkplain IStatusEvent suppressed or terminated} by any listener, + * {@code false} otherwise * @see EventBus#dispatchInverted(Object, Class) */ boolean dispatchInverted(Object event, Class type); diff --git a/src/main/java/me/tori/wraith/bus/TargetableEventBus.java b/src/main/java/me/tori/wraith/bus/TargetableEventBus.java index abbbce9..f44517d 100644 --- a/src/main/java/me/tori/wraith/bus/TargetableEventBus.java +++ b/src/main/java/me/tori/wraith/bus/TargetableEventBus.java @@ -21,7 +21,7 @@ package me.tori.wraith.bus; -import me.tori.wraith.event.cancelable.ICancelableEvent; +import me.tori.wraith.event.status.IStatusEvent; import me.tori.wraith.event.targeted.IClassTargetingEvent; /** @@ -32,7 +32,8 @@ public interface TargetableEventBus extends IEventBus { /** * @param event the {@linkplain IClassTargetingEvent} to dispatch - * @return {@code true} if the given event was {@linkplain ICancelableEvent cancelable} and canceled, {@code false otherwise} + * @return {@code true} if the given event was {@linkplain IStatusEvent suppressed or terminated} by any listener, + * {@code false otherwise} * @see EventBus#dispatchTargeted(IClassTargetingEvent) */ boolean dispatchTargeted(IClassTargetingEvent event); @@ -40,7 +41,8 @@ public interface TargetableEventBus extends IEventBus { /** * @param event the {@linkplain IClassTargetingEvent} to dispatch * @param type the type of listener to invoke (can be {@code null}) - * @return {@code true} if the given event was {@linkplain ICancelableEvent cancelable} and canceled, {@code false otherwise} + * @return {@code true} if the given event was {@linkplain IStatusEvent suppressed or terminated} by any listener, + * {@code false otherwise} * @see EventBus#dispatchTargeted(IClassTargetingEvent, Class) */ boolean dispatchTargeted(IClassTargetingEvent event, Class type); diff --git a/src/main/java/me/tori/wraith/event/cancelable/CancelableEvent.java b/src/main/java/me/tori/wraith/event/cancelable/CancelableEvent.java index 1558a53..ae3f539 100644 --- a/src/main/java/me/tori/wraith/event/cancelable/CancelableEvent.java +++ b/src/main/java/me/tori/wraith/event/cancelable/CancelableEvent.java @@ -21,48 +21,24 @@ package me.tori.wraith.event.cancelable; +import me.tori.wraith.event.status.StatusEvent; + +import static me.tori.wraith.event.status.IStatusEvent.EventStatus.SUPPRESSED; + /** * Default implementation of the {@link ICancelableEvent} interface. * - *

This class provides a basic implementation of the cancelable event behavior. - * Event classes can extend this class to inherit the cancellation capability. - * * @author 7orivorian * @see ICancelableEvent * @since 1.0.0 */ -public class CancelableEvent implements ICancelableEvent { - - /** - * Indicates the cancellation state of this event. - */ - private boolean canceled = false; - - /** - * Checks whether this event is canceled. - * - * @return {@code true} if this event is canceled, {@code false} otherwise - */ - @Override - public boolean isCanceled() { - return canceled; - } - - /** - * Sets the cancellation state of this event. - * - * @param canceled {@code true} to mark this event as canceled, {@code false} otherwise - * @implNote Passing {@code false} to this method can un-cancel this event if it was previously canceled. - */ - @Override - public void setCanceled(boolean canceled) { - this.canceled = canceled; - } +@Deprecated(forRemoval = true, since = "3.2.0") +public class CancelableEvent extends StatusEvent implements ICancelableEvent { @Override public String toString() { return "Cancelable{" + - "canceled=" + canceled + + "canceled=" + (getEventStatus() == SUPPRESSED) + '}'; } } \ No newline at end of file diff --git a/src/main/java/me/tori/wraith/event/cancelable/ICancelableEvent.java b/src/main/java/me/tori/wraith/event/cancelable/ICancelableEvent.java index 36feebf..13b14ea 100644 --- a/src/main/java/me/tori/wraith/event/cancelable/ICancelableEvent.java +++ b/src/main/java/me/tori/wraith/event/cancelable/ICancelableEvent.java @@ -21,43 +21,36 @@ package me.tori.wraith.event.cancelable; +import me.tori.wraith.event.status.IStatusEvent; + /** - * Represents a cancelable event that can be prevented from further processing. - * - *

This interface allows events to be canceled, indicating that they should not proceed through their - * normal processing flow. This is particularly useful in scenarios where certain conditions require an event - * to be halted from performing its intended action. - * * @author 7orivorian * @see CancelableEvent * @since 1.0.0 + * @deprecated Use {@link IStatusEvent} instead. */ -public interface ICancelableEvent { +@Deprecated(forRemoval = true, since = "3.2.0") +public interface ICancelableEvent extends IStatusEvent { /** - * Checks whether this event is canceled. - * * @return {@code true} if this event is canceled, {@code false} otherwise + * @see #isSuppressed() */ - boolean isCanceled(); + default boolean isCanceled() { + return isSuppressed(); + } /** - * Sets the cancellation state of this event. - * - * @param canceled {@code true} to mark this event as canceled, {@code false} otherwise - * @implNote Passing {@code false} to this method can un-cancel this event if it was previously canceled. + * @see #setSuppressed(boolean) */ - void setCanceled(boolean canceled); + default void setCanceled(boolean canceled) { + setSuppressed(canceled); + } /** - * Convenience method to cancel this event. - * - *

This is a shorthand method equivalent to calling {@code setCanceled(true)}, conveniently - * marking this event as canceled. - * - * @see #setCanceled(boolean) + * @see #suppress() */ default void cancel() { - setCanceled(true); + suppress(); } } \ No newline at end of file diff --git a/src/main/java/me/tori/wraith/event/status/IStatusEvent.java b/src/main/java/me/tori/wraith/event/status/IStatusEvent.java new file mode 100644 index 0000000..5d17741 --- /dev/null +++ b/src/main/java/me/tori/wraith/event/status/IStatusEvent.java @@ -0,0 +1,128 @@ +/* + * Copyright (c) 2024 7orivorian. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package me.tori.wraith.event.status; + +import org.jetbrains.annotations.NotNull; + +/** + * Represents an event that can be alive, suppressed, or terminated. + *

+ * This interface defines the status of an event and provides methods to + * manipulate and check this status. The possible statuses are defined by {@link EventStatus}.

+ * + * @author 7orivorian + * @see StatusEvent + * @since 3.2.0 + */ +public interface IStatusEvent { + + /** + * Gets the current status of this event. + * + * @return the current {@link EventStatus} of this event. + */ + @NotNull + EventStatus getEventStatus(); + + /** + * Sets the status of this event. + * + * @param status the new {@link EventStatus} to set. + */ + void setEventStatus(@NotNull EventStatus status); + + /** + * Checks whether this event is suppressed. + * + * @return {@code true} if this event is suppressed, {@code false} otherwise. + */ + boolean isSuppressed(); + + /** + * Sets the suppression state of this event. + * + *

If the event is not terminated, this method will update the event's state to either + * suppressed or alive based on the provided boolean parameter ({@code suppressed}).

+ * + * @param suppressed {@code true} to suppress the event, {@code false} to unsuppress it. + * @return {@code true} if the suppression state was successfully updated, {@code false} if the event is terminated. + */ + default boolean setSuppressed(boolean suppressed) { + if (getEventStatus() != EventStatus.TERMINATED) { + if (suppressed) { + setEventStatus(EventStatus.SUPPRESSED); + } else { + setEventStatus(EventStatus.ALIVE); + } + return true; + } + return false; + } + + /** + * Convenience method to suppress this event if it is not currently terminated. + *

+ * This is a shorthand method equivalent to calling {@code setSuppressed(true)}. + * + * @return {@code true} if the event was successfully suppressed, {@code false} if the event is terminated. + * @see #setSuppressed(boolean) + */ + default boolean suppress() { + return setSuppressed(true); + } + + /** + * Checks whether this event is terminated. + * + * @return {@code true} if this event is terminated, {@code false} otherwise. + */ + boolean isTerminated(); + + /** + * Convenience method to terminate this event. + *

+ * This is a shorthand method equivalent to calling {@code setEventStatus(EventStatus.TERMINATED)}. + * + * @see #setEventStatus(EventStatus) + */ + default void terminate() { + setEventStatus(EventStatus.TERMINATED); + } + + /** + * Enum representing the possible statuses of a {@link IStatusEvent}. + */ + enum EventStatus { + /** + * The event is active and not suppressed or terminated. + */ + ALIVE, + /** + * The event is suppressed. A suppressed event may become unsuppressed. + */ + SUPPRESSED, + /** + * The event is terminated and cannot be altered further. + */ + TERMINATED + } +} \ No newline at end of file diff --git a/src/main/java/me/tori/wraith/event/status/StatusEvent.java b/src/main/java/me/tori/wraith/event/status/StatusEvent.java new file mode 100644 index 0000000..ce1b48b --- /dev/null +++ b/src/main/java/me/tori/wraith/event/status/StatusEvent.java @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2024 7orivorian. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package me.tori.wraith.event.status; + +import org.jetbrains.annotations.NotNull; + +/** + * Default implementation of {@link IStatusEvent}. + * + * @author 7orivorian + * @see IStatusEvent + * @since 3.2.0 + */ +public class StatusEvent implements IStatusEvent { + + protected EventStatus status = EventStatus.ALIVE; + + /** + * {@inheritDoc} + * + * @return the current {@link EventStatus} of this event. + */ + @Override + public @NotNull EventStatus getEventStatus() { + return status; + } + + /** + * {@inheritDoc} + * + * @param status the new {@link EventStatus} to set. + */ + @Override + public void setEventStatus(@NotNull EventStatus status) { + this.status = status; + } + + /** + * {@inheritDoc} + * + * @return {@code true} if this event is suppressed, {@code false} otherwise. + */ + @Override + public boolean isSuppressed() { + return status == EventStatus.SUPPRESSED; + } + + /** + * {@inheritDoc} + * + * @return {@code true} if this event is terminated, {@code false} otherwise. + */ + @Override + public boolean isTerminated() { + return status == EventStatus.TERMINATED; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if ((o == null) || (getClass() != o.getClass())) { + return false; + } + + StatusEvent that = (StatusEvent) o; + return status == that.status; + } + + @Override + public int hashCode() { + return status.hashCode(); + } + + @Override + public String toString() { + return "StatusEvent{" + + "status=" + status + + '}'; + } +} \ No newline at end of file diff --git a/src/main/test/me/tori/wraith/statusevent/StatusEventTest.java b/src/main/test/me/tori/wraith/statusevent/StatusEventTest.java new file mode 100644 index 0000000..03cff8e --- /dev/null +++ b/src/main/test/me/tori/wraith/statusevent/StatusEventTest.java @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2024 7orivorian. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package me.tori.wraith.statusevent; + +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 org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +/** + * @author 7orivorian + * @since 3.2.0 + */ +public class StatusEventTest { + + @Test + public void testSupression() { + final EventBus bus = new EventBus(); + + MySubscriber subscriber = new MySubscriber() {{ + registerListeners( + new LambdaEventListener<>(StatusEvent.class, 1, event -> { + this.counter = 1; + event.suppress(); + }), + new LambdaEventListener<>(StatusEvent.class, 0, event -> { + this.counter++; + }) + ); + }}; + bus.subscribe(subscriber); + + Assertions.assertTrue(bus.dispatch(new StatusEvent())); + Assertions.assertEquals(2, subscriber.counter); + } + + @Test + public void testTermination() { + final EventBus bus = new EventBus(); + + MySubscriber subscriber = new MySubscriber() {{ + registerListeners( + new LambdaEventListener<>(StatusEvent.class, 1, event -> { + this.counter = 1; + event.terminate(); + }), + new LambdaEventListener<>(StatusEvent.class, 0, event -> { + this.counter = 1_000; + }) + ); + }}; + bus.subscribe(subscriber); + + Assertions.assertTrue(bus.dispatch(new StatusEvent())); + Assertions.assertEquals(1, subscriber.counter); + } + + private static class MySubscriber extends Subscriber { + + public int counter = 0; + + public MySubscriber() { + + } + } +} \ No newline at end of file diff --git a/src/main/test/me/tori/wraith/targetedevent/TestSubsciber.java b/src/main/test/me/tori/wraith/targetedevent/TestSubsciber.java deleted file mode 100644 index 5b2db18..0000000 --- a/src/main/test/me/tori/wraith/targetedevent/TestSubsciber.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2021-2024 7orivorian. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package me.tori.wraith.targetedevent; - -import me.tori.wraith.subscriber.Subscriber; - -/** - * @author 7orivorian - */ -public class TestSubsciber extends Subscriber { - - public TestSubsciber() { - registerListeners( - new ValidListener(), - new InvalidListener() - ); - } -} \ No newline at end of file From 2383d1276626b38942dfbfbd870b2844d1e3d5e0 Mon Sep 17 00:00:00 2001 From: 7orivorian <7orivorian+github@gmail.com> Date: Tue, 25 Jun 2024 00:52:28 -0400 Subject: [PATCH 18/26] Refactor TargetedEventTest Signed-off-by: 7orivorian <7orivorian+github@gmail.com> --- .../wraith/targetedevent/InvalidListener.java | 40 -------------- .../targetedevent/TargetedEventTest.java | 53 +++++++++++++++++-- .../tori/wraith/targetedevent/TestEvent.java | 45 ---------------- .../wraith/targetedevent/ValidListener.java | 39 -------------- 4 files changed, 50 insertions(+), 127 deletions(-) delete mode 100644 src/main/test/me/tori/wraith/targetedevent/InvalidListener.java delete mode 100644 src/main/test/me/tori/wraith/targetedevent/TestEvent.java delete mode 100644 src/main/test/me/tori/wraith/targetedevent/ValidListener.java diff --git a/src/main/test/me/tori/wraith/targetedevent/InvalidListener.java b/src/main/test/me/tori/wraith/targetedevent/InvalidListener.java deleted file mode 100644 index 5de9566..0000000 --- a/src/main/test/me/tori/wraith/targetedevent/InvalidListener.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2021-2024 7orivorian. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package me.tori.wraith.targetedevent; - -import me.tori.wraith.listener.EventListener; - -/** - * @author 7orivorian - */ -public class InvalidListener extends EventListener { - - public InvalidListener() { - super(TestEvent.class); - } - - @Override - public void invoke(TestEvent event) { - event.message = "mwahahahaa >:/"; - event.cancel(); - } -} \ No newline at end of file diff --git a/src/main/test/me/tori/wraith/targetedevent/TargetedEventTest.java b/src/main/test/me/tori/wraith/targetedevent/TargetedEventTest.java index 4813fd2..a7ddbb3 100644 --- a/src/main/test/me/tori/wraith/targetedevent/TargetedEventTest.java +++ b/src/main/test/me/tori/wraith/targetedevent/TargetedEventTest.java @@ -22,6 +22,11 @@ package me.tori.wraith.targetedevent; import me.tori.wraith.bus.EventBus; +import me.tori.wraith.event.cancelable.CancelableEvent; +import me.tori.wraith.event.targeted.IClassTargetingEvent; +import me.tori.wraith.listener.EventListener; +import me.tori.wraith.listener.Listener; +import me.tori.wraith.subscriber.Subscriber; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -35,10 +40,52 @@ public class TargetedEventTest { public void testTargetedEvent() { final EventBus bus = new EventBus(); - TestSubsciber subsciber = new TestSubsciber(); - bus.subscribe(subsciber); + bus.subscribe(new Subscriber() {{ + registerListeners( + new MyListener(), + new OtherListener() + ); + }}); - TestEvent event = new TestEvent("message", ValidListener.class); + TestEvent event = new TestEvent(MyListener.class); assertFalse(bus.dispatchTargeted(event)); } + + public static class MyListener extends EventListener { + + public MyListener() { + super(TestEvent.class); + } + + @Override + public void invoke(TestEvent event) { + + } + } + + public static class OtherListener extends EventListener { + + public OtherListener() { + super(TestEvent.class); + } + + @Override + public void invoke(TestEvent event) { + event.cancel(); + } + } + + public static class TestEvent extends CancelableEvent implements IClassTargetingEvent { + + private final Class> targetClass; + + public TestEvent(Class> target) { + this.targetClass = target; + } + + @Override + public Class> getTargetClass() { + return targetClass; + } + } } \ No newline at end of file diff --git a/src/main/test/me/tori/wraith/targetedevent/TestEvent.java b/src/main/test/me/tori/wraith/targetedevent/TestEvent.java deleted file mode 100644 index 6cbad3b..0000000 --- a/src/main/test/me/tori/wraith/targetedevent/TestEvent.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2021-2024 7orivorian. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package me.tori.wraith.targetedevent; - -import me.tori.wraith.event.cancelable.CancelableEvent; -import me.tori.wraith.event.targeted.IClassTargetingEvent; -import me.tori.wraith.listener.Listener; - -/** - * @author 7orivorian - */ -public class TestEvent extends CancelableEvent implements IClassTargetingEvent { - - public String message; - private final Class> targetClass; - - public TestEvent(String message, Class> target) { - this.message = message; - this.targetClass = target; - } - - @Override - public Class> getTargetClass() { - return targetClass; - } -} \ No newline at end of file diff --git a/src/main/test/me/tori/wraith/targetedevent/ValidListener.java b/src/main/test/me/tori/wraith/targetedevent/ValidListener.java deleted file mode 100644 index e23be63..0000000 --- a/src/main/test/me/tori/wraith/targetedevent/ValidListener.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2021-2024 7orivorian. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package me.tori.wraith.targetedevent; - -import me.tori.wraith.listener.EventListener; - -/** - * @author 7orivorian - */ -public class ValidListener extends EventListener { - - public ValidListener() { - super(TestEvent.class); - } - - @Override - public void invoke(TestEvent event) { - event.message = "hello world :D"; - } -} \ No newline at end of file From 71873dde54587056a00f4b2fe905f091c4b28a0b Mon Sep 17 00:00:00 2001 From: 7orivorian <7orivorian+github@gmail.com> Date: Tue, 25 Jun 2024 00:53:40 -0400 Subject: [PATCH 19/26] Update .gitignore Signed-off-by: 7orivorian <7orivorian+github@gmail.com> --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index a1bc206..5a45940 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /.idea/ /target/ /dependency-reduced-pom.xml +/developer-docs/ \ No newline at end of file From 45ddb5ef1eec69852c9510cb17dbaeadacea5cab Mon Sep 17 00:00:00 2001 From: 7orivorian <7orivorian+github@gmail.com> Date: Tue, 25 Jun 2024 01:01:26 -0400 Subject: [PATCH 20/26] Update README.md Signed-off-by: 7orivorian <7orivorian+github@gmail.com> --- README.md | 50 +++++++++++++------------------------------------- 1 file changed, 13 insertions(+), 37 deletions(-) diff --git a/README.md b/README.md index 74277fa..df822c6 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ Lightweight Java event library created and maintained by [7orivorian](https://gi com.github.7orivorian Wraith - 3.1.0 + 3.2.0 ``` @@ -51,13 +51,13 @@ repositories { ```gradle dependencies { - implementation 'com.github.7orivorian:Wraith:3.1.0' + implementation 'com.github.7orivorian:Wraith:3.2.0' } ``` ### Other -Download a `.jar` file from [releases](https://github.com/7orivorian/Wraith/releases/tag/3.1.0) +Download a `.jar` file from [releases](https://github.com/7orivorian/Wraith/releases/tag/3.2.0) # Building @@ -66,7 +66,7 @@ Download a `.jar` file from [releases](https://github.com/7orivorian/Wraith/rele Packaged file can be found in the `target/` directory. -# Usage +# Quick-Start Guide While the code itself is thoroughly documented, here's a simple guide to help you get started with the latest features. @@ -96,11 +96,13 @@ 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 ExampleSubscriber extends Subscriber { +public class Consts { private static final IEventBus EVENT_BUS = new EventBus(); +} +public class ExampleSubscriber extends Subscriber { public ExampleSubscriber() { - EVENT_BUS.subscribe(this); + Consts.EVENT_BUS.subscribe(this); } } ``` @@ -144,24 +146,6 @@ public class ExampleEvent { } ``` -To create a cancelable event, you can: - -Extend the Cancelable class: - -```java -public class CancelableEvent extends Cancelable { -// ... -} -``` - -Implement the ICancelable interface: - -```java -public class CancelableEvent implements ICancelable { -// ... -} -``` - ### Listeners @@ -180,9 +164,7 @@ public class ExampleListener extends EventListener { @Override public void invoke(ExampleEvent event) { - if (event.getStage() == EventStage.POST) { - event.setMessage("I feel wonderful!"); - } + event.setMessage("Hello world!"); } } ``` @@ -205,11 +187,7 @@ public class ExampleSubscriber extends Subscriber { public ExampleSubscriber() { // Register the listener registerListener( - new LambdaEventListener<>(ExampleEvent.class, event -> { - if (event.getStage() == EventStage.PRE) { - event.setMessage("Hello world!"); - } - }) + new LambdaEventListener<>(ExampleEvent.class, event -> event.setMessage("Hello world!")) ); } } @@ -234,20 +212,18 @@ public class Example { public static void main(String[] args) { - ExampleEvent event = new ExampleEvent("Initial message"); + ExampleEvent event = new ExampleEvent("world greetings"); EVENT_BUS.dispatch(event); - if (!event.isCanceled()) { - System.out.println(event.getMessage()); - } + System.out.println(event.getMessage()); } } ``` -Feel free to explore the [example folder](./examples/java/me/tori/example) for more Wraith implementations. +Please explore the [example folder](./examples/java/me/tori/example) for _even more_ Wraith implementations! # Contributing From 9e55a5f64d7fe87a72c5a05d7b498cb88c51c483 Mon Sep 17 00:00:00 2001 From: 7orivorian <7orivorian+github@gmail.com> Date: Tue, 25 Jun 2024 01:03:02 -0400 Subject: [PATCH 21/26] Update SECURITY.md Signed-off-by: 7orivorian <7orivorian+github@gmail.com> --- SECURITY.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/SECURITY.md b/SECURITY.md index 6ae715d..487acba 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -6,8 +6,7 @@ |-----------|--------------------| | \>= 3.0.0 | :white_check_mark: | | 2.0.1 | :white_check_mark: | -| 2.0.0 | :x: | -| < 2.0.0 | :x: | +| <= 2.0.0 | :x: | ## Reporting a Vulnerability From 7b4dffd333f6e8ee08a2a5e01913f02dd500df06 Mon Sep 17 00:00:00 2001 From: 7orivorian <7orivorian+github@gmail.com> Date: Tue, 25 Jun 2024 01:25:10 -0400 Subject: [PATCH 22/26] Update SECURITY.md Signed-off-by: 7orivorian <7orivorian+github@gmail.com> --- SECURITY.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/SECURITY.md b/SECURITY.md index 487acba..4ea3204 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -8,7 +8,4 @@ | 2.0.1 | :white_check_mark: | | <= 2.0.0 | :x: | -## Reporting a Vulnerability - -Vulnerabilities can be reported by visiting the 'Security' -tab on this repo and clicking 'Report a vulnerability'. +[Report a vulnerability.](https://github.com/7orivorian/Wraith/security/advisories/new) From 80e301b591328d71cfea325cb477cf0022cba4f3 Mon Sep 17 00:00:00 2001 From: 7orivorian <7orivorian+github@gmail.com> Date: Tue, 25 Jun 2024 01:28:08 -0400 Subject: [PATCH 23/26] IntelliJ failed to update license dates so I did it manually Signed-off-by: 7orivorian <7orivorian+github@gmail.com> --- LICENSE | 2 +- src/main/resources/LICENSE | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/LICENSE b/LICENSE index 06c5e4d..7a2067d 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2021-2023 7orivorian +Copyright (c) 2021-2024 7orivorian Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/src/main/resources/LICENSE b/src/main/resources/LICENSE index 06c5e4d..7a2067d 100644 --- a/src/main/resources/LICENSE +++ b/src/main/resources/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2021-2023 7orivorian +Copyright (c) 2021-2024 7orivorian Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal From 19a5565bb447d2ffc824f0860463f41fafe6f64d Mon Sep 17 00:00:00 2001 From: 7orivorian <7orivorian+github@gmail.com> Date: Tue, 25 Jun 2024 17:14:58 -0400 Subject: [PATCH 24/26] Remove double null-check in StagedEvent Signed-off-by: 7orivorian <7orivorian+github@gmail.com> --- src/main/java/me/tori/wraith/event/staged/StagedEvent.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/me/tori/wraith/event/staged/StagedEvent.java b/src/main/java/me/tori/wraith/event/staged/StagedEvent.java index 6183216..bc332a4 100644 --- a/src/main/java/me/tori/wraith/event/staged/StagedEvent.java +++ b/src/main/java/me/tori/wraith/event/staged/StagedEvent.java @@ -45,7 +45,6 @@ public class StagedEvent implements IStagedEvent { * @throws NullPointerException If the provided {@code stage} is {@code null}. */ public StagedEvent(@NotNull EventStage stage) { - Objects.requireNonNull(stage); this.stage = stage; } From 5e24750cda37e9ad7eeabbe41f282be6b71f1091 Mon Sep 17 00:00:00 2001 From: 7orivorian <7orivorian+github@gmail.com> Date: Tue, 25 Jun 2024 17:19:33 -0400 Subject: [PATCH 25/26] Fix minor code formatting issue in StatusEvent Signed-off-by: 7orivorian <7orivorian+github@gmail.com> --- src/main/java/me/tori/wraith/event/status/StatusEvent.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/me/tori/wraith/event/status/StatusEvent.java b/src/main/java/me/tori/wraith/event/status/StatusEvent.java index ce1b48b..86ff702 100644 --- a/src/main/java/me/tori/wraith/event/status/StatusEvent.java +++ b/src/main/java/me/tori/wraith/event/status/StatusEvent.java @@ -39,8 +39,9 @@ public class StatusEvent implements IStatusEvent { * * @return the current {@link EventStatus} of this event. */ + @NotNull @Override - public @NotNull EventStatus getEventStatus() { + public EventStatus getEventStatus() { return status; } From 956d35f574ce912484ba33a9472b9e86f9c180d0 Mon Sep 17 00:00:00 2001 From: 7orivorian <7orivorian+github@gmail.com> Date: Tue, 25 Jun 2024 18:20:53 -0400 Subject: [PATCH 26/26] Add StatusEvent examples Signed-off-by: 7orivorian <7orivorian+github@gmail.com> --- .../statusevents/SupressionExample.java | 67 +++++++++++++++++++ .../statusevents/TerminationExample.java | 67 +++++++++++++++++++ 2 files changed, 134 insertions(+) create mode 100644 examples/java/me/tori/example/statusevents/SupressionExample.java create mode 100644 examples/java/me/tori/example/statusevents/TerminationExample.java diff --git a/examples/java/me/tori/example/statusevents/SupressionExample.java b/examples/java/me/tori/example/statusevents/SupressionExample.java new file mode 100644 index 0000000..f62abf0 --- /dev/null +++ b/examples/java/me/tori/example/statusevents/SupressionExample.java @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2024 7orivorian. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package me.tori.example.statusevents; + +import me.tori.wraith.bus.EventBus; +import me.tori.wraith.bus.IEventBus; +import me.tori.wraith.event.status.StatusEvent; +import me.tori.wraith.listener.LambdaEventListener; +import me.tori.wraith.subscriber.Subscriber; + +/** + * @author 7orivorian + * @since 3.2.0 + */ +public class SupressionExample { + + private static final IEventBus EVENT_BUS = new EventBus(); + private static final Subscriber SUBSCRIBER = new Subscriber() {{ + registerListeners( + new LambdaEventListener<>(StringEvent.class, 1, event -> { + event.message = "Hello world!"; + event.suppress(); + }), + new LambdaEventListener<>(StringEvent.class, 0, event -> { + event.message = "I do not greet"; + }) + ); + }}; + + public static void main(String[] args) { + EVENT_BUS.subscribe(SUBSCRIBER); + + StringEvent event = new StringEvent(null); + System.out.println(EVENT_BUS.dispatch(event)); // This will print "true" because the event was suppressed + + // Even though the event was suppressed, it was still passed to subsequent listeners + System.out.println(event.message); // This will print "I do not greet" + } + + private static class StringEvent extends StatusEvent { + + public String message; + + public StringEvent(String message) { + this.message = message; + } + } +} \ No newline at end of file diff --git a/examples/java/me/tori/example/statusevents/TerminationExample.java b/examples/java/me/tori/example/statusevents/TerminationExample.java new file mode 100644 index 0000000..5a2a4f1 --- /dev/null +++ b/examples/java/me/tori/example/statusevents/TerminationExample.java @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2024 7orivorian. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package me.tori.example.statusevents; + +import me.tori.wraith.bus.EventBus; +import me.tori.wraith.bus.IEventBus; +import me.tori.wraith.event.status.StatusEvent; +import me.tori.wraith.listener.LambdaEventListener; +import me.tori.wraith.subscriber.Subscriber; + +/** + * @author 7orivorian + * @since 3.2.0 + */ +public class TerminationExample { + + private static final IEventBus EVENT_BUS = new EventBus(); + private static final Subscriber SUBSCRIBER = new Subscriber() {{ + registerListeners( + new LambdaEventListener<>(StringEvent.class, 1, event -> { + event.message = "Hello world!"; + event.terminate(); + }), + new LambdaEventListener<>(StringEvent.class, 0, event -> { + event.message = "I do not greet"; + }) + ); + }}; + + public static void main(String[] args) { + EVENT_BUS.subscribe(SUBSCRIBER); + + StringEvent event = new StringEvent(null); + System.out.println(EVENT_BUS.dispatch(event)); // This will print "true" because the event was terminated + + // Terminated events are not handled by subsequent listeners + System.out.println(event.message); // This will print "Hello world!" + } + + private static class StringEvent extends StatusEvent { + + public String message; + + public StringEvent(String message) { + this.message = message; + } + } +} \ No newline at end of file