From 43da3d45417c27446a0825b472cf96e5117d7437 Mon Sep 17 00:00:00 2001 From: Luck Date: Mon, 3 Dec 2018 23:53:06 +0000 Subject: [PATCH] Allow the same EventHandler to be registered with different PostOrders The #equals implementations in KyoriToVelocityHandler silently prevented this previously. --- .../proxy/plugin/VelocityEventManager.java | 31 +++++-------------- 1 file changed, 7 insertions(+), 24 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/plugin/VelocityEventManager.java b/proxy/src/main/java/com/velocitypowered/proxy/plugin/VelocityEventManager.java index cb2223e88..a9d9f8ce5 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/plugin/VelocityEventManager.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/plugin/VelocityEventManager.java @@ -123,14 +123,18 @@ public class VelocityEventManager implements EventManager { return eventFuture; } + private void unregisterHandler(EventHandler handler) { + bus.unregister(s -> s instanceof KyoriToVelocityHandler && + ((KyoriToVelocityHandler) s).handler == handler); + } + @Override public void unregisterListeners(Object plugin) { ensurePlugin(plugin); Collection listeners = registeredListenersByPlugin.removeAll(plugin); listeners.forEach(methodAdapter::unregister); Collection> handlers = registeredHandlersByPlugin.removeAll(plugin); - handlers - .forEach(handler -> bus.unregister(new KyoriToVelocityHandler<>(handler, PostOrder.LAST))); + handlers.forEach(this::unregisterHandler); } @Override @@ -146,7 +150,7 @@ public class VelocityEventManager implements EventManager { ensurePlugin(plugin); Preconditions.checkNotNull(handler, "listener"); registeredHandlersByPlugin.remove(plugin, handler); - bus.unregister(new KyoriToVelocityHandler<>(handler, PostOrder.LAST)); + unregisterHandler(handler); } public boolean shutdown() throws InterruptedException { @@ -196,26 +200,5 @@ public class VelocityEventManager implements EventManager { public int postOrder() { return postOrder; } - - public EventHandler getHandler() { - return handler; - } - - @Override - public boolean equals(@Nullable Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - KyoriToVelocityHandler that = (KyoriToVelocityHandler) o; - return Objects.equals(handler, that.handler); - } - - @Override - public int hashCode() { - return Objects.hash(handler); - } } }