mob entity type is always a player... Help?

Discussion in 'Plugin Development' started by RjSowden, May 1, 2012.

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

    RjSowden

    What I want to happen in my plugin is to return a string containing the mob type of them mob that killed a player, if it isn't a human. But even though I've already checked if its an instance of a player and it has returned false, whenever a mob kills a player, it says that the mob that killed it was a player. This is what I've got:
    Code:
    public void onPlayerDeath(PlayerDeathEvent event){
                Player p = event.getEntity();
                if(p.getLastDamageCause() instanceof Player){
                Player attacker = (Player) p.getLastDamageCause().getEntity();
                if (Minebase.hasAccount(attacker.getDisplayName()) == true){
                Minebase.PostStatus(p, "Just got killed by <a href=u/" + attacker.getDisplayName() + "</a>");
                Minebase.PostStatus(attacker,"Just killed <a href=u/" + p.getDisplayName() + "</a>");
                Minebase.IncrementKills(attacker);
                } else {
                    Minebase.PostStatus(p, "Just got killed by " + attacker.getDisplayName() + " (No minebase account)");
                }
                }else{
                   
                    Minebase.PostStatus(p, "Just got killed by a " + [B]p.getLastDamageCause().getEntity().getType().toString().toLowerCase()[/B]);
                }
                Minebase.IncrementDeaths(p);
           
       
        }
    the code in bold is the code I am using to get the mob type that killed the player, which always returns 'player' even if its an endermen or creeper.

    Can anyone help?
    Thanks!
     
  2. Offline

    CorrieKay

    p.getLastDamageCause() returns the last EntityDamageEvent that contained the player, so its not gonna be an instanceof a player.

    gimme a sec, im gonna look through the docs for this cuz im not sure if you can return the last ENTITY, being that if you get the cause, it, at most, will be ENTITY_ATTACK... which can be a player or mob.

    Edit: what you can do is catch an EntityDamageByEntityEvent, if the damaged entity instanceof player, grab the players health, subtract it by the damage dealt, if <= zero, and the damaging entity is instanceof player, then do your code
     
  3. Offline

    RjSowden

    wow. Just got code pwned. by someone with a brony as a profile pic. I feel so... useless. Thanks for the advice!
     
  4. Offline

    CorrieKay

    No worries, always here to help ;)
     
Thread Status:
Not open for further replies.

Share This Page