Solved Check who shot an arrow?

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

  1. Offline

    chaseoes Retired Staff

    My BukkitDev Profile
    My Plugins (15)
    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

    My BukkitDev Profile
    My Plugins (5)
    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Code (Text):
    1. @EventHandler(priority=EventPriority.HIGH, ignoreCancelled = false)
    2. public void onArrowHit(ProjectileHitEvent e) {
    3. Player player = (Player)shooter;
    When it finds out who was the shooter what do you want done?
     
  3. Offline

    Timr

    My BukkitDev Profile
    My Plugins (3)
    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

    My BukkitDev Profile
    My Plugins (5)
    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Timr
    Shooter is recoginized as Player thats what the "=" for

    Code (Text):
    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.     }
     
  5. Offline

    Timr

    My BukkitDev Profile
    My Plugins (3)
    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.
     
  6. Offline

    Giorgio

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

    Simple mistake I understand.
     

Share This Page