Solved (1.8.1 R4) PlayerDeathEvent

Discussion in 'Plugin Help/Development/Requests' started by amatokus, Apr 19, 2015.

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

    amatokus

    Hi all I tried to use the bukkit version 1.8.1 R4 to update one of my plugins.

    The problem is that I guess, the way to get the player changed.

    Code:
            Player killed = event.getEntity().getPlayer();
    is wrong.

    HEEEELP I'll give you a cookie!
     
  2. Offline

    pie_flavor

    @amatokus That was never the case. event.getEntity() returns the Player. You have never been able to take a Player object and call getPlayer() on it. Just do event.getEntity().
     
  3. Offline

    nverdier

    @pie_flavor You gonna keep that cookie? Or, uh, *cough* can I have it *cough*
     
    amatokus likes this.
  4. Offline

    amatokus

  5. Offline

    nverdier

    @amatokus Player#getKiller() and check if it's null.
     
  6. Offline

    amatokus

  7. Offline

    nverdier

  8. Offline

    amatokus

  9. Offline

    pie_flavor

    @amatokus Player#getKiller() will always return an entity, whether or not the last death was a kill and not environmental.
    Here is a block of code I always use:
    Code:
    public void onDeath(PlayerDeathEvent event) {
        if (event.getEntity().getLastDamageCause() instanceof EntityDamageByEntityEvent) {
            EntityDamageByEntityEvent e = (EntityDamageByEntityEvent) event.getEntity().getLastDamageCause();
            if (e.getDamager().getType().equals(EntityType.PLAYER) {
                //code here
            }
        }
    }
    also @nverdier in response to your first comment
    in a crafting table put wheat, cocoa beans, wheat
     
Thread Status:
Not open for further replies.

Share This Page