Solved Event questions

Discussion in 'Plugin Development' started by Zettelkasten, Aug 27, 2014.

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

    Zettelkasten

    Hello,

    I got some questions about events that I could not solve using Google / the source code of Bukkit - I hope you guys can help me :)

    The interface PluginManager has this method:
    Code:java
    1. public void registerEvent(Class<? extends Event> event, Listener listener, EventPriority priority, EventExecutor executor, Plugin plugin);

    What exactly will it do?
    Will it only register all events of specified type (event parameter)?
    Why do I need an event priority if the @EventHandler takes care of it?
    What is the peruse of the EventExecutor? I thought it would perform the actual event (for example the block break on BlockBreakEvent) and is called after all the event handler methods, but I don't think I'm right.

    Thanks for all answers! I would really appreciate it if someone could explain me the system or link me to a good documentation. Thanks :)
     
  2. Offline

    _LB

    You don't need to use that particular method, it's for internal use by the API. The executor does not perform the actual event, it calls the correct event handler.
     
  3. Offline

    Zettelkasten

    _LB Thanks for the answer :)

    How am I supposed to "execute" custom events? Do you just use @EventHandler(priority = EventPriority.MONITOR) or what? :eek:
     
  4. Offline

    _LB

    Zettelkasten I don't know what you mean, I was just answering two of your questions separately. Ignore the executor stuff.
     
  5. Offline

    Zettelkasten

    _LB If I have some custom event, for example "PlayerMaxHealthChangeEvent" with a method setNewMaxHealth(double).
    I want all handlers to be able to change the new max health amount, so I need to wait for them to "execute" the event (= setting the actual max health).
    Where is the place to "execute" the event?
     
  6. Offline

    _LB

    Zettelkasten
    Code:java
    1. MyCustomEvent mce = new MyCustomEvent();
    2. getPluginManager().callEvent(mce);
    3. double result = mce.getNewMaxHealth();
     
    Zettelkasten and BillyGalbreath like this.
  7. Offline

    BillyGalbreath

    As an extension to what _LB posted, you dont have to worry about "registering" your event. Any 3rd party plugin that wants to listen to your event can include your plugin as a dependency and use it as intended (the same way you include BukkitAPI as a dependency to use it's events), no extra effort on your part at all.

    Edit: Including a live example of exactly how i'm doing it (exactly as _LB posted, btw)

    https://bitbucket.org/BillyGalbreat...ommand/city/CmdCitySpawn.java?at=master#cl-53

    Lines 53-57 call the event and check if its been cancelled (to stop the action from happening as requested).

    Lines 62 & 63 you see me using the Location from the event instead of the command, just in case something somewhere changed it when the event fired.

    ;)
     
    Zettelkasten likes this.
  8. Offline

    Zettelkasten

Thread Status:
Not open for further replies.

Share This Page