Solved Check if a snowball killed a Player?

Discussion in 'Plugin Development' started by Haribo98, Dec 21, 2012.

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

    Haribo98

    Hey there,
    I'm using the EntityDamageByEntity event, to make a snowball fight plugin (private). When the snowball hits it sets the damage as 2 hearts, etc. That all works fine.

    What I want to know, is how do I check when a Snowball kills a player?

    I thought by fetching the LastDamageCause (LDC), then fetching the entity from the LDC on a PlayerDeathEvent would work. However, it does not. So I thought, I'll check using a DamageCause.PROJECTILE. However, that only works for Arrows. Any suggestions?
     
  2. Offline

    tommycake50

    EntityDeathEvent
    if(e.getKiller().getType().equals(EntityType.snowball))
    //its a snowball
     
  3. Offline

    Haribo98

    Tried that, however, the getKiller() method, will return the actual killer, not the entity that killed them.
    Eg. If a player shot a player. getKiller() would return a Player now an Arrow or a Snowball.
     
  4. Offline

    tommycake50

    oh yeah :/ wow idk then.
    ProjectileHitEvent maybe.
     
  5. Offline

    Haribo98

    Why is a Snowball not a Projectile?

    EDIT: Or is it because the Snowball, by default doesn't do any damage. Therefore it can't be a cause?
     
  6. Offline

    tommycake50

    so how can it kill a player?
    custom damage?
     
  7. Offline

    gomeow

    SnowBalls are projectiles.
    But the method .getKiller() always returns a player.

    On entity damage, you could check if their health is 0
     
  8. Offline

    Rprrr

    Use getLastDamageCause() ?
     
  9. Offline

    fireblast709

    That in combination with a check if:
    • the EntityDamageEvent is an instanceof EntityDamageByEntityEvent
    • if the damager is an instanceof Snowball
     
  10. Offline

    gamerzap

    When you set the damage for the snowball, check if the player's health == 0. If so, go ahead.
     
  11. Offline

    whitehooder

    Isn't the problem located in that the damage is not actually coming from the snowball itself, but from the plugin lowering the targets health?
    In my eyes you wouldn't be able to check what entity killed him if he was killed by code. (Correct me if I'm wrong, just brainstorming here ;))
     
  12. Offline

    fireblast709

    Code:java
    1. player.damage(2, <insert Snowball entity here>)
    How about this? (or set the damage in the EntityDamageByEntityEvent if the damager is a Snowball)
     
  13. Offline

    Haribo98

    I used setDamage() from EntityDamageByEntity event. Turns out, it worked, but, I forgot to fire the event itself.
     
Thread Status:
Not open for further replies.

Share This Page