Doesn't Recognize Arrow

Discussion in 'Plugin Development' started by chasechocolate, Dec 26, 2012.

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

    chasechocolate

    Hi, I am trying to make a headshot feature in my plugin, and it doesn't work. When I shoot another player with an arrow, it will broadcast "Event fired!" and "Hit a player", but it won't broadcast "Entity is an arrow!". Am I doing something wrong?
    Code:java
    1. @EventHandler
    2. public void onArcherheadshot(EntityDamageByEntityEvent event){
    3. plugin.getServer().broadcastMessage("Event fired!");
    4. int x1, x2, z1, z2;
    5. Entity entity = event.getDamager();
    6. if(event.getEntity() instanceof Player){
    7. plugin.getServer().broadcastMessage("Hit a player!");
    8. if(entity instanceof Arrow){
    9. plugin.getServer().broadcastMessage("Entity is an arrow!");
    10. Arrow arrow = (Arrow) event.getEntity();
    11. if(arrow.getShooter() instanceof Player){
    12. plugin.getServer().broadcastMessage("Shooter is a player!");
    13. Player shooter = (Player) arrow.getShooter();
    14. Location sLoc = shooter.getLocation();
    15. Location vLoc = entity.getLocation();
    16. int sx = sLoc.getBlockY(), sz = sLoc.getBlockZ(), vx = vLoc.getBlockX(), vz = vLoc.getBlockZ();
    17. if(sx > vx){
    18. plugin.getServer().broadcastMessage("sx > vx!");
    19. x1 = sx;
    20. x2 = vx;
    21. } else {
    22. plugin.getServer().broadcastMessage("sx !> vx!");
    23. x1 = vx;
    24. x2 = sx;
    25. }
    26.  
    27. if(sz > vz){
    28. plugin.getServer().broadcastMessage("sx > vz!");
    29. z1 = sx;
    30. z2 = vx;
    31. } else {
    32. plugin.getServer().broadcastMessage("sx !> vz!");
    33. z1 = vz;
    34. z2 = sz;
    35. }
    36. int z = z1 - z2, x = x1 - x2;
    37. int distSquared = z * z + x * x;
    38. double dist = Math.sqrt(distSquared); //Pythagorean Theorm
    39. if(dist >= plugin.getHeadshotDistance()){
    40. plugin.getServer().broadcastMessage("Distance is greater than " + plugin.getHeadshotDistance() + "!");
    41. //Players
    42. Player killed = (Player) event.getEntity();
    43. Player killer = (Player) arrow.getShooter();
    44.  
    45. //Killed stuff
    46. killed.getInventory().clear();
    47. killed.setHealth(0);
    48. killed.sendMessage(plugin.getHeadshotKilledMessage(killer));
    49.  
    50. //Killer stuff
    51. killer.sendMessage(plugin.getHeadshotKillerMessage(killed));
    52. }
    53. }
    54. }
    55. }
    56. }
     
  2. Offline

    fireblast709

    Then the damage is not due an Arrow, is it?
     
  3. Offline

    chasechocolate

    No, I shot another player with an arrow.

    Wait should I check if the entity is an instanceof Projectile, because it might think that it is an arrow being held?

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

Share This Page