Getting the player a snowball hit?

Discussion in 'Plugin Development' started by NoEffex, Nov 17, 2012.

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


    How would i do this? I got who threw the snowball, but now who the snowballhit...
  2. Offline


    What are you asking for exactly?
  3. Offline


    Just a snippet of code that'll return the player in a projectile event, i can't seem the get WHO the projectile hit
  4. Code:JAVA
    2. public void onEntityDamageByEntityEvent(EntityDamageByEntityEvent event) {
    3. if(event.getDamager() instanceof Snowball && event.getEntity() instanceof Player) {
    4. Player playerWhoGotHit = event.getEntity();
    5. }
    6. }

    Should work, untested though.

    Alternatively, since I'm not sure a snowball would work from this since it doesn't cause damage, you could try using a
  5. RealDope

    That works fine in the ProjectileHitEvent. I use it for a few things in one of my plugins.
  6. Offline


    That actually gets who threw the snowball, not who got hit :/
  7. That seems highly unlikely. I'm almost positive DamgeEvents return the damaged entity.
  8. NoEffex
    1. Player playerWhoGotHit = event.getEntity();

    No, event.getEntity() gets the player who got hit by it, not the shooter :/
  9. The Entity involved in EntityDamageByEntity event is the ENTITY THAT GOT DAMAGED.

    You'll notice in my code I called getDamager() which is what gets the entity that caused the damage.
Thread Status:
Not open for further replies.

Share This Page