How to see who killed someone

Discussion in 'Plugin Development' started by greg_t, Nov 4, 2011.

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

    greg_t

    I want to with my player listener or any listener dont mind but it think player is only one that would work i want to see who killed someone.
     
  2. Offline

    AinSophAur

    There is a lot of different ways this can be done.

    PHP:
    public void onEntityDeath (EntityDeathEvent event) {
            
    Event eventType event.getEntity().getLastDamageCause();
            if (
    eventType instanceof EntityDamageByEntityEvent) {
                
    EntityDamageByEntityEvent evt = (EntityDamageByEntityEventeventType;
                if (
    evt.getDamager() instanceof Player) {
                    
    Player damager = (Playerevt.getDamager();
                    
    String weapon " (" damager.getItemInHand().getType().toString().toLowerCase().replace("_"" ") + ")";
                    if (
    event.getEntity() instanceof Player) {
                        
    Player player = (Player)event.getEntity();
                        
    plugin.log.info(damager " killed " player " with " weapon);
                    }
                }
            }
    }
    I use the EntityListener and do it this way to get player kills of other players, animals and mobs. Alternatively you can hook into other plugins like HeroicDeath which catch the events of death from players and other things and just simply get it that way too while using this to get kills on mob and animals.
     
Thread Status:
Not open for further replies.

Share This Page