diff --git a/api/src/main/java/com/discordsrv/api/eventbus/EventPriority.java b/api/src/main/java/com/discordsrv/api/eventbus/EventPriorities.java
similarity index 58%
rename from api/src/main/java/com/discordsrv/api/eventbus/EventPriority.java
rename to api/src/main/java/com/discordsrv/api/eventbus/EventPriorities.java
index 440f6c16..cbea4d52 100644
--- a/api/src/main/java/com/discordsrv/api/eventbus/EventPriority.java
+++ b/api/src/main/java/com/discordsrv/api/eventbus/EventPriorities.java
@@ -23,47 +23,19 @@
package com.discordsrv.api.eventbus;
-import com.discordsrv.api.events.Processable;
-
/**
* A simple enum to dictate the order that event listeners will be executed, going from {@link #POST} to {@link #POST}.
*/
-public enum EventPriority {
+@SuppressWarnings("unused") // "API"
+public class EventPriorities {
- /**
- * This is the first in the priority order, this should be used to observe the event before any processing.
- */
- PRE,
-
- /**
- * This is the earliest in the processing. This should be used to cancel events.
- */
- EARLIEST,
-
- /**
- * This should be used to modify events.
- */
- EARLY,
-
- /**
- * The default priority, right in the middle of the priority order. Use this if you need to override
- * one of DiscordSRV's implementations for {@link Processable}s.
- */
- DEFAULT,
-
- /**
- * This is where DiscordSRV's integrations for other plugins will process {@link Processable}'s.
- */
- LATE,
-
- /**
- * This is where DiscordSRV's default implementations for {@link Processable}'s will run.
- */
- LAST,
-
- /**
- * This is the last in the priority order, this should be used to observe the event after all processing is complete.
- */
- POST
+ public static final byte PRE = Byte.MIN_VALUE;
+ public static final byte EARLIEST = (byte) -96;
+ public static final byte EARLY = (byte) -48;
+ public static final byte DEFAULT = (byte) 0;
+ public static final byte LATE = (byte) 48;
+ public static final byte LAST = (byte) 96;
+ public static final byte POST = Byte.MAX_VALUE;
+ private EventPriorities() {}
}
diff --git a/api/src/main/java/com/discordsrv/api/eventbus/Subscribe.java b/api/src/main/java/com/discordsrv/api/eventbus/Subscribe.java
index 54453561..5c7940f1 100644
--- a/api/src/main/java/com/discordsrv/api/eventbus/Subscribe.java
+++ b/api/src/main/java/com/discordsrv/api/eventbus/Subscribe.java
@@ -33,7 +33,7 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
- * Placed on a public non-abstract non-static method that has only 1 parameters,
+ * Placed on a public non-abstract non-static method that has only 1 parameter,
* being an event extending {@link Event} or {@link net.dv8tion.jda.api.events.GenericEvent}.
*
* You can register a listener through {@link EventBus#subscribe(Object)}, {@link DiscordSRVApi#eventBus()} to get the event bus.
@@ -52,7 +52,8 @@ public @interface Subscribe {
/**
* The priority for this event listener, this determines the order that event listeners receive events.
* @return the priority of this event listener
+ * @see EventPriorities
*/
- EventPriority priority() default EventPriority.DEFAULT;
+ byte priority() default 0;
}
diff --git a/api/src/main/java/com/discordsrv/api/events/channel/GameChannelLookupEvent.java b/api/src/main/java/com/discordsrv/api/events/channel/GameChannelLookupEvent.java
index a2a87247..fcb151da 100644
--- a/api/src/main/java/com/discordsrv/api/events/channel/GameChannelLookupEvent.java
+++ b/api/src/main/java/com/discordsrv/api/events/channel/GameChannelLookupEvent.java
@@ -24,7 +24,7 @@
package com.discordsrv.api.events.channel;
import com.discordsrv.api.channel.GameChannel;
-import com.discordsrv.api.eventbus.EventPriority;
+import com.discordsrv.api.eventbus.EventPriorities;
import com.discordsrv.api.events.Processable;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -32,7 +32,7 @@ import org.jetbrains.annotations.Nullable;
/**
* This event is used to lookup {@link GameChannel}s by their name (and optionally plugin name).
* This is also used to determine which plugin's channel should take priority when multiple plugins
- * define channels with the same name ({@link EventPriority}).
+ * define channels with the same name ({@link EventPriorities}).
*
* @see #isDefault()
*/
diff --git a/api/src/main/java/com/discordsrv/api/events/lifecycle/DiscordSRVShuttingDownEvent.java b/api/src/main/java/com/discordsrv/api/events/lifecycle/DiscordSRVShuttingDownEvent.java
index a9885e3b..df29da88 100644
--- a/api/src/main/java/com/discordsrv/api/events/lifecycle/DiscordSRVShuttingDownEvent.java
+++ b/api/src/main/java/com/discordsrv/api/events/lifecycle/DiscordSRVShuttingDownEvent.java
@@ -23,20 +23,20 @@
package com.discordsrv.api.events.lifecycle;
-import com.discordsrv.api.eventbus.EventPriority;
+import com.discordsrv.api.eventbus.EventPriorities;
import com.discordsrv.api.events.Event;
/**
* Indicates that DiscordSRV is shutting down.
*
* DiscordSRV's own systems will shut down at the following times:
- * {@link EventPriority#EARLY}
+ * {@link EventPriorities#EARLY}
* - DiscordSRV's own modules shutdown
*
- * {@link EventPriority#LATE}
+ * {@link EventPriorities#LATE}
* - Discord connections are shutdown
*
- * {@link EventPriority#LAST}
+ * {@link EventPriorities#LAST}
* - DiscordSRV's scheduler is shutdown
*/
public class DiscordSRVShuttingDownEvent implements Event {
diff --git a/api/src/main/java/com/discordsrv/api/events/message/receive/game/AwardMessageReceiveEvent.java b/api/src/main/java/com/discordsrv/api/events/message/receive/game/AwardMessageReceiveEvent.java
index 7c31cbb3..4246d3fe 100644
--- a/api/src/main/java/com/discordsrv/api/events/message/receive/game/AwardMessageReceiveEvent.java
+++ b/api/src/main/java/com/discordsrv/api/events/message/receive/game/AwardMessageReceiveEvent.java
@@ -25,7 +25,7 @@ package com.discordsrv.api.events.message.receive.game;
import com.discordsrv.api.channel.GameChannel;
import com.discordsrv.api.component.MinecraftComponent;
-import com.discordsrv.api.eventbus.EventPriority;
+import com.discordsrv.api.eventbus.EventPriorities;
import com.discordsrv.api.events.PlayerEvent;
import com.discordsrv.api.player.DiscordSRVPlayer;
import org.jetbrains.annotations.NotNull;
@@ -33,7 +33,7 @@ import org.jetbrains.annotations.Nullable;
/**
* Indicates that an advancement or achievement message was received will be processed
- * at {@link EventPriority#DEFAULT} unless cancelled or processed by a 3rd party.
+ * at {@link EventPriorities#DEFAULT} unless cancelled or processed by a 3rd party.
*/
public class AwardMessageReceiveEvent extends AbstractGameMessageReceiveEvent implements PlayerEvent {
diff --git a/api/src/main/java/com/discordsrv/api/events/message/receive/game/DeathMessageReceiveEvent.java b/api/src/main/java/com/discordsrv/api/events/message/receive/game/DeathMessageReceiveEvent.java
index 1ed94a97..9e25e8cd 100644
--- a/api/src/main/java/com/discordsrv/api/events/message/receive/game/DeathMessageReceiveEvent.java
+++ b/api/src/main/java/com/discordsrv/api/events/message/receive/game/DeathMessageReceiveEvent.java
@@ -25,7 +25,7 @@ package com.discordsrv.api.events.message.receive.game;
import com.discordsrv.api.channel.GameChannel;
import com.discordsrv.api.component.MinecraftComponent;
-import com.discordsrv.api.eventbus.EventPriority;
+import com.discordsrv.api.eventbus.EventPriorities;
import com.discordsrv.api.events.PlayerEvent;
import com.discordsrv.api.player.DiscordSRVPlayer;
import org.jetbrains.annotations.NotNull;
@@ -33,7 +33,7 @@ import org.jetbrains.annotations.Nullable;
/**
* Indicates that a death message was received and will be processed
- * at {@link EventPriority#DEFAULT} unless cancelled or processed by a 3rd party.
+ * at {@link EventPriorities#DEFAULT} unless cancelled or processed by a 3rd party.
*/
public class DeathMessageReceiveEvent extends AbstractGameMessageReceiveEvent implements PlayerEvent {
diff --git a/api/src/main/java/com/discordsrv/api/events/message/receive/game/GameChatMessageReceiveEvent.java b/api/src/main/java/com/discordsrv/api/events/message/receive/game/GameChatMessageReceiveEvent.java
index a385d839..34639a79 100644
--- a/api/src/main/java/com/discordsrv/api/events/message/receive/game/GameChatMessageReceiveEvent.java
+++ b/api/src/main/java/com/discordsrv/api/events/message/receive/game/GameChatMessageReceiveEvent.java
@@ -25,7 +25,7 @@ package com.discordsrv.api.events.message.receive.game;
import com.discordsrv.api.channel.GameChannel;
import com.discordsrv.api.component.MinecraftComponent;
-import com.discordsrv.api.eventbus.EventPriority;
+import com.discordsrv.api.eventbus.EventPriorities;
import com.discordsrv.api.events.PlayerEvent;
import com.discordsrv.api.player.DiscordSRVPlayer;
import org.jetbrains.annotations.NotNull;
@@ -33,7 +33,7 @@ import org.jetbrains.annotations.Nullable;
/**
* Indicates that a chat message was received and will be processed
- * at {@link EventPriority#DEFAULT} unless cancelled or processed by a 3rd party.
+ * at {@link EventPriorities#DEFAULT} unless cancelled or processed by a 3rd party.
*/
public class GameChatMessageReceiveEvent extends AbstractGameMessageReceiveEvent implements PlayerEvent {
diff --git a/api/src/main/java/com/discordsrv/api/events/message/receive/game/JoinMessageReceiveEvent.java b/api/src/main/java/com/discordsrv/api/events/message/receive/game/JoinMessageReceiveEvent.java
index b11421c4..b0ca8805 100644
--- a/api/src/main/java/com/discordsrv/api/events/message/receive/game/JoinMessageReceiveEvent.java
+++ b/api/src/main/java/com/discordsrv/api/events/message/receive/game/JoinMessageReceiveEvent.java
@@ -25,7 +25,7 @@ package com.discordsrv.api.events.message.receive.game;
import com.discordsrv.api.channel.GameChannel;
import com.discordsrv.api.component.MinecraftComponent;
-import com.discordsrv.api.eventbus.EventPriority;
+import com.discordsrv.api.eventbus.EventPriorities;
import com.discordsrv.api.events.PlayerEvent;
import com.discordsrv.api.player.DiscordSRVPlayer;
import org.jetbrains.annotations.NotNull;
@@ -33,7 +33,7 @@ import org.jetbrains.annotations.Nullable;
/**
* Indicates that a join message was received and will be processed
- * at {@link EventPriority#DEFAULT} unless cancelled or processed by a 3rd party.
+ * at {@link EventPriorities#DEFAULT} unless cancelled or processed by a 3rd party.
*/
public class JoinMessageReceiveEvent extends AbstractGameMessageReceiveEvent implements PlayerEvent {
diff --git a/api/src/main/java/com/discordsrv/api/events/message/receive/game/LeaveMessageReceiveEvent.java b/api/src/main/java/com/discordsrv/api/events/message/receive/game/LeaveMessageReceiveEvent.java
index 887cfa19..bb25d934 100644
--- a/api/src/main/java/com/discordsrv/api/events/message/receive/game/LeaveMessageReceiveEvent.java
+++ b/api/src/main/java/com/discordsrv/api/events/message/receive/game/LeaveMessageReceiveEvent.java
@@ -25,7 +25,7 @@ package com.discordsrv.api.events.message.receive.game;
import com.discordsrv.api.channel.GameChannel;
import com.discordsrv.api.component.MinecraftComponent;
-import com.discordsrv.api.eventbus.EventPriority;
+import com.discordsrv.api.eventbus.EventPriorities;
import com.discordsrv.api.events.PlayerEvent;
import com.discordsrv.api.player.DiscordSRVPlayer;
import org.jetbrains.annotations.NotNull;
@@ -33,7 +33,7 @@ import org.jetbrains.annotations.Nullable;
/**
* Indicates that a leave message was received and will be processed
- * at {@link EventPriority#DEFAULT} unless cancelled or processed by a 3rd party.
+ * at {@link EventPriorities#DEFAULT} unless cancelled or processed by a 3rd party.
*/
public class LeaveMessageReceiveEvent extends AbstractGameMessageReceiveEvent implements PlayerEvent {
diff --git a/api/src/main/java/com/discordsrv/api/events/message/receive/game/ServerSwitchMessageReceiveEvent.java b/api/src/main/java/com/discordsrv/api/events/message/receive/game/ServerSwitchMessageReceiveEvent.java
index 8c105198..fa2ae4c7 100644
--- a/api/src/main/java/com/discordsrv/api/events/message/receive/game/ServerSwitchMessageReceiveEvent.java
+++ b/api/src/main/java/com/discordsrv/api/events/message/receive/game/ServerSwitchMessageReceiveEvent.java
@@ -24,7 +24,7 @@
package com.discordsrv.api.events.message.receive.game;
import com.discordsrv.api.component.MinecraftComponent;
-import com.discordsrv.api.eventbus.EventPriority;
+import com.discordsrv.api.eventbus.EventPriorities;
import com.discordsrv.api.events.PlayerEvent;
import com.discordsrv.api.player.DiscordSRVPlayer;
import org.jetbrains.annotations.NotNull;
@@ -32,7 +32,7 @@ import org.jetbrains.annotations.Nullable;
/**
* Indicates that a server switch message was received and will be processed
- * at {@link EventPriority#DEFAULT} unless cancelled or processed by a 3rd party.
+ * at {@link EventPriorities#DEFAULT} unless cancelled or processed by a 3rd party.
*/
public class ServerSwitchMessageReceiveEvent extends AbstractGameMessageReceiveEvent implements PlayerEvent {
diff --git a/bukkit/src/main/java/com/discordsrv/bukkit/integration/EssentialsXIntegration.java b/bukkit/src/main/java/com/discordsrv/bukkit/integration/EssentialsXIntegration.java
index 479a542b..b9701352 100644
--- a/bukkit/src/main/java/com/discordsrv/bukkit/integration/EssentialsXIntegration.java
+++ b/bukkit/src/main/java/com/discordsrv/bukkit/integration/EssentialsXIntegration.java
@@ -20,7 +20,7 @@ package com.discordsrv.bukkit.integration;
import com.discordsrv.api.channel.GameChannel;
import com.discordsrv.api.component.MinecraftComponent;
-import com.discordsrv.api.eventbus.EventPriority;
+import com.discordsrv.api.eventbus.EventPriorities;
import com.discordsrv.api.eventbus.Subscribe;
import com.discordsrv.api.events.channel.GameChannelLookupEvent;
import com.discordsrv.api.events.message.receive.game.GameChatMessageReceiveEvent;
@@ -149,7 +149,7 @@ public class EssentialsXIntegration
));
}
- @Subscribe(priority = EventPriority.LAST)
+ @Subscribe(priority = EventPriorities.LAST)
public void onGameChannelLookup(GameChannelLookupEvent event) {
if (checkProcessor(event) || !discordSRV.server().getPluginManager().isPluginEnabled("EssentialsChat")) {
return;
diff --git a/bukkit/src/main/java/com/discordsrv/bukkit/integration/chat/GriefPreventionChatIntegration.java b/bukkit/src/main/java/com/discordsrv/bukkit/integration/chat/GriefPreventionChatIntegration.java
index ae8756d2..c79882a9 100644
--- a/bukkit/src/main/java/com/discordsrv/bukkit/integration/chat/GriefPreventionChatIntegration.java
+++ b/bukkit/src/main/java/com/discordsrv/bukkit/integration/chat/GriefPreventionChatIntegration.java
@@ -18,7 +18,7 @@
package com.discordsrv.bukkit.integration.chat;
-import com.discordsrv.api.eventbus.EventPriority;
+import com.discordsrv.api.eventbus.EventPriorities;
import com.discordsrv.api.eventbus.Subscribe;
import com.discordsrv.api.events.message.receive.game.GameChatMessageReceiveEvent;
import com.discordsrv.api.player.DiscordSRVPlayer;
@@ -50,7 +50,7 @@ public class GriefPreventionChatIntegration extends PluginIntegration im
HandlerList.unregisterAll(this);
}
- @Subscribe(priority = EventPriority.EARLY)
+ @Subscribe(priority = EventPriorities.EARLY)
public void onGameChatMessageReceive(GameChatMessageReceiveEvent event) {
Player player = discordSRV.server().getPlayer(event.getPlayer().uniqueId());
if (!player.hasMetadata("mcMMO: Player Data")) {
diff --git a/common/src/main/java/com/discordsrv/common/core/eventbus/EventBusImpl.java b/common/src/main/java/com/discordsrv/common/core/eventbus/EventBusImpl.java
index ff5612a7..e6e2749a 100644
--- a/common/src/main/java/com/discordsrv/common/core/eventbus/EventBusImpl.java
+++ b/common/src/main/java/com/discordsrv/common/core/eventbus/EventBusImpl.java
@@ -20,7 +20,6 @@ package com.discordsrv.common.core.eventbus;
import com.discordsrv.api.eventbus.EventBus;
import com.discordsrv.api.eventbus.EventListener;
-import com.discordsrv.api.eventbus.EventPriority;
import com.discordsrv.api.eventbus.Subscribe;
import com.discordsrv.api.eventbus.internal.EventStateHolder;
import com.discordsrv.api.events.Cancellable;
@@ -37,36 +36,40 @@ import net.dv8tion.jda.api.events.GenericEvent;
import org.apache.commons.lang3.tuple.Pair;
import org.jetbrains.annotations.NotNull;
-import java.lang.reflect.InvocationTargetException;
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
-import java.util.function.Function;
+import java.util.function.Predicate;
import java.util.stream.Collectors;
import static com.discordsrv.common.util.ExceptionUtil.minifyException;
public class EventBusImpl implements EventBus {
- private static final List, ThreadLocal>> STATES = Arrays.asList(
- Pair.of(event -> event instanceof Cancellable && ((Cancellable) event).isCancelled(), EventStateHolder.CANCELLED),
- Pair.of(event -> event instanceof Processable && ((Processable) event).isProcessed(), EventStateHolder.PROCESSED)
+ private static final List> STATES = Arrays.asList(
+ new State<>(Cancellable.class, Cancellable::isCancelled, EventStateHolder.CANCELLED),
+ new State<>(Processable.class, Processable::isProcessed, EventStateHolder.PROCESSED)
);
private final Map