mirror of
https://github.com/PaperMC/Velocity.git
synced 2026-02-20 07:57:42 +01:00
Add support for arbitrary event handler ordering.
This allows for 65,536 different orders, which should be more than enough for anyone.
This commit is contained in:
@@ -39,7 +39,7 @@ public interface EventManager {
|
|||||||
* @param handler the handler to register
|
* @param handler the handler to register
|
||||||
* @param <E> the event type to handle
|
* @param <E> the event type to handle
|
||||||
*/
|
*/
|
||||||
<E> void register(Object plugin, Class<E> eventClass, PostOrder postOrder,
|
<E> void register(Object plugin, Class<E> eventClass, short postOrder,
|
||||||
EventHandler<E> handler);
|
EventHandler<E> handler);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -4,7 +4,12 @@ package com.velocitypowered.api.event;
|
|||||||
* Represents the order an event will be posted to a listener method, relative to other listeners.
|
* Represents the order an event will be posted to a listener method, relative to other listeners.
|
||||||
*/
|
*/
|
||||||
public enum PostOrder {
|
public enum PostOrder {
|
||||||
|
;
|
||||||
|
|
||||||
FIRST, EARLY, NORMAL, LATE, LAST
|
public static final short FIRST = Short.MIN_VALUE;
|
||||||
|
public static final short EARLY = Short.MIN_VALUE >> 1;
|
||||||
|
public static final short NORMAL = 0;
|
||||||
|
public static final short LATE = Short.MAX_VALUE >> 1;
|
||||||
|
public static final short LAST = Short.MAX_VALUE;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,6 @@ public @interface Subscribe {
|
|||||||
*
|
*
|
||||||
* @return the order
|
* @return the order
|
||||||
*/
|
*/
|
||||||
PostOrder order() default PostOrder.NORMAL;
|
short order() default PostOrder.NORMAL;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -94,11 +94,10 @@ public class VelocityEventManager implements EventManager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("type.argument.type.incompatible")
|
@SuppressWarnings("type.argument.type.incompatible")
|
||||||
public <E> void register(Object plugin, Class<E> eventClass, PostOrder postOrder,
|
public <E> void register(Object plugin, Class<E> eventClass, short postOrder,
|
||||||
EventHandler<E> handler) {
|
EventHandler<E> handler) {
|
||||||
ensurePlugin(plugin);
|
ensurePlugin(plugin);
|
||||||
Preconditions.checkNotNull(eventClass, "eventClass");
|
Preconditions.checkNotNull(eventClass, "eventClass");
|
||||||
Preconditions.checkNotNull(postOrder, "postOrder");
|
|
||||||
Preconditions.checkNotNull(handler, "listener");
|
Preconditions.checkNotNull(handler, "listener");
|
||||||
|
|
||||||
registeredHandlersByPlugin.put(plugin, handler);
|
registeredHandlersByPlugin.put(plugin, handler);
|
||||||
@@ -201,7 +200,7 @@ public class VelocityEventManager implements EventManager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int postOrder(@NonNull Object listener, @NonNull Method method) {
|
public int postOrder(@NonNull Object listener, @NonNull Method method) {
|
||||||
return method.getAnnotation(Subscribe.class).order().ordinal();
|
return method.getAnnotation(Subscribe.class).order();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -213,11 +212,11 @@ public class VelocityEventManager implements EventManager {
|
|||||||
private static class KyoriToVelocityHandler<E> implements EventSubscriber<E> {
|
private static class KyoriToVelocityHandler<E> implements EventSubscriber<E> {
|
||||||
|
|
||||||
private final EventHandler<E> handler;
|
private final EventHandler<E> handler;
|
||||||
private final int postOrder;
|
private final short postOrder;
|
||||||
|
|
||||||
private KyoriToVelocityHandler(EventHandler<E> handler, PostOrder postOrder) {
|
private KyoriToVelocityHandler(EventHandler<E> handler, short postOrder) {
|
||||||
this.handler = handler;
|
this.handler = handler;
|
||||||
this.postOrder = postOrder.ordinal();
|
this.postOrder = postOrder;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user