How to get if a player is hit by a certain throwable item such as an egg

Discussion in 'Plugin Development' started by winitro, Sep 18, 2014.

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

    winitro

    What I've got right know but I'm lost from here.
    Code:java
    1. @EventHandler
    2. public void onPlayerHit(EntityDamageEvent event){
    3. if(event.getEntity() instanceof Player) {
    4. Player damaged = (Player) event.getEntity();
    5. }
    6. } [syntax][/syntax]
     
  2. Offline

    blablubbabc

    Check out the EntityDamagedByEntityEvent and check if the damaging entity is instanceof Projectile.
     
  3. Offline

    winitro

    Alright

    blablubbabc
    Can I see some code?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 14, 2016
  4. Offline

    mythbusterma

    winitro

    Can I see that you've made any effort whatsoever?
     
  5. Offline

    97WaterPolo

    winitro
    The event EntityDamageByEntityEvent
    if the entity instanceof player && damager instance of Egg
    //Run code?

    Isn't egg counted as a projectile?
     
  6. Offline

    rbrick

    Yes, the Egg interface extends the Projectile interface.
     
    97WaterPolo likes this.
  7. Offline

    BetaNyan

    Use a ProjectileHitEvent, check if the one who gets hit is a Player, check if the projectile is an egg, snowball, etc, and then it should work.
     
  8. Offline

    fireblast709

    BetaNyan you cannot guarantee that a player was hit by using this event :p
     
  9. Offline

    BetaNyan

    I think there is a way of checking, though.
     
Thread Status:
Not open for further replies.

Share This Page