Solved EntityDamageEvent.....

Discussion in 'Plugin Development' started by ASHninja1997, Aug 24, 2013.

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

    ASHninja1997

    I made a plugin that shoots arrows from hoes and the problem is....that the arrows that the player shot hurts themselves. The arrows shoot in front of the players face and if the player move's to fast they get hit by their own arrow. I tried several different type's of ways to check if the Player damaged = the Damager, but all of them give me error's.
    Does anyone know how to do this?
     
  2. Offline

    tommycake50

    Fire it faster?
     
  3. Offline

    Axe2760

    Code:
    Arrow arrow = (Arrow)player.launchProjectile(Arrow.class);
    arrow.setVelocity(arrow.getVelocity().multiply(10));
    
    Super fast arrows! :p
     
  4. Offline

    ASHninja1997

    Axe2760 tommycake50
    My plugin sets each hoe as an different velocity so I sadly can't change the velocity of the arrow.

    xTrollxDudex
    would be good at trying to solve this or telling me why this won't work.

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

    metalhedd

    show us the code that launches the projectile.
     
  6. Offline

    ASHninja1997

    metalhedd
    Code:java
    1. @SuppressWarnings("deprecation")
    2. @EventHandler
    3. public void onInteract(PlayerInteractEvent e) {
    4. Player p = e.getPlayer();
    5. if (e.getAction() == Action.RIGHT_CLICK_AIR) {
    6. if (p.getItemInHand().getType() == Material.WOOD_HOE) {
    7. if (!p.getInventory().containsAtLeast(
    8. new ItemStack(Material.FLINT), 1)) {
    9. p.sendMessage(ChatColor.DARK_AQUA
    10. + "You need flint to shoot!");
    11. p.playSound(p.getLocation() , Sound.ANVIL_LAND, 1f,3f);
    12. e.setCancelled(true);
    13. } else {
    14. float yaw = p.getLocation().getYaw();
    15. double D = 1.0;
    16. double x = -D * Math.sin(yaw * Math.PI / 180);
    17. double z = D * Math.cos(yaw * Math.PI / 180);
    18. p.getInventory().removeItem(
    19. new ItemStack(Material.FLINT, 1));
    20. Entity arrow = p.getWorld().spawn(
    21. p.getLocation().add(x, 1.62, z), Arrow.class);
    22. arrow.setVelocity(p.getLocation().getDirection()
    23. .multiply(1.5f));
    24. p.updateInventory();
    25. }
    26. } else {
    27. return;
    28. }
    29. }
    30. }


    I going to go swim in a river, I will be back in a few :D.

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

    metalhedd

    you should probably replace most of that code with a simple LivingEntity.launchProjectile call. that would solve all your problems. but you COULD also just spawn the arrow a little bit further in front of the player instead of right inside their head.
     
    ASHninja1997 likes this.
  8. Offline

    Ultimate_n00b

    :/ you're spawning it in a players location.

    Try :
    Code:java
    1. Arrow arrow = p.launchProjectile(Arrow.class);
    2. arrow.setVelocity(etc..);
     
  9. Offline

    xTrollxDudex

    ASHninja1997 likes this.
  10. Offline

    ASHninja1997

    metalhedd
    Thank you so much this solved everything!!

    xTrollxDudex
    Thanks :D.

    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