From 65ca41cdb54a2cb3e2b65f083a25e80e22fbf3a0 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Sun, 2 Dec 2018 01:58:21 -0500 Subject: [PATCH] Warn when using Guava Subscribe annotation. Additionally, registration of listeners will not be fatal if an exception was thrown. --- .../java/com/velocitypowered/proxy/VelocityServer.java | 9 +++++++-- .../proxy/plugin/VelocityEventManager.java | 9 +++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java b/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java index 821e0e4ea..88494fb3d 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java @@ -225,11 +225,16 @@ public class VelocityServer implements ProxyServer { logger.error("Couldn't load plugins", e); } - // Register the plugin main classes so that we may proceed with firing the proxy initialize event + // Register the plugin main classes so that we can fire the proxy initialize event for (PluginContainer plugin : pluginManager.getPlugins()) { Optional instance = plugin.getInstance(); if (instance.isPresent()) { - eventManager.register(instance.get(), instance.get()); + try { + eventManager.register(instance.get(), instance.get()); + } catch (Exception e) { + logger.error("Unable to register plugin listener for {}", + plugin.getDescription().getName(), e); + } } } 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 812b7d0b9..cb2223e88 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/plugin/VelocityEventManager.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/plugin/VelocityEventManager.java @@ -70,6 +70,15 @@ public class VelocityEventManager implements EventManager { if (plugin == listener && registeredListenersByPlugin.containsEntry(plugin, plugin)) { throw new IllegalArgumentException("The plugin main instance is automatically registered."); } + + for (Method method : listener.getClass().getDeclaredMethods()) { + if (method.isAnnotationPresent(com.google.common.eventbus.Subscribe.class)) { + throw new IllegalArgumentException("Method " + listener.getClass().getName() + "#" + + method.getName() + " has a Guava @Subscribe annotation. Use the Velocity @Subscribe " + + "annotation instead."); + } + } + registeredListenersByPlugin.put(plugin, listener); methodAdapter.register(listener); }