diff --git a/api/src/main/java/com/velocitypowered/api/event/EventManager.java b/api/src/main/java/com/velocitypowered/api/event/EventManager.java index 63cae6f32..2261e2220 100644 --- a/api/src/main/java/com/velocitypowered/api/event/EventManager.java +++ b/api/src/main/java/com/velocitypowered/api/event/EventManager.java @@ -46,7 +46,7 @@ public interface EventManager { * @param handler the handler to register * @param the event type to handle */ - void register(Object plugin, Class eventClass, PostOrder postOrder, + void register(Object plugin, Class eventClass, short postOrder, EventHandler handler); /** diff --git a/api/src/main/java/com/velocitypowered/api/event/PostOrder.java b/api/src/main/java/com/velocitypowered/api/event/PostOrder.java index dde8a4379..559899068 100644 --- a/api/src/main/java/com/velocitypowered/api/event/PostOrder.java +++ b/api/src/main/java/com/velocitypowered/api/event/PostOrder.java @@ -10,8 +10,12 @@ package com.velocitypowered.api.event; /** * Represents the order an event will be posted to a listener method, relative to other listeners. */ -public enum PostOrder { +public class PostOrder { - FIRST, EARLY, NORMAL, LATE, LAST + public static final short FIRST = -32768; + public static final short EARLY = -16384; + public static final short NORMAL = 0; + public static final short LATE = 16834; + public static final short LAST = 32767; } diff --git a/api/src/main/java/com/velocitypowered/api/event/Subscribe.java b/api/src/main/java/com/velocitypowered/api/event/Subscribe.java index 9cfd57ff9..7e81b2230 100644 --- a/api/src/main/java/com/velocitypowered/api/event/Subscribe.java +++ b/api/src/main/java/com/velocitypowered/api/event/Subscribe.java @@ -24,7 +24,7 @@ public @interface Subscribe { * * @return the order */ - PostOrder order() default PostOrder.NORMAL; + short order() default PostOrder.NORMAL; /** * Whether the handler must be called asynchronously. diff --git a/proxy/src/main/java/com/velocitypowered/proxy/event/VelocityEventManager.java b/proxy/src/main/java/com/velocitypowered/proxy/event/VelocityEventManager.java index 31f86dfff..62f9681eb 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/event/VelocityEventManager.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/event/VelocityEventManager.java @@ -29,7 +29,6 @@ import com.velocitypowered.api.event.Continuation; import com.velocitypowered.api.event.EventHandler; import com.velocitypowered.api.event.EventManager; import com.velocitypowered.api.event.EventTask; -import com.velocitypowered.api.event.PostOrder; import com.velocitypowered.api.event.Subscribe; import com.velocitypowered.api.plugin.PluginContainer; import com.velocitypowered.api.plugin.PluginManager; @@ -330,7 +329,7 @@ public class VelocityEventManager implements EventManager { if (subscribe.async()) { asyncType = AsyncType.ALWAYS; } - final short order = (short) subscribe.order().ordinal(); + final short order = subscribe.order(); final String errorsJoined = errors.isEmpty() ? null : String.join(",", errors); collected.put(key, new MethodHandlerInfo(method, asyncType, eventType, order, errorsJoined, continuationType)); @@ -370,13 +369,13 @@ public class VelocityEventManager implements EventManager { @Override @SuppressWarnings("unchecked") public void register(final Object plugin, final Class eventClass, - final PostOrder order, final EventHandler handler) { + final short order, final EventHandler handler) { final PluginContainer pluginContainer = pluginManager.ensurePluginContainer(plugin); requireNonNull(eventClass, "eventClass"); requireNonNull(handler, "handler"); final HandlerRegistration registration = new HandlerRegistration(pluginContainer, - (short) order.ordinal(), eventClass, handler, (EventHandler) handler, + order, eventClass, handler, (EventHandler) handler, AsyncType.SOMETIMES); register(Collections.singletonList(registration)); }