Deflect projectiles

Discussion in 'Plugin Development' started by victor2748, Oct 14, 2014.

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

    victor2748

    Hey all, I have this problem. I wanna make a feature, that when an arrow hits a player, it reflects back in the opposite direction. However, when the PlayerDamageByEntity event fires, the projectile already removes, and I can't set it's velocity. Can you please help?
     
  2. Offline

    Jaaakee224

  3. Offline

    victor2748

    Jaaakee224
    Code:java
    1. @EventHandler
    2. public void onItem(EntityDamageByEntityEvent e) {
    3. Entity damager = e.getDamager();
    4. if (damager instanceof Projectile) {
    5. e.setCancelled(true);
    6. Vector vel = damager.getVelocity();
    7. damager.setVelocity(new Vector(-vel.getX(), -vel.getY(), -vel.getZ()));
    8. }
    9. }
     
  4. Offline

    teej107

    victor2748 Well since the projectile gets removed by then, create a new one.
     
  5. victor2748 there is a ProjectileHitEvent you can listen to :)
     
  6. Offline

    Watto

    Shmobi

    ProjectileHitEvent doesn't let you check what you hit so it's pretty useless in this case.
     
  7. Watto yea, you're right. I wasn't sure about that, sry.
    EntityDamageByEntityEvent worked just fine for me. getDamager() returns the entity which damaged the target. check its instance, cast it and then relaunch it. I did this with a snowball
     
Thread Status:
Not open for further replies.

Share This Page