DeathInfo - is entity a player?

Discussion in 'Plugin Development' started by immapoint, Jan 29, 2011.

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

    immapoint

    Hey guys,

    im porting DeathInfo from hMod to bukkit. I need to know, if a Entity object is a Player and then i need to know the players name.
    so far i have the following:
    Code:
    @Override
        public void onEntityDamageByBlock(EntityDamageByBlockEvent evt){
    
            Player victim = (Player)evt.getEntity();
    
        }
    But now i have no idea how to fill all the attributes of the player class - entity is just the base class so there is no name, health etc.

    thanks in advance.
     
  2. Offline

    8e8

    if(evt.getEntity() instanceof Player) {
    Player victim = (Player) evt.getEntity();
    String victimName = victim.getName();
    }

    You'd want to check if it's a Player entity first before you turn it into one in case you try to turn a mob into a Player. It would cause an error if it did.
     
  3. Offline

    immapoint

    ok, but how to get the name of the player who killed victimName? ;O
     
  4. Offline

    8e8

    in onEntityDamagedByEntity you just add another bit to that function.
    Code:
    // After victim named recieved
    if(event.getAttacker() instanceof Player) {
        String attackerName = ((Player) event.getAttacker()).getName();
    }
     
  5. Offline

    immapoint

    first: i found no function called getAttacker,
    second: there is an error in the plugin, but I cant find it. can you help me, please? ;O
     

    Attached Files:

  6. Offline

    void420

    You need to also listen to onEntityDamageByBlock (cactus ...), onEntityDamageByEntity (mobs, other players ...), onEntityDamageByProjectile (arrows ...)
     
  7. Offline

    Night3

    Use event.getDamager() instead of event.getAttacker()
     
Thread Status:
Not open for further replies.

Share This Page