PlayerDeathEvent, counts as 2 kill/2 deaths

Discussion in 'Plugin Development' started by Phatomhugo, Dec 3, 2015.

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

    Phatomhugo

    Well, in my plugin, when a guy dies or kill anyone, says the same things 2 times!
    Can anyone explain to me?



    - Sorry for my bad english.
     
  2. Offline

    mythbusterma

    @Phatomhugo

    You probably registered your listener twice.
     
  3. Offline

    Phatomhugo

  4. Offline

    mythbusterma

    @Phatomhugo

    Well then we can't help you without your code.
     
  5. Offline

    mcdorli

    Or you have two methods inside the one event.
     
  6. Offline

    CoolDude53

    @Phatomhugo In my experience, there is a weird bukkit bug (for 1.7.10) that calls the death event twice. This is weird, and I spent lots of time trying to identify why it was happening and couldn't find an answer. The solution I implemented was to record when the event was called and to cancel the event on the second event fire.
     
  7. Offline

    Phatomhugo

    @mythbusterma

    Code:
    @EventHandler
        public void onDeath(PlayerDeathEvent event) {
            Player p = event.getEntity();
            Player k = event.getEntity().getKiller();
            if (((event.getEntity() instanceof Player)) && ((event.getEntity().getKiller() instanceof Player)))
            {
               
                if(me.hugo.halff.a.d.viking.contains(k.getName())){
                    if(k.getInventory().contains(Material.STONE_AXE)){
                        k.getInventory().remove(Material.STONE_AXE);
                        k.getInventory().addItem(new ItemStack(Material.IRON_AXE));
                    }
                    if(k.getInventory().contains(Material.IRON_AXE)) {
                        k.getInventory().remove(Material.IRON_AXE);
                        k.getInventory().addItem(new ItemStack(Material.DIAMOND_AXE));
                       
                    }
                }
               
                event.setDeathMessage(null);
               
                me.hugo.halff.a.d.remover(p);
               
                addDeath(p, +1);
                getKills(k, +1);
    
                p.playSound(p.getLocation(), Sound.ANVIL_LAND, 1.0F, 1.0F);
                k.playSound(k.getLocation(), Sound.ANVIL_USE, 1.0F, 1.0F);
    
                k.sendMessage("§a[✖] - Você matou: " + p.getName()+"(" + KitManager.getKit(p)+")");
                main.econ.depositPlayer(k.getName(), 50);
    
                p.sendMessage("§4[✖] - Você morreu para: " + k.getName()+"("+KitManager.getKit(k)+")");
                main.econ.bankWithdraw(p.getName(), 25);
    
                setScoreboard(k);
            } else {
                me.hugo.halff.a.d.remover(p);
                addDeath(p, +1);
                event.setDeathMessage(null);
            }
        }
     
  8. Offline

    Scimiguy

    @CoolDude53 @Phatomhugo
    Probably an issue on your end.

    My CompleteDeaths plugin handles every death event, I've never had a single issue with double deaths
     
  9. Offline

    xMrPoi

    What does your addDeath and getKills method look like?
     
  10. Offline

    CoolDude53

    @Scimiguy I no longer encounter the issue, so I wouldn't know. It was something with the EntityDeathEvent and the PlayerDeathEvent that caused the double fire. Just a possibility to consider.
     
  11. Offline

    MajorSkillage

    Maybe try make it synchronized to test it?
     
  12. Offline

    mythbusterma

  13. Offline

    Scimiguy

    @mythbusterma
    Sounds like the result of inserting random words into a sentence.


    @Phatomhugo
    Let's just try narrow it down.
    Can you show us your entire main class? (The one that extends JavaPlugin)
     
    mythbusterma likes this.
  14. Offline

    mcdorli

    1.: Jesus, what's this
    Code:
    me.hugo.halff.a.d.viking.contains(k.getName())
    
    2.: there is no way in a player death event, that the entity won't be an instance of Player
     
  15. Offline

    MajorSkillage

    Maybe perhaps some of the data in the method could have gotten overwritten due to it happening constant amounts of times, should only be used for testing though otherwise you may be a few ticks behind anything from happening.

    P.S Better naming conventions should be applied.
     
  16. Offline

    mythbusterma

    @MajorSkillage

    Uhm.....no?

    The Bukkit server is completely synchronous. Adding the "synchronized" keyword to your event handler will do nothing, as there will never be contention for calling that method. Only the main thread calls event handlers (other than for the events that explicitly begin with "async").
     
  17. Offline

    MajorSkillage

    Well I never looked, was just a guess. Anyway in addKills() and addDeaths() method, mind showing us? Also, if you are sure the event fires twice instead of once when it is meant to then check if the player's balance matches with the amount of kills. If it does the only conclusion I can think of is one of the other plugins installed on the server calls PlayerDeathEvent when it isn't meant to.
     
Thread Status:
Not open for further replies.

Share This Page