From d08baa6d0eea01995d75352b297462fcdbafbccf Mon Sep 17 00:00:00 2001 From: 7orivorian <7orivorian+github@gmail.com> Date: Wed, 3 Jul 2024 00:40:16 -0400 Subject: [PATCH 01/17] Refactor ListenerBuilder documentation Signed-off-by: 7orivorian <7orivorian+github@gmail.com> --- src/main/java/me/tori/wraith/listener/ListenerBuilder.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/me/tori/wraith/listener/ListenerBuilder.java b/src/main/java/me/tori/wraith/listener/ListenerBuilder.java index bf576c0..2c02670 100644 --- a/src/main/java/me/tori/wraith/listener/ListenerBuilder.java +++ b/src/main/java/me/tori/wraith/listener/ListenerBuilder.java @@ -36,7 +36,7 @@ *
Usage Example: *
* {@code - * EventListener* - * @paramlistener = new ListenerBuilder () + * EventListener listener = new ListenerBuilder<>() * .target(MyEvent.class) * .type(SomeSpecificType.class) * .priority(5) @@ -46,7 +46,7 @@ * } *
+ * This default method evaluates whether the given type is acceptable by comparing it with + * the type associated with this listener. It returns {@code true} if any of the following conditions are met: + *
+ * This method checks if the given event is not an instance of {@code IClassTargetingEvent} + * or, if it is, delegates the check to the {@code isListenerTargeted} method of the event. + * + * @param listener the listener to check + * @param event the event to check against + * @return {@code true} if the event targets the listener, {@code false} otherwise. + * @since 3.3.0 + */ + static boolean isListenerTargetedByEvent(Listener> listener, Object event) { + return !(event instanceof IClassTargetingEvent e) + || e.isListenerTargeted(listener); + } + /** * Retrieves the target class of listeners for this event. * * @return The class that represents the type of listeners targeted by this event. */ Class extends Listener>> getTargetClass(); + + /** + * Checks if the listener is an instance of the target class of this event. + *
+ * This default method verifies if the provided listener is an instance of the class
+ * that the event targets by using the {@code getTargetClass} method.
+ *
+ * @param listener the listener to check
+ * @return {@code true} if the listener is an instance of the target class, {@code false} otherwise.
+ * @since 3.3.0
+ */
+ default boolean isListenerTargeted(Listener> listener) {
+ return getTargetClass().isInstance(listener);
+ }
}
\ No newline at end of file
From 129d5aab58f1f78ddd439aff39543d69817f0e46 Mon Sep 17 00:00:00 2001
From: 7orivorian <7orivorian+github@gmail.com>
Date: Wed, 3 Jul 2024 00:44:19 -0400
Subject: [PATCH 04/17] Deprecated TargetableEventBus class as well as
EventBus#dispatchTargeted methods
Signed-off-by: 7orivorian <7orivorian+github@gmail.com>
---
src/main/java/me/tori/wraith/bus/EventBus.java | 4 ++++
.../java/me/tori/wraith/bus/TargetableEventBus.java | 10 ++++++++--
2 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/src/main/java/me/tori/wraith/bus/EventBus.java b/src/main/java/me/tori/wraith/bus/EventBus.java
index 3ef51c9..daf85b9 100644
--- a/src/main/java/me/tori/wraith/bus/EventBus.java
+++ b/src/main/java/me/tori/wraith/bus/EventBus.java
@@ -228,7 +228,9 @@ public boolean dispatch(Object event, Class> type) {
* {@code false} otherwise
* @throws NullPointerException if the given event is {@code null}
* @throws UnsupportedOperationException if this event bus is {@link #shutdown}
+ * @deprecated This method's functionality is now built into {@link #dispatch(Object)}.
*/
+ @Deprecated(since = "3.3.0", forRemoval = true)
@Override
public boolean dispatchTargeted(IClassTargetingEvent event) {
return dispatchTargeted(event, null);
@@ -246,7 +248,9 @@ public boolean dispatchTargeted(IClassTargetingEvent event) {
* {@code false} otherwise
* @throws NullPointerException if the given event is {@code null}
* @throws UnsupportedOperationException if this event bus is {@link #shutdown}
+ * @deprecated This method's functionality is now built into {@link #dispatch(Object, Class)}.
*/
+ @Deprecated(since = "3.3.0", forRemoval = true)
@Override
public boolean dispatchTargeted(IClassTargetingEvent event, Class> type) {
Objects.requireNonNull(event, "Cannot dispatch a null event to event bus " + id + "!");
diff --git a/src/main/java/me/tori/wraith/bus/TargetableEventBus.java b/src/main/java/me/tori/wraith/bus/TargetableEventBus.java
index f44517d..8c19411 100644
--- a/src/main/java/me/tori/wraith/bus/TargetableEventBus.java
+++ b/src/main/java/me/tori/wraith/bus/TargetableEventBus.java
@@ -27,23 +27,29 @@
/**
* @author 7orivorian
* @since 3.0.0
+ * @deprecated This event bus' functionality is now built into the standard event bus.
*/
+@Deprecated(since = "3.3.0", forRemoval = true)
public interface TargetableEventBus extends IEventBus {
/**
* @param event the {@linkplain IClassTargetingEvent} to dispatch
* @return {@code true} if the given event was {@linkplain IStatusEvent suppressed or terminated} by any listener,
- * {@code false otherwise}
+ * {@code false} otherwise
* @see EventBus#dispatchTargeted(IClassTargetingEvent)
+ * @deprecated This method's functionality is now built into {@link #dispatch(Object)}
*/
+ @Deprecated(since = "3.3.0", forRemoval = true)
boolean dispatchTargeted(IClassTargetingEvent event);
/**
* @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 IStatusEvent suppressed or terminated} by any listener,
- * {@code false otherwise}
+ * {@code false} otherwise
* @see EventBus#dispatchTargeted(IClassTargetingEvent, Class)
+ * @deprecated This method's functionality is now built into {@link #dispatch(Object)}
*/
+ @Deprecated(since = "3.3.0", forRemoval = true)
boolean dispatchTargeted(IClassTargetingEvent event, Class> type);
}
\ No newline at end of file
From 91024bd90cb246c15c0d5e570ae46b138fe0ebeb Mon Sep 17 00:00:00 2001
From: 7orivorian <7orivorian+github@gmail.com>
Date: Wed, 3 Jul 2024 00:44:44 -0400
Subject: [PATCH 05/17] Refactor IEventBus documentation
Signed-off-by: 7orivorian <7orivorian+github@gmail.com>
---
src/main/java/me/tori/wraith/bus/IEventBus.java | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/main/java/me/tori/wraith/bus/IEventBus.java b/src/main/java/me/tori/wraith/bus/IEventBus.java
index 6e905e4..bc31072 100644
--- a/src/main/java/me/tori/wraith/bus/IEventBus.java
+++ b/src/main/java/me/tori/wraith/bus/IEventBus.java
@@ -65,7 +65,7 @@ public interface IEventBus {
/**
* @param event the event to be dispatched
* @return {@code true} if the given event is {@linkplain IStatusEvent suppressed or terminated} by any listener,
- * {@code false} otherwise
+ * {@code false} otherwise.
*/
boolean dispatch(Object event);
@@ -73,17 +73,17 @@ public interface 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 IStatusEvent suppressed or terminated} by any listener,
- * {@code false} otherwise
+ * {@code false} otherwise.
*/
boolean dispatch(Object event, Class> type);
/**
- * Shuts down this event bus, preventing future events from being dispatched
+ * Shuts down this event bus, preventing future events from being dispatched.
*/
void shutdown();
/**
- * @return {@code true} if this event bus is shut down, {@code false} otherwise
+ * @return {@code true} if this event bus is shut down, {@code false} otherwise.
*/
boolean isShutdown();
}
\ No newline at end of file
From bb98ac9cdac2cd682f13a9fbc263458993144649 Mon Sep 17 00:00:00 2001
From: 7orivorian <7orivorian+github@gmail.com>
Date: Wed, 3 Jul 2024 00:45:49 -0400
Subject: [PATCH 06/17] Impl new utility methods in EventBus#dispatch,
EventBus#dispatchInverted, & EventBus#dispatchTargeted
Signed-off-by: 7orivorian <7orivorian+github@gmail.com>
---
.../java/me/tori/wraith/bus/EventBus.java | 24 +++----------------
1 file changed, 3 insertions(+), 21 deletions(-)
diff --git a/src/main/java/me/tori/wraith/bus/EventBus.java b/src/main/java/me/tori/wraith/bus/EventBus.java
index daf85b9..4bab6d7 100644
--- a/src/main/java/me/tori/wraith/bus/EventBus.java
+++ b/src/main/java/me/tori/wraith/bus/EventBus.java
@@ -209,7 +209,7 @@ public boolean dispatch(Object event, Class> type) {
dispatchToEachListener(
event,
this.listeners.get(event.getClass()),
- listener -> (type == null) || (listener.getType() == null) || (listener.getType() == type),
+ listener -> listener.isAcceptableType(type) && IClassTargetingEvent.isListenerTargetedByEvent(listener, event),
false
);
@@ -253,25 +253,7 @@ public boolean dispatchTargeted(IClassTargetingEvent event) {
@Deprecated(since = "3.3.0", forRemoval = true)
@Override
public boolean dispatchTargeted(IClassTargetingEvent event, Class> type) {
- 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);
-
- dispatchToEachListener(
- event,
- this.listeners.get(event.getClass()),
- listener -> ((type == null) || (listener.getType() == null) || (listener.getType() == type))
- && listener.getClass().equals(event.getTargetClass()),
- false
- );
-
- if (event instanceof IStatusEvent e) {
- return e.isSuppressed() || e.isTerminated();
- }
- }
- return false;
+ return dispatch(event, type);
}
/**
@@ -314,7 +296,7 @@ public boolean dispatchInverted(Object event, Class> type) {
dispatchToEachListener(
event,
this.listeners.get(event.getClass()),
- listener -> (type == null) || (listener.getType() == null) || (listener.getType() == type),
+ listener -> listener.isAcceptableType(type) && IClassTargetingEvent.isListenerTargetedByEvent(listener, event),
true
);
From cc50d4c4cf52f8dd4dd03bedd42801449217b2e9 Mon Sep 17 00:00:00 2001
From: 7orivorian <7orivorian+github@gmail.com>
Date: Wed, 3 Jul 2024 00:46:28 -0400
Subject: [PATCH 07/17] Minor documentation refactoring in EventBus
Signed-off-by: 7orivorian <7orivorian+github@gmail.com>
---
src/main/java/me/tori/wraith/bus/EventBus.java | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/main/java/me/tori/wraith/bus/EventBus.java b/src/main/java/me/tori/wraith/bus/EventBus.java
index 4bab6d7..eca3fab 100644
--- a/src/main/java/me/tori/wraith/bus/EventBus.java
+++ b/src/main/java/me/tori/wraith/bus/EventBus.java
@@ -351,7 +351,6 @@ public boolean isShutdown() {
/**
* @return the {@code id} of this event bus
- * @author 7orivorian
* @since 3.1.0
*/
public int getId() {
@@ -367,7 +366,7 @@ public int getId() {
* @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,
+ * @param invertPriority if {@code true}, listeners are processed in order of inverse priority; otherwise,
* they are processed in normal order
* @since 3.2.0
*/
@@ -410,7 +409,8 @@ private void dispatchToEachListener(Object event, List If the given object is an event bus, it is only considered equal if {@code this.id == that.id}.
+ *
+ * If the given object is an event bus, it is only considered equal if {@code this.id == that.id}.
*
* @param o the object to compare with
* @return {@code true} if the object is equal to this event bus, {@code false} otherwise
From 735e54afb229a7a224bae27cc2e89554659e152e Mon Sep 17 00:00:00 2001
From: 7orivorian <7orivorian+github@gmail.com>
Date: Wed, 3 Jul 2024 00:46:55 -0400
Subject: [PATCH 08/17] Refactored EventBus#dispatchToEachListener
Signed-off-by: 7orivorian <7orivorian+github@gmail.com>
---
.../java/me/tori/wraith/bus/EventBus.java | 47 ++++++++-----------
1 file changed, 19 insertions(+), 28 deletions(-)
diff --git a/src/main/java/me/tori/wraith/bus/EventBus.java b/src/main/java/me/tori/wraith/bus/EventBus.java
index eca3fab..483095b 100644
--- a/src/main/java/me/tori/wraith/bus/EventBus.java
+++ b/src/main/java/me/tori/wraith/bus/EventBus.java
@@ -32,6 +32,7 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.function.Predicate;
+import java.util.function.Supplier;
/**
* Default implementation of {@link IEventBus}, {@link TargetableEventBus}, and {@link InvertableEventBus}.
@@ -370,38 +371,28 @@ public int getId() {
* they are processed in normal order
* @since 3.2.0
*/
- @SuppressWarnings("DuplicatedCode")
private void dispatchToEachListener(Object event, List Last updated for version 3.1.0
*
- * @author 7orivorian
+ * @author 7orivorian
+ * @since 1.0.0
*/
-class ExampleEvent extends CancelableEvent implements IStagedEvent {
+class ExampleEvent extends StatusEvent implements IStagedEvent {
private String message;
private final EventStage stage;
diff --git a/examples/java/me/tori/example/expanded/ExampleListener.java b/examples/java/me/tori/example/expanded/ExampleListener.java
index c3de8fc..7d0ebaf 100644
--- a/examples/java/me/tori/example/expanded/ExampleListener.java
+++ b/examples/java/me/tori/example/expanded/ExampleListener.java
@@ -26,10 +26,9 @@
/**
* Example listener.
- * Last updated for version 3.1.0
*
- * @author 7orivorian
- * @since 1.0.0
+ * @author 7orivorian
+ * @since 1.0.0
*/
class ExampleListener extends EventListener Last updated for version 3.1.0
+ * Example program.
*
- * @author 7orivorian
+ * @author 7orivorian
+ * @since 1.0.0
*/
class ExampleMain {
@@ -44,7 +44,7 @@ public static void main(String[] args) {
EVENT_BUS.dispatch(event1);
- if (!event1.isCanceled()) {
+ if (!event1.isSuppressed()) {
System.out.println(event1.getMessage());
}
@@ -52,7 +52,7 @@ public static void main(String[] args) {
EVENT_BUS.dispatch(event2);
- if (!event2.isCanceled()) {
+ if (!event2.isSuppressed()) {
System.out.println(event2.getMessage());
}
}
diff --git a/examples/java/me/tori/example/expanded/ExampleSubscriber.java b/examples/java/me/tori/example/expanded/ExampleSubscriber.java
index a8dae62..f3cf156 100644
--- a/examples/java/me/tori/example/expanded/ExampleSubscriber.java
+++ b/examples/java/me/tori/example/expanded/ExampleSubscriber.java
@@ -27,10 +27,9 @@
/**
* Example subscriber.
- * Last updated for version 3.1.0
*
- * @author 7orivorian
- * @since 1.0.0
+ * @author 7orivorian
+ * @since 1.0.0
*/
class ExampleSubscriber extends Subscriber {
diff --git a/examples/java/me/tori/example/simple/SimpleExample.java b/examples/java/me/tori/example/simple/SimpleExample.java
index b346f28..3d6fdfa 100644
--- a/examples/java/me/tori/example/simple/SimpleExample.java
+++ b/examples/java/me/tori/example/simple/SimpleExample.java
@@ -22,16 +22,14 @@
package me.tori.example.simple;
import me.tori.wraith.bus.EventBus;
-import me.tori.wraith.event.cancelable.CancelableEvent;
+import me.tori.wraith.event.status.StatusEvent;
import me.tori.wraith.listener.LambdaEventListener;
import me.tori.wraith.subscriber.Subscriber;
/**
- * One-class example
- *
- * Last updated for version 3.1.0
+ * One-class example.
*
- * @author 7orivorian
+ * @author 7orivorian
*/
class SimpleExample {
@@ -45,38 +43,23 @@ public static void main(String[] args) {
// Subscribe to the event bus
bus.subscribe(subscriber);
- SimpleEvent event;
-
// Create a simple event
- // This event will be canceled, see the lambda in SimpleSubscriber to know why ;P
- event = new SimpleEvent("Pie is gross!");
-
- if (!bus.dispatch(event)) {
- // Only log the message if our event isn't canceled
- System.out.println(event.getMessage());
- }
+ SimpleEvent event = new SimpleEvent("Pie is delicious <3");
- event = new SimpleEvent("Pie is delicious <3");
- if (!bus.dispatch(event)) {
- System.out.println(event.getMessage());
- }
+ // Dispatch our event
+ bus.dispatch(event);
}
private static final class SimpleSubscriber extends Subscriber {
public SimpleSubscriber() {
registerListener(
- new LambdaEventListener<>(SimpleEvent.class, event -> {
- if (event.getMessage().contains("gross")) {
- // Pie is not gross, so we cancel this event, preventing it from being written to the console
- event.cancel();
- }
- })
+ new LambdaEventListener<>(SimpleEvent.class, event -> System.out.println(event.getMessage()))
);
}
}
- private static final class SimpleEvent extends CancelableEvent {
+ private static final class SimpleEvent extends StatusEvent {
private final String message;
From 4a0854418a2ec3876e9e6175b887362d8e5fff53 Mon Sep 17 00:00:00 2001
From: 7orivorian <7orivorian+github@gmail.com>
Date: Wed, 3 Jul 2024 00:59:24 -0400
Subject: [PATCH 10/17] Remove deprecated classes CancelableEvent.java &
ICancelableEvent.java
Signed-off-by: 7orivorian <7orivorian+github@gmail.com>
---
.../event/cancelable/CancelableEvent.java | 44 ---------------
.../event/cancelable/ICancelableEvent.java | 56 -------------------
.../wraith/persistency/PersistencyTest.java | 8 +--
.../targetedevent/TargetedEventTest.java | 10 ++--
4 files changed, 9 insertions(+), 109 deletions(-)
delete mode 100644 src/main/java/me/tori/wraith/event/cancelable/CancelableEvent.java
delete mode 100644 src/main/java/me/tori/wraith/event/cancelable/ICancelableEvent.java
diff --git a/src/main/java/me/tori/wraith/event/cancelable/CancelableEvent.java b/src/main/java/me/tori/wraith/event/cancelable/CancelableEvent.java
deleted file mode 100644
index ae3f539..0000000
--- a/src/main/java/me/tori/wraith/event/cancelable/CancelableEvent.java
+++ /dev/null
@@ -1,44 +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.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.
- *
- * @author 7orivorian
- * @see ICancelableEvent
- * @since 1.0.0
- */
-@Deprecated(forRemoval = true, since = "3.2.0")
-public class CancelableEvent extends StatusEvent implements ICancelableEvent {
-
- @Override
- public String toString() {
- return "Cancelable{" +
- "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
deleted file mode 100644
index 13b14ea..0000000
--- a/src/main/java/me/tori/wraith/event/cancelable/ICancelableEvent.java
+++ /dev/null
@@ -1,56 +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.event.cancelable;
-
-import me.tori.wraith.event.status.IStatusEvent;
-
-/**
- * @author 7orivorian
- * @see CancelableEvent
- * @since 1.0.0
- * @deprecated Use {@link IStatusEvent} instead.
- */
-@Deprecated(forRemoval = true, since = "3.2.0")
-public interface ICancelableEvent extends IStatusEvent {
-
- /**
- * @return {@code true} if this event is canceled, {@code false} otherwise
- * @see #isSuppressed()
- */
- default boolean isCanceled() {
- return isSuppressed();
- }
-
- /**
- * @see #setSuppressed(boolean)
- */
- default void setCanceled(boolean canceled) {
- setSuppressed(canceled);
- }
-
- /**
- * @see #suppress()
- */
- default void cancel() {
- suppress();
- }
-}
\ 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
index 1fd050e..56bec70 100644
--- a/src/main/test/me/tori/wraith/persistency/PersistencyTest.java
+++ b/src/main/test/me/tori/wraith/persistency/PersistencyTest.java
@@ -22,7 +22,7 @@
package me.tori.wraith.persistency;
import me.tori.wraith.bus.EventBus;
-import me.tori.wraith.event.cancelable.CancelableEvent;
+import me.tori.wraith.event.status.StatusEvent;
import me.tori.wraith.listener.EventListener;
import me.tori.wraith.subscriber.Subscriber;
import org.junit.jupiter.api.Assertions;
@@ -62,7 +62,7 @@ public void testIndefiniteEvent() {
}
}
- public static class MyListener extends EventListener The delay value determines the number of event dispatches that should occur before the task is executed.
* The delay decrements with each event dispatch, and once it becomes less than or equal to 0, the task is executed.
*
- * @author 7orivorian
+ * @author 7orivorian
* @see TaskExecutor
- * @since 3.0.0
+ * @since 3.0.0
*/
public abstract class ScheduledTask implements Runnable {
From 319edf07b3c0d29dcde4eae24233eafe100c7a6a Mon Sep 17 00:00:00 2001
From: 7orivorian <7orivorian+github@gmail.com>
Date: Wed, 3 Jul 2024 01:30:11 -0400
Subject: [PATCH 14/17] Deprecate InvertableEventBus
Signed-off-by: 7orivorian <7orivorian+github@gmail.com>
---
.../java/me/tori/wraith/bus/EventBus.java | 49 ++++++++++++++-----
.../java/me/tori/wraith/bus/IEventBus.java | 23 +++++++++
.../tori/wraith/bus/InvertableEventBus.java | 10 +++-
3 files changed, 69 insertions(+), 13 deletions(-)
diff --git a/src/main/java/me/tori/wraith/bus/EventBus.java b/src/main/java/me/tori/wraith/bus/EventBus.java
index 483095b..7879c69 100644
--- a/src/main/java/me/tori/wraith/bus/EventBus.java
+++ b/src/main/java/me/tori/wraith/bus/EventBus.java
@@ -173,23 +173,45 @@ public void unregister(Listener> listener) {
}
/**
- * Dispatches an event to listeners.
+ * Convenience method to dispatch an event with no {@linkplain Listener#getType() listener type} restriction, and
+ * normal processing priority.
*
- * @param event the event to be dispatched
- * @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}
+ * @see #dispatch(Object, Class, boolean)
+ * @since 3.3.0
*/
@Override
public boolean dispatch(Object event) {
- return dispatch(event, null);
+ return dispatch(event, null, false);
}
/**
- * Dispatches an event to listeners.
+ * Convenience method to dispatch an event with an optional {@linkplain Listener#getType() listener type} restriction, and
+ * normal processing priority.
*
- * The {@code type} parameter serves as a filtering mechanism for listeners, enabling you to selectively invoke
+ * @see #dispatch(Object, Class, boolean)
+ * @since 3.3.0
+ */
+ @Override
+ public boolean dispatch(Object event, Class> type) {
+ return dispatch(event, type, false);
+ }
+
+ /**
+ * Convenience method to dispatch an event with no {@linkplain Listener#getType() listener type} restriction, and
+ * optional inverted processing priority.
+ *
+ * @see #dispatch(Object, Class, boolean)
+ * @since 3.3.0
+ */
+ @Override
+ public boolean dispatch(Object event, boolean invertPriority) {
+ return dispatch(event, null, invertPriority);
+ }
+
+ /**
+ * Dispatches the given event to all valid registered 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
@@ -198,9 +220,10 @@ public boolean dispatch(Object event) {
* {@code false} otherwise
* @throws NullPointerException if the given event is {@code null}
* @throws UnsupportedOperationException if this event bus is {@link #shutdown}
+ * @since 3.3.0
*/
@Override
- public boolean dispatch(Object event, Class> type) {
+ public boolean dispatch(Object event, Class> type, boolean invertPriority) {
Objects.requireNonNull(event, "Cannot dispatch a null event to event bus " + id + "!");
if (isShutdown()) {
throw new UnsupportedOperationException("Dispatcher " + id + " is shutdown!");
@@ -211,7 +234,7 @@ public boolean dispatch(Object event, Class> type) {
event,
this.listeners.get(event.getClass()),
listener -> listener.isAcceptableType(type) && IClassTargetingEvent.isListenerTargetedByEvent(listener, event),
- false
+ invertPriority
);
if (event instanceof IStatusEvent e) {
@@ -266,7 +289,9 @@ public boolean dispatchTargeted(IClassTargetingEvent event, Class> type) {
* {@code false} otherwise
* @throws NullPointerException if the given event is {@code null}
* @throws UnsupportedOperationException if this event bus is {@link #shutdown}
+ * @deprecated This method's functionality is now built into {@link #dispatch(Object)}.
*/
+ @Deprecated(since = "3.3.0", forRemoval = true)
@Override
public boolean dispatchInverted(Object event) {
return dispatchInverted(event, null);
@@ -285,7 +310,9 @@ public boolean dispatchInverted(Object event) {
* {@code false} otherwise
* @throws NullPointerException if the given event is {@code null}
* @throws UnsupportedOperationException if this event bus is {@link #shutdown}
+ * @deprecated This method's functionality is now built into {@link #dispatch(Object)}.
*/
+ @Deprecated(since = "3.3.0", forRemoval = true)
@Override
public boolean dispatchInverted(Object event, Class> type) {
Objects.requireNonNull(event, "Cannot dispatch a null event to event bus " + id + "!");
diff --git a/src/main/java/me/tori/wraith/bus/IEventBus.java b/src/main/java/me/tori/wraith/bus/IEventBus.java
index 6a033cc..a2167af 100644
--- a/src/main/java/me/tori/wraith/bus/IEventBus.java
+++ b/src/main/java/me/tori/wraith/bus/IEventBus.java
@@ -89,6 +89,29 @@ public interface IEventBus {
*/
boolean dispatch(Object event, Class> type);
+ /**
+ * Dispatches the specified event to all registered listeners, with the option to invert the processing priority.
+ *
+ * @param event the event to be dispatched
+ * @param invertPriority if {@code true}, listeners are processed in order of inverse priority; otherwise,
+ * they are processed in normal order
+ * @return {@code true} if the given event is {@linkplain IStatusEvent suppressed or terminated} by any listener,
+ * {@code false} otherwise.
+ */
+ boolean dispatch(Object event, boolean invertPriority);
+
+ /**
+ * Dispatches the specified event to all registered listeners of the specified type, with the option to invert the processing priority.
+ *
+ * @param event the event to be dispatched
+ * @param type the type of listener to invoke (can be {@code null})
+ * @param invertPriority if {@code true}, listeners are processed in order of inverse priority; otherwise,
+ * they are processed in normal order
+ * @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, boolean invertPriority);
+
/**
* Shuts down this event bus, preventing future events from being dispatched.
*/
diff --git a/src/main/java/me/tori/wraith/bus/InvertableEventBus.java b/src/main/java/me/tori/wraith/bus/InvertableEventBus.java
index b1e51a2..a49ecbc 100644
--- a/src/main/java/me/tori/wraith/bus/InvertableEventBus.java
+++ b/src/main/java/me/tori/wraith/bus/InvertableEventBus.java
@@ -24,9 +24,11 @@
import me.tori.wraith.event.status.IStatusEvent;
/**
- * @author 7orivorian
- * @since 3.0.0
+ * @author 7orivorian
+ * @since 3.0.0
+ * @deprecated This event bus' functionality is now built into the {@linkplain IEventBus standard event bus}.
*/
+@Deprecated(since = "3.3.0", forRemoval = true)
public interface InvertableEventBus extends IEventBus {
/**
@@ -34,7 +36,9 @@ public interface InvertableEventBus extends IEventBus {
* @return {@code true} if the given event is {@linkplain IStatusEvent suppressed or terminated} by any listener,
* {@code false} otherwise
* @see EventBus#dispatchInverted(Object)
+ * @deprecated This method's functionality is now handled by {@link #dispatch(Object, boolean)}.
*/
+ @Deprecated(since = "3.3.0", forRemoval = true)
boolean dispatchInverted(Object event);
/**
@@ -43,6 +47,8 @@ public interface InvertableEventBus extends IEventBus {
* @return {@code true} if the given event is {@linkplain IStatusEvent suppressed or terminated} by any listener,
* {@code false} otherwise
* @see EventBus#dispatchInverted(Object, Class)
+ * @deprecated This method's functionality is now handled by {@link #dispatch(Object, Class, boolean)}.
*/
+ @Deprecated(since = "3.3.0", forRemoval = true)
boolean dispatchInverted(Object event, Class> type);
}
\ No newline at end of file
From 6c4cfb23d60be1241f17f96f966276d8c2678021 Mon Sep 17 00:00:00 2001
From: 7orivorian <7orivorian+github@gmail.com>
Date: Wed, 3 Jul 2024 01:33:43 -0400
Subject: [PATCH 15/17] Update README.md
Signed-off-by: 7orivorian <7orivorian+github@gmail.com>
---
README.md | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/README.md b/README.md
index fce1a70..83e33ab 100644
--- a/README.md
+++ b/README.md
@@ -31,7 +31,7 @@ Lightweight Java event library created and maintained by [7orivorian](https://gi
Details...
-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:
+To dispatch an event, call one of the `dispatch` methods defined in `EventBus`, passing your event as a parameter:
```java
import me.tori.wraith.event.staged.EventStage;
From 4724d619bb7fe8b3e16c58af8a6a7e2e17657a20 Mon Sep 17 00:00:00 2001
From: 7orivorian <7orivorian+github@gmail.com>
Date: Wed, 3 Jul 2024 01:34:54 -0400
Subject: [PATCH 16/17] Bump version from 3.2.2 -> 3.3.0
Signed-off-by: 7orivorian <7orivorian+github@gmail.com>
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 3e33b59..c829fcb 100644
--- a/pom.xml
+++ b/pom.xml
@@ -10,7 +10,7 @@