Register event handler dynamically

Discussion in 'BungeeCord Plugin Development' started by MrDienns, Mar 22, 2020.

  1. (Note this is a Bungeecord question)

    I'm trying to build a plugin which dynamically listens for all events. It scans the classes with ClassGraph and registers handlers dynamically. This all works as expected on Spigot, now I need to do the same on Bungee. Was wondering if anyone knows how to actually do this.

    So, what I have is a class that extends Event. Now I need to create a listener for this, dynamically, programmatically. In Spigot I could do it like so;

    Code (Java):
         * Reads all of the current stored Spigot & plugin events and registers an event handler for all of them.

        private void registerAllEvents() {
            PluginManager pm = this.getServer().getPluginManager();
            GlobalEventListener globalListener = new GlobalEventListener();
            for (Class<?> clazz : this.spigotEvents) {
                this.registerEventHandler((Class<? extends Event>) clazz, pm, globalListener, globalListener::handleEvent);
    Is there any way to achieve the same in Bungee? I looked through the source a bit, but what I need seems mostly hidden behind private functions.
  2. SteelPhoenix


    BungeeCord does not support this, but it should be possible to inject listeners using reflection to make this work.