Solved Check who shot an arrow?

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

  1. Offline

    chaseoes Retired Staff

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    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

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    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?

    This post has been edited 1 time. It was last edited by Giorgio Oct 13, 2012.
  3. Offline

    Timr

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    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

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    @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!
          }
          }
          }
        }

    This post has been edited 1 time. It was last edited by Giorgio Oct 13, 2012.
  5. Offline

    Timr

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    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.

    This post has been edited 1 time. It was last edited by Timr Oct 13, 2012.
  6. Offline

    Giorgio

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    @Timr

    Simple mistake I understand.

Share This Page