Solved Help with EntityDeathEvent

Discussion in 'Plugin Development' started by A4Papers, May 24, 2014.

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

    A4Papers

    How would i get the players name though this? Thanks

    Code:java
    1. @EventHandler
    2. public void onEntityDeath(EntityDeathEvent e) {
    3. Entity entity = e.getEntity();
    4. if (entity instanceof Player) {
    5. if (entity.getLastDamageCause() instanceof EntityDamageByEntityEvent) {
    6. EntityDamageByEntityEvent entityDamageByEntityEvent = (EntityDamageByEntityEvent) entity.getLastDamageCause();
    7. if (entityDamageByEntityEvent.getDamager() instanceof Player) {
    8. Player Att = (Player) entityDamageByEntityEvent.getDamager(); {
    9. Attacker.add(Att);
    10. }
    11. }
    12. }
    13. }
    14. }
    15.  
     
  2. A4Papers Why don't you use PlayerDeathEvent?
     
  3. Offline

    teej107

    I do agree with driver-e, since it returns the player but to answer your question, you'll need to cast the entity as a player.
     
  4. Offline

    A4Papers

    Thanks guys!
     
Thread Status:
Not open for further replies.

Share This Page