Custom Events

Discussion in 'Bukkit Discussion' started by Afforess, Jan 13, 2011.

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

    Afforess

    To call a custom event with Bukkit's event handler, I assume that each unique event will need to have it's own object that extends the generic org.java.bukkit.event, right?

    I assume we also will need a CustomEventListener of some kind to pick up the event.

    Then to call that custom event, do we just use getServer().getPluginManager().callEvent(ourEventObject)?

    An example of a simple custom event would be awesome.
     
  2. Offline

    Raphfrk

    There is a CustomEventListener.java file.

    Code:
    package org.bukkit.event;
    
    public interface CustomEventListener {
        public void onCustomEvent(Event event);
    
    }
    
    

    It seems like all custom events will go through the same listener though, which is maybe not the most efficient.

    The register function takes:

    public void registerEvent(Event.Type type, Listener listener, Priority priority, Plugin plugin);

    so, it doesn't seem to allow registering just a specific names hook.

    (I could also insert a question about thread safety here :) )
     
  3. Offline

    Afforess

    I was able to get custom events working with some trial and error.
     
  4. Offline

    feverdream

    So if it is a custom event.. what triggers it?

    As least with OnPlayerChat() etc we have an idea of how and when to register it; and from reading the docs I'm under the possibly incorrect assumption that the custom event is never actualy triggered as the docs don't tell you what this event does.

    This leads to the idea that if this event is triggered by the game, that it need to be re-factored so the events are more clearly defined. Or just defined better so we know when to use it.
     
  5. Offline

    Raphfrk

    A custom event is triggered by a plugin.

    It allows a plugin to inform other plugins (or parts of the same plugin) something has happened.
     
  6. Offline

    feverdream

    So shouldn't it be renamed PLUGIN_CUSTOM_EVENT? With the docs updated to reflect this?
     
  7. Offline

    Afforess

    Custom Event is more generic, I don't see a problem with it. Anyway, custom events are named by an internal string parameter when creating the event object, so you can tell your custom event apart from others.
     
  8. Offline

    Raphfrk

    True, but you still get notified of all of them. They could use a HashMap to map the custom strings to a list of plugins registered on that event.
     
  9. Offline

    4am

    I'm trying to catch a custom event now, and I get nothing. I've even recompiled the plugin calling callEvent() to log right before it calls it, so I know execution is making it to callEvent() (the plugin is HeroChat). I can't seem to trap it on the backend though. Is there something special that needs to be done? I can post code if you like.

    SOLVED: Eclipse problems again, grr
     
Thread Status:
Not open for further replies.

Share This Page