How to get the shooter and the entity hit from an arrow shot?

Discussion in 'Plugin Development' started by MrSnare, Jan 7, 2013.

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

    MrSnare

    Im using ProjectileHitEvent. does event.getEntity() return the entity hit?
    How do i get the shooter?

    Bonus question: How could i go about finding if a players bow shot hits a target(entity) or not?
     
  2. Offline

    RealDope

    You'll have to store the name of the shooter and the UUID of the arrow when it's shot, then when it hits somebody, check which name links with the UUID.

    Use a HashMap<String, UUID> and ProjectileLaunchEvent
     
  3. Offline

    fireblast709

    1. EntityDamageByEntityEvent
    2. event.getDamager() instanceof Arrow
    3. LivingEntity shooter = ((Arrow)event.getDamager()).getShooter(); <- shooter
    4. event.getEntity() <- damaged
     
  4. Offline

    MrSnare

    Which one of these is better? I'm leaning towards fireblast709's for fear of the HashMap getting really big
     
  5. Offline

    fireblast709

    MrSnare my version is the advised one, as
    • you cannot get the hit entity with the ProjectileHitEvent
    • you could just get the LivingEntity shooter from the Projectile
     
  6. Offline

    ImDeJay

    Code:java
    1. public void playerFight(EntityDamageByEntityEvent event){
    2.  
    3. if(event.getDamager() instanceof Arrow){
    4. Arrow arrow = (Arrow) event.getDamager();
    5.  
    6. if(arrow.getShooter() instanceof Player){
    7.  
    8. if(event.getEntity() instanceof Player){
    9.  
    10. Player shooter = (Player) arrow.getShooter();
    11.  
    12. Player victim = (Player) event.getEntity();
    13.  
    14. }
    15.  
    16. }
    17.  
    18. }
    19. }
     
  7. Offline

    MrSnare

    Thanks. I went with your way and it worked perfectly
     
Thread Status:
Not open for further replies.

Share This Page