Event priority

Discussion in 'Plugin Development' started by dcgamingentral, Dec 17, 2012.

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

    dcgamingentral

    Hi, I have been working on a DTC plugin and Faction and Essentials are overriding my Listener, Please help me work out what @EventHandler(priority = EventPriority.LOWEST to use.
    Code:
     @EventHandler(priority = EventPriority.LOWEST)
        public void onRespawn(PlayerRespawnEvent e) {
            if(plugin.gameActive == true) {
            Player p = (Player)e.getPlayer();
            if(plugin.pl.contains(p.getName())) {
                if(plugin.diamond.contains(p.getName())) {
                    String number = "diamond";
                    String world =  plugin.customConfig.getString("Warps" + "." +number+".world");
                    double x = plugin.customConfig.getDouble("Warps" + "." +number+".x");
                    double y = plugin.customConfig.getDouble("Warps" + "." +number+".y");
                    double z = plugin.customConfig.getDouble("Warps" + "." +number+".z");
                    String yaws = plugin.customConfig.getString("Warps" + "." +number+".yaw");
                    String pitchs = plugin.customConfig.getString("Warps" + "." +number+".pitch");
                    float yaw = Float.valueOf(yaws.trim()).floatValue();
                    float pitch = Float.valueOf(pitchs.trim()).floatValue();       
                    Location diamond = new Location(Bukkit.getWorld(world), x, y, z, yaw, pitch);
                    p.getPlayer().getInventory().addItem(new ItemStack(267, 1));
                    p.getPlayer().getInventory().addItem(new ItemStack(322, 2));
                    p.getPlayer().getInventory().addItem(new ItemStack(216, 1));
                    p.getPlayer().getInventory().addItem(new ItemStack(262, 10));
                    p.getPlayer().getInventory().setBoots(new ItemStack(313));
                    p.getPlayer().getInventory().setLeggings(new ItemStack(312));
                    p.getPlayer().getInventory().setChestplate(new ItemStack(311));
                    p.getPlayer().getInventory().setHelmet(new ItemStack(310));
                    p.teleport(diamond);
                } else if(plugin.iron.contains(p.getName())) {
                    String number = "iron";
                    String world =  plugin.customConfig.getString("Warps" + "." +number+".world");
                    double x = plugin.customConfig.getDouble("Warps" + "." +number+".x");
                    double y = plugin.customConfig.getDouble("Warps" + "." +number+".y");
                    double z = plugin.customConfig.getDouble("Warps" + "." +number+".z");
                    String yaws = plugin.customConfig.getString("Warps" + "." +number+".yaw");
                    String pitchs = plugin.customConfig.getString("Warps" + "." +number+".pitch");
                    float yaw = Float.valueOf(yaws.trim()).floatValue();
                    float pitch = Float.valueOf(pitchs.trim()).floatValue();       
                    Location iron = new Location(Bukkit.getWorld(world), x, y, z, yaw, pitch);
                    p.getPlayer().getInventory().addItem(new ItemStack(267, 1));
                    p.getPlayer().getInventory().addItem(new ItemStack(322, 2));
                    p.getPlayer().getInventory().setBoots(new ItemStack(309));
                    p.getPlayer().getInventory().setLeggings(new ItemStack(308));
                    p.getPlayer().getInventory().setChestplate(new ItemStack(307));
                    p.getPlayer().getInventory().setHelmet(new ItemStack(306));
                    p.teleport(iron);
                }
            }
            }
        }
    Please help me take top priority.

    Thanks in advance.
     
  2. Offline

    drtshock Retired Staff

    If you want to override everything else just do EventPriority.HIGHEST
     
  3. Offline

    tommycake50

    but that causes errors a lot of the time so do not use highest
    for instance a lot of the big plugins like to use highest.
    if two events use highest(very likely)
    it wont get passed to one of them the highest i ever go is high and the lowest low.
    but use normal to avoid errors.
     
  4. Offline

    dcgamingentral

    Okay, thank you, I will try normal and high.
     
  5. Offline

    drtshock Retired Staff

    :eek: Thanks for the info.

    I've never had issues or really used event priority, just read the wiki on them.
     
  6. Offline

    tommycake50

    tbh it doesnt matter what priority you use unless you NEED to have the final say in cancelling the event :/
     
  7. Offline

    fireblast709

    The fact that other plugins already use HIGHEST does not mean you can not use it. It solely depends on your plugin's needs
     
  8. Offline

    drtshock Retired Staff

    So I'm correct in never using them except when I had to cancel :)
     
  9. Offline

    fireblast709

    drtshock I basically always omit them (except for a few cases) ;D
     
    drtshock likes this.
  10. Offline

    dcgamingentral

    I tried High and Normal and it still either took them to their faction home or spawn, not my set points.
     
  11. Offline

    fireblast709

    Factions uses HIGH. If you want to override it, use HIGHEST
     
  12. Offline

    tommycake50

    well i have used highest in the past and got many errors :I.
     
  13. Offline

    dcgamingentral

    I have also used Highest and it still doesn't work, I think it may be to do with the fact this game is running on a new different map to the default, could that be to do with why they are not respawing?
     
  14. Offline

    Tirelessly

    That's user error, I've never had an issue.. what kind of problem do you have?
     
  15. Offline

    tommycake50

    other plugins not getting the event which stops when i reduce the piority.
     
  16. Offline

    fireblast709

    Then you must be doing something wrong ;3

    1. Set your priority to highest
    2. Don't teleport in the PlayerRespawnEvent, use event.setRespawnPoint(Location) instead
    3. I don't think you can instantly give the player items, use a scheduler to delay the item setting 1 tick

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 30, 2016
  17. Offline

    dcgamingentral

    Thanks that worked on 2 severs out of 3 but on the server where the arena is on a different map to the default one they do not get respawed in the arena world just at spawn of there Faction home.

    Thanks that worked on 2 severs out of 3 but on the server where the arena is on a different map to the default one they do not get respawed in the arena world just at spawn of there Faction home.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 30, 2016
  18. Offline

    lorenzo_p

    came across your forum post while doing some googling. I didn't understand the event priorities at first either. read this page again, closely http://wiki.bukkit.org/Event_API_Reference in order to override all other plugins, use EventPriority.LOWEST . how it works, every plugin listening for the event will get that event, even if it has already been canceled. any plugin down the chain can cancel or uncancel the event. in order to have the last say in where a player spawns, you'd want to be the last plugin to get the event, that way you set the location and no other plugin overrides it.

    so HIGHEST gets called first, but has the least say in the outcome. LOWEST gets called last, but has the final say in the outcome of the event.
     
  19. Offline

    morshu9001

    No, lowest gets called first. Does anyone know what happens if two events have the same priority?
     
    Th3Br1x likes this.
  20. Offline

    ItsLeoFTW

    morshu9001 Then I guess that the events are not called at all. I could be wrong... I don't know much about this.
     
  21. Offline

    morshu9001

    Actually, I tried it, and both were called. Maybe a coincidence, but the one with the name lower in the alphabetical order was called first.
     
  22. Offline

    Th3Br1x

    Yeah, think so too. Or the event of the plugin, which was loaded earlier, has the higher priority.
     
Thread Status:
Not open for further replies.

Share This Page