Solved Arrow Hitting Entity Will Not Work!

Discussion in 'Plugin Development' started by hubeb, Aug 22, 2013.

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

    hubeb

    Ive tried projectilehitevent and entitydamageevent and I cannot for the life of me figure out if the arrow has hit a mob or player.

    Can someone point me in a direction please.

    Thanks,
    Hubeb
     
  2. Offline

    Tarestudio

    hubeb
    'if (ProjectileHitEvent.getEntity() != null && ProjectileHitEvent.getEntity() instanceof Player)' doesnt work?
     
  3. Offline

    hubeb

  4. Offline

    SoThatsIt

    firstly, have you registered your events, this is a common problem that often annoys people who try to help you only to find out it was that simple. secondly, you could just listen to entitydamageevent then check if the entity, e.getEntity(), is an arrow.
     
  5. Offline

    hubeb

    SoThatsIt
    Yes I have registered my events.
     
  6. Offline

    SoThatsIt

    e.getEntity() might get the damaged entity i think, use e.getDamager i believe to get the arrow.

    so then, just listen to entityDamageEvent then check if e.getDamager() is an arrow then you can check if e.getEntity() is instanceof Player

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
  7. Offline

    hubeb

    Last edited by a moderator: Jun 4, 2016
  8. Offline

    Tarestudio

    hubeb
    With mobs you mean? If you mean the 'bad guys' you can check instanceof Monster, if you mean animals and villigers as well, instanceof Creature, if all the things and player its instanceof LivingEntity
     
  9. Offline

    hubeb

    Tarestudio SoThatsIt
    This is my code... and it "should" work:
    Code:java
    1. @EventHandler
    2. public void arrowHit(EntityDamageEvent event) throws IOException{
    3. if (event.getEntity() != null){
    4. if(event.getEntity().getLastDamageCause() instanceof Arrow){
    5. Arrow a = (Arrow)event.getEntity().getLastDamageCause();
    6. if(a.getShooter() instanceof Player){
    7. Player player = (Player) a.getShooter();
    8. Bukkit.broadcastMessage("3");
    9. Useful.setExp(player, "archery", 5);
    10. player.sendMessage(ChatColor.GOLD+"You have gained: "+
    11. ChatColor.AQUA+5+ChatColor.GOLD+" Archery Exp.");
    12. Bukkit.broadcastMessage("4");
    13. }
    14. }
    15. }
    16. }
     
  10. Offline

    Tarestudio

  11. Offline

    hubeb

    Tarestudio
    Still No Luck: ----Edited ----
    Code:java
    1. @EventHandler
    2. public void arrowHit(EntityDamageEvent event) throws IOException{
    3. if (event.getEntity() != null){
    4. if(event.getEntity().getLastDamageCause() instanceof Projectile){
    5. Projectile pro = (Projectile)event.getEntity().getLastDamageCause();
    6. if(pro instanceof Arrow){
    7. Arrow a = (Arrow)pro;
    8. if(a.getShooter() instanceof Player){
    9. Player player = (Player) a.getShooter();
    10. Bukkit.broadcastMessage("3");
    11. Useful.setExp(player, "archery", 5);
    12. player.sendMessage(ChatColor.GOLD+"You have gained: "+
    13. ChatColor.AQUA+5+ChatColor.GOLD+" Archery Exp.");
    14. Bukkit.broadcastMessage("4");
    15. }
    16. }
    17. }
    18. }
    19. }
     
  12. Offline

    Tarestudio

     
  13. Offline

    hubeb

    Tarestudio
    Trust me ive already tried both.
    How am I supposed to grab the entity hit from the projectilehitevent?

    Tarestudio SoThatsIt
    Thanks for the help guys, I needed the EntityDamagedByEntityEvent... derp part on my end.
    Here is the code if you want:
    Code:java
    1. @EventHandler
    2. public void arrowhit(EntityDamageByEntityEvent event) throws IOException{
    3. if(event.getDamager() instanceof Arrow){
    4. Arrow arrow = (Arrow) event.getDamager();
    5. if(arrow.getShooter() instanceof Player){
    6. Player shooter = (Player) arrow.getShooter();
    7. //Code Here
    8. }
    9. }
    10. }

    now its 3:15am here im going to go to bed.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
Thread Status:
Not open for further replies.

Share This Page