Solved Check who shot an arrow?

Discussion in 'Plugin Development' started by chaseoes, Oct 12, 2012.

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

    chaseoes

    I'm sure this has been asked before but I'm not finding anything..

    Best way to figure out who shot another player? I figured listen to the bow shoot event and store the entity id of the arrow then compare it against the entity id of when they get hit.. but it's not working out.

    Anyone have some working/example code? Thanks!
     
  2. Offline

    Giorgio

    Code:
    @EventHandler(priority=EventPriority.HIGH, ignoreCancelled = false)
    public void onArrowHit(ProjectileHitEvent e) {
    Player player = (Player)shooter;
    When it finds out who was the shooter what do you want done?
     
  3. Offline

    Timr

    Don't know where you're getting this magical "shooter" from, one look at the javadocs shows that there is no way to get the shooter of a projectile.
     
  4. Offline

    Giorgio

    Timr
    Shooter is recoginized as Player thats what the "=" for

    Code:
    @EventHandler(priority=EventPriority.HIGH, ignoreCancelled = false)
        public void onSnowballHit(ProjectileHitEvent e) {
        Entity entity = e.getEntity();
          if (entity instanceof Egg) {
            Egg egg = (Egg)entity;
            Entity shooter = egg.getShooter();
            if ((shooter instanceof Player)) {
              Player player = (Player)shooter;
              if(player.hasPermission("kitpvp.ninja")){
                player.getWorld().createExplosion(egg.getLocation(), 0.0F); //Doesn't give players damage or damage blocks
            }else{
                //Do nothing!
          }
          }
          }
        }
     
  5. Offline

    Timr

    This:
    Code:java
    1. @EventHandler(priority=EventPriority.HIGH, ignoreCancelled = false)
    2. public void onArrowHit(ProjectileHitEvent e) {
    3. Player player = (Player)shooter;


    is not this:

    Code:java
    1. @EventHandler(priority=EventPriority.HIGH, ignoreCancelled = false)
    2. public void onSnowballHit(ProjectileHitEvent e) {
    3. Entity entity = e.getEntity();
    4. if (entity instanceof Egg) {
    5. Egg egg = (Egg)entity;
    6. Entity shooter = egg.getShooter();
    7. if ((shooter instanceof Player)) {
    8. Player player = (Player)shooter;
    9. if(player.hasPermission("kitpvp.ninja")){
    10. player.getWorld().createExplosion(egg.getLocation(), 0.0F); //Doesn't give players damage or damage blocks
    11. }else{
    12. //Do nothing!
    13. }
    14. }
    15. }
    16. }


    Edit: If you post code, please post an entire example. It doesn't matter if you understand it, but other people have to understand it too.
     
  6. Offline

    Giorgio

    Timr

    Simple mistake I understand.
     
Thread Status:
Not open for further replies.

Share This Page