From 21a79d814295bbc74ed5fdb7df579f51bdbf89a1 Mon Sep 17 00:00:00 2001 From: Luck Date: Fri, 17 May 2019 10:58:11 +0100 Subject: [PATCH 1/2] Correctly register Event handlers in the registeredHandlersByPlugin map --- .../com/velocitypowered/proxy/plugin/VelocityEventManager.java | 2 ++ 1 file changed, 2 insertions(+) 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 24c3c5b90..a89f589a9 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/plugin/VelocityEventManager.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/plugin/VelocityEventManager.java @@ -97,6 +97,8 @@ public class VelocityEventManager implements EventManager { Preconditions.checkNotNull(eventClass, "eventClass"); Preconditions.checkNotNull(postOrder, "postOrder"); Preconditions.checkNotNull(handler, "listener"); + + registeredHandlersByPlugin.put(plugin, handler); bus.register(eventClass, new KyoriToVelocityHandler<>(handler, postOrder)); } From 72c668c04891d0ce911b89d4f03cf14986303f2e Mon Sep 17 00:00:00 2001 From: Luck Date: Fri, 17 May 2019 10:59:35 +0100 Subject: [PATCH 2/2] Only unregister event handlers/listeners if the correct matching plugin is given Currently, unregister will succeed & unregister a handler/listener if any valid plugin is given, not necessarily the one the handler was registered with. --- .../proxy/plugin/VelocityEventManager.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 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 a89f589a9..2ef08dade 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/plugin/VelocityEventManager.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/plugin/VelocityEventManager.java @@ -161,16 +161,18 @@ public class VelocityEventManager implements EventManager { public void unregisterListener(Object plugin, Object listener) { ensurePlugin(plugin); Preconditions.checkNotNull(listener, "listener"); - registeredListenersByPlugin.remove(plugin, listener); - methodAdapter.unregister(listener); + if (registeredListenersByPlugin.remove(plugin, listener)) { + methodAdapter.unregister(listener); + } } @Override public void unregister(Object plugin, EventHandler handler) { ensurePlugin(plugin); Preconditions.checkNotNull(handler, "listener"); - registeredHandlersByPlugin.remove(plugin, handler); - unregisterHandler(handler); + if (registeredHandlersByPlugin.remove(plugin, handler)) { + unregisterHandler(handler); + } } public boolean shutdown() throws InterruptedException {