[Question] CustomEvents - how to implement it correctly?

Discussion in 'Plugin Development' started by lycano, Jan 27, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    lycano

    Hi there,

    i recently stumbled over the new Wiki entry on bukkit about CustomEvents... As far as i got it you have to always include the following code

    Code:
        private static final HandlerList handlers = new HandlerList();
       
        public HandlerList getHandlers() {
            return handlers;
        }
       
        public static HandlerList getHandlerList() {
            return handlers;
        }
    in your custom event. Which leads me to a question: What is the background of this? Can someone please explain it in detail?

    Maybe answering the question "Why do i have to carry a static around in each CustomEvent"?

    Regards, Lycano
     
  2. I think that's where the event "knows" later in which listeners it appears.
    That's probably to save performance instead of searching all listeners all the time and to checkl which listener would require which events.
     
  3. I think a way more interesting question is: As we have to extend Event, why isn't that defined in Event anyway, giving us the ability to overwrite it if needed (which maybe never will be the case)?
     
  4. Offline

    nisovin

    The idea is there's a static list for each event type. You can't define that on the base class, or there'd only be one list for all events. It has to be defined on each event.
     
Thread Status:
Not open for further replies.

Share This Page