Velocity icon indicating copy to clipboard operation
Velocity copied to clipboard

EventManager#unregisterListeners unregisters the plugin main instance

Open hevav opened this issue 2 years ago • 2 comments

@Plugin(
    id = "testplugin"
)
public class TestPlugin {
  @Inject
  private ProxyServer server;

  @Subscribe
  public void onProxyInitialization(ProxyInitializeEvent event) {
    EventManager eventManager = this.server.getEventManager();
    eventManager.unregisterListeners(this);
    System.out.println("test123");
  }

  @Subscribe
  public void onProxyReload(ProxyReloadEvent event) {
    System.out.println("test321");
  }
}

Excepted behaviour:

  • It writes test123 on startup
  • It writes test321 after /velocity reload

Current behaviour:

  • It writes test123 on startup
  • It doesn't write test321 after /velocity reload

We can't register the main instance again (eventManager.registerListeners(this, this)) as the "The plugin main instance is automatically registered." error appears

hevav avatar Jun 30 '22 06:06 hevav

Not really sure I consider this a bug, I mean, maybe it should allow you to re-register the main class if it's been unregistered, and only then

electronicboy avatar Jun 30 '22 12:06 electronicboy

The main class cannot be excluded from the unregistration since the method explicitly indicates that it unregisters all the listeners of the plugin. But we could allow to register the main class as a listener as electronicboy said #1211

4drian3d avatar Jan 21 '24 03:01 4drian3d