Entity Event

Discussion in 'Plugin Development' started by zakarls, Jun 21, 2014.

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

    zakarls

    Im using the EntityHitByEntityEvent but whenever I get shot by an arrow It doesnt perform the command (probably because the arrow is the entity I was hit by). So my question is, how do you get the shooter of an arrow in this event? Thanks for any help :)
     
  2. Offline

    Deleted user

    First of all, it's 'EntityDamageByEntityEvent'.

    Check to see if the damaged entity is a player

    Code:
    if (!(event.getEntity instanceof Player))
    return;
     
    Player player = (Player) event.getEntity();
    
    then see if the player was damaged by a projectile and then specify arrow

    Code:
    if (!(event.getDamager() instanceof Projectile))
    return;
    Projectile proj = (Projectile) event.getDamager();
    if (!(proj instanceof Arrow))
    return;
    
    (You may be able to skip checking for Projectile and just directly check for Arrow)
    Then check to see if the shooter is a player.

    Code:
    if (!(proj.getShooter() instanceof Player))
    return;
    Player shooter = (Shooter) proj.getShooter();
    
    and now you have your shooter.
     
  3. Offline

    zakarls

    Yeah, Silly me :p thats what I meant. Also, Thanks for the help.

    Eballer48
    I have another question. It is unrelated but im not sure about something. So if i wanted to check when a player hits a block. Would I use EntityDamageByBlockEvent? Or is there another event to use in that situation

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

    Deleted user

    When you just click (hit) a block? It's PlayerInteractEvent.
    When you break a block? BlockBreakEvent.
     
  5. Offline

    zakarls

    Eballer48
    No. Like when a player falls from the sky and hits the block beneath them and gets fall damage.
     
  6. Offline

    Deleted user


    EntityDamageEvent

    Code:
    if (event.getCause == DamageCause.FALL) {
    
     
  7. Offline

    zakarls

  8. Offline

    Deleted user

    Make sure you check to make sure the Entity is Player.
     
  9. Offline

    zakarls

Thread Status:
Not open for further replies.

Share This Page