Getting when a player is shot in the head by another player

Discussion in 'Plugin Development' started by techboy291, Feb 11, 2013.

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

    techboy291

    Hi,

    So as the title says, I want to get when a player is shot in the head by another player. This code doesn't seem to be working:

    Code:
    @EventHandler
        public void onEntityDamageByEntity(EntityDamageEvent e) {
            if(e instanceof EntityDamageByEntityEvent) {
                EntityDamageByEntityEvent event = (EntityDamageByEntityEvent) e;
                if(event.getDamager() instanceof Arrow) {
                    Entity damagedEntity = event.getEntity();
                    Location l = damagedEntity.getLocation();
                    Location damagedEntityPart = new Location(damagedEntity.getWorld(), l.getX(), l.getY() + 2, l.getZ());
                    if(((Arrow)event.getDamager()).getLocation().equals(damagedEntityPart) && damagedEntity instanceof LivingEntity)
                        ((LivingEntity)damagedEntity).damage(20);
                }
            }
        }
    Yes, I've registered my listener class. And no, I did not get any errors.

    Sorry about the mess. Thanks in advance :)
     
  2. Offline

    raGan.

    You can't check if location is equals, check if Y is in certain range of player's eyes.
     
  3. Offline

    valon750

    techboy291

    Can you apply what you do with blocks to this situation?

    By that I mean, have .getLocation().add(0,1,0)

    Code:
    if(((Arrow)event.getDamager()).getLocation()add(0,1,0)).equals(damagedEntityPart) && damagedEntity instanceof LivingEntity)
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
Thread Status:
Not open for further replies.

Share This Page