mirror of
https://github.com/PaperMC/Velocity.git
synced 2026-02-17 14:37:43 +01:00
Fix the automatic registration of main plugin event listeners. (#471)
This commit is contained in:
@@ -330,7 +330,7 @@ public class VelocityServer implements ProxyServer, ForwardingAudience {
|
|||||||
Optional<?> instance = plugin.instance();
|
Optional<?> instance = plugin.instance();
|
||||||
if (instance.isPresent()) {
|
if (instance.isPresent()) {
|
||||||
try {
|
try {
|
||||||
eventManager.register(instance.get(), instance.get());
|
eventManager.registerInternally(plugin, instance.get());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("Unable to register plugin listener for {}",
|
logger.error("Unable to register plugin listener for {}",
|
||||||
plugin.description().name().orElse(plugin.description().id()), e);
|
plugin.description().name().orElse(plugin.description().id()), e);
|
||||||
|
|||||||
@@ -319,7 +319,23 @@ public class VelocityEventManager implements EventManager {
|
|||||||
if (plugin == listener) {
|
if (plugin == listener) {
|
||||||
throw new IllegalArgumentException("The plugin main instance is automatically registered.");
|
throw new IllegalArgumentException("The plugin main instance is automatically registered.");
|
||||||
}
|
}
|
||||||
|
registerInternally(pluginContainer, listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public <E> void register(final Object plugin, final Class<E> eventClass,
|
||||||
|
final short order, final EventHandler<E> handler) {
|
||||||
|
final PluginContainer pluginContainer = ensurePlugin(plugin);
|
||||||
|
requireNonNull(eventClass, "eventClass");
|
||||||
|
requireNonNull(handler, "handler");
|
||||||
|
|
||||||
|
final HandlerRegistration registration = new HandlerRegistration(pluginContainer, order,
|
||||||
|
eventClass, handler, (EventHandler<Object>) handler, AsyncType.SOMETIMES);
|
||||||
|
register(Collections.singletonList(registration));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void registerInternally(final PluginContainer pluginContainer, final Object listener) {
|
||||||
final Class<?> targetClass = listener.getClass();
|
final Class<?> targetClass = listener.getClass();
|
||||||
final Map<String, MethodHandlerInfo> collected = new HashMap<>();
|
final Map<String, MethodHandlerInfo> collected = new HashMap<>();
|
||||||
collectMethods(targetClass, collected);
|
collectMethods(targetClass, collected);
|
||||||
@@ -342,19 +358,6 @@ public class VelocityEventManager implements EventManager {
|
|||||||
register(registrations);
|
register(registrations);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public <E> void register(final Object plugin, final Class<E> eventClass,
|
|
||||||
final short order, final EventHandler<E> handler) {
|
|
||||||
final PluginContainer pluginContainer = ensurePlugin(plugin);
|
|
||||||
requireNonNull(eventClass, "eventClass");
|
|
||||||
requireNonNull(handler, "handler");
|
|
||||||
|
|
||||||
final HandlerRegistration registration = new HandlerRegistration(pluginContainer, order,
|
|
||||||
eventClass, handler, (EventHandler<Object>) handler, AsyncType.SOMETIMES);
|
|
||||||
register(Collections.singletonList(registration));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void unregisterListeners(final Object plugin) {
|
public void unregisterListeners(final Object plugin) {
|
||||||
final PluginContainer pluginContainer = ensurePlugin(plugin);
|
final PluginContainer pluginContainer = ensurePlugin(plugin);
|
||||||
|
|||||||
Reference in New Issue
Block a user