Solved How do I make one EventHander execute before another?

Discussion in 'Plugin Development' started by RastaLulz, Apr 24, 2014.

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

    RastaLulz

    Hello,

    I have two PlayerQuitEvent's. One is used globally, another is used on a specific game basis.

    On the game specific event, I want to check if the player was still playing before they quit, but I can't do that if the global one removes them from every team first.
    Code:java
    1. @EventHandler
    2. public void onPlayerQuit(PlayerQuitEvent event) {
    3.  
    4. Bukkit.getLogger().log(Level.INFO, "GameSpecificEvent");
    5.  
    6. Player player = event.getPlayer();
    7.  
    8. if(TeamUtil.isPlayerPlaying(player)) {
    9.  
    10. GameSpecific.getInstance().setPlayerDeath();
    11.  
    12. }
    13.  
    14. GameSpecific.getInstance().checkForWinner();
    15.  
    16. }
    As you can see below, the global one removes the player that quit from all teams.
    Code:java
    1. @EventHandler(priority = EventPriority.LOW)
    2. public void onPlayerQuit(PlayerQuitEvent event) {
    3.  
    4. Bukkit.getLogger().log(Level.INFO, "PlayerEvent");
    5.  
    6. TeamUtil.removePlayerFromAllTeams(player);
    7.  
    8. }
    As you can see above, I tried adding "(priority = EventPriority.LOW)" to the global event, in hopes that it'd have a lower priority than the game specific one, and would in result be executed after the game specific event. Sadly, that was not the case, and "PlayerEvent" was shown in my console before "GameSpecificEvent" was.
     
  2. Offline

    RainoBoy97

    Try using the HIGH priority, the priorities are "backwards". Or you could add the single line to the upper eventhandler.
     
    RastaLulz likes this.
  3. Offline

    1Rogue


    They aren't backwards, lowest priorities get called first because they have the least control over the outcome. (a higher priority will override the actions of a lower priority, etc).
     
    RastaLulz likes this.
  4. Offline

    RastaLulz

    Thanks for clearing that up guys. :cool:

    I assumed the higher priority would come first, because well, it's the higher priority.
     
  5. Offline

    RainoBoy97

    Theyre executed in this order, and by "backwards" I ment that people think HIGHEST is executed first (as it's the highest priority): Lowest ->Low -> Normal -> High -> Highest -> Monitor
     
Thread Status:
Not open for further replies.

Share This Page