From 72c668c04891d0ce911b89d4f03cf14986303f2e Mon Sep 17 00:00:00 2001 From: Luck Date: Fri, 17 May 2019 10:59:35 +0100 Subject: [PATCH] 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 {