Solved When to use EventPriority & how to use it effectively.

Discussion in 'Plugin Development' started by Sir_Cam, Mar 22, 2016.

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

    Sir_Cam

    I have noticed in various situations, when looking for particular means to put my thoughts into code, that some others are using the @EventHandler tag like so:
    Code:java
    1. @EventHandler(priority = EventPriority.HIGHEST)
    My question is, when is it most appropriate, or rather in some cases: essential, that i use EventPriority with my EventHandlers? A piece of code I have found that uses the EventPriority is cancellation of Fall Damage:
    Code:java
    1. @EventHandler(priority = EventPriority.HIGHEST) //Highest priority
    2. public void onEntityDamageEvent(final EntityDamageEvent e) {
    3. if (!(e.getEntity() instanceof Player)) {
    4. return; }
    5. if (e.getCause() == DamageCause.FALL) { e.setCancelled(true); } }
    In this example of code i am currently using in a KitsPvP Plugin, in it's context, is the EventPriority essential? And what, if any, differences would the server or the Event itself have if it was removed, or even it it was set to a lower priority? Is it something that i don't need to worry about unless the server it is for is going to contain a significant amount of players? As well as how do i know what i should set an events priority at (if i do in fact need them) for each event i want to have priority over others?

    Thanks! :p
     
  2. Offline

    Zombie_Striker

    @Sir_Cam
    There is a thread in the PluginDev stickies that discusses what EventPriority means. All it means is when will the event run? If the priority is set to "lowest", the event will run first. If it is set to "Monitor", it will be the last event to run. This is only good for when you have to cancel/ un-cancel events.
     
    Sir_Cam likes this.
  3. Offline

    Konato_K

    @Sir_Cam Just to make it a bit more clear from Zombie's explanation, let's say there are 3 plugins listening at PlayerDeathEvent, one on Low, High and Monitor

    First the plugin that is listening on Low will get the event and do it's stuff
    Then the one in high and at last the one in Monitor, so it just means the execution order, against other EventHandlers on the same event.

    I didn't see the thread on the stickies anymore, so here it is https://bukkit.org/threads/getting-your-priorities-straight-the-plugin-version.788/
     
    Sir_Cam likes this.
  4. Offline

    mcdorli

    There are people who think "My plugin is very very important, so it needs to happen first, because people need chickens for pets definitely", then wonder, why the events, wich got accepted by them gets cancelled or changed by other plugins.
     
  5. Offline

    Sir_Cam

    @Zombie_Striker Thank you for the help. They merely confused me as far as which would go before the others: I had thought they'd go in the opposite order, but now I see how that works.

    @Konato_K That thread was immensely helpful with understanding the EventPriority. And I hadn't saw it in stickies either, but thank you for the added clarification :D

    @mcdorli And oh, based off of importance as well, I can see that. Thank you for your input too!
     
Thread Status:
Not open for further replies.

Share This Page