EventPriority

Discussion in 'BungeeCord Plugin Development' started by David_Mayr, Mar 7, 2020.

  1. Currently i have this
    Code (Text):

    public class ListenerExecutor<T extends Event> implements Listener {

        private final Class<? extends Event> cls;
        private final EventListener listener;

        public ListenerExecutor(Class<? extends Event> cls, EventListener listener) {
            this.cls = cls;
            this.listener = listener;
        }

        @EventHandler
        public void onEvent(T event) {
            listener.on(event);
        }

        public Class<? extends Event> getCls() {
            return cls;
        }

        public EventListener getListener() { return this.listener; }
    }
     
    and i have a event manager to register events wighout creating new listener classes for them.
    The only problem i have is that i cant put a local varible to the EventHandler.
    Whats the best way to fix this? Or is there a better way to do this?

    Edit: btw to code above doesnt even work :(
     
    #1 David_Mayr, Mar 7, 2020
    Last edited: Mar 8, 2020
  2. Choco

    Moderator

    If you want to register events like this, you're not going to be able to use the EventHandler annotation. I advise working directly with an event's HandlerList (most events have static getters for these) and registering a RegisteredListener using HandlerList#register()

    Also, is this meant to be in Bungee Plugin Development?
     
  3. Yes it is. I want to do this with Bungeecord. I allready have it on spigot an its working there with eventpriority...
    But now i want to port it to bungee...

    On spigot i do it like this:
    Code (Text):

    ListenerExecutor executor = new ListenerExecutor(cls, listener);
    this.plugin.getServer().getPluginManager().registerEvent(cls, new Listener() {  }, eventPriority, executor, this.plugin);
     
    and
    Code (Text):

    public class ListenerExecutor implements EventExecutor
     
    But this isnt possible on Bungeecord... And i dont see Bungeecord Events that have a handlerlist
     
  4. You can't do that with bungeecord, unless someone makes a PR about it to bungeecord, there won't be such functionallity. Just do it normal way, there aren't as much events as bukkit has.