Fireball direction not changing

Discussion in 'Plugin Development' started by moo3oo3oo3, Oct 11, 2014.

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

    moo3oo3oo3

    I'm getting all nearby fireball with .getNearbyEntities() and multiplying their direction by -1. When this happens, the fireball will go in the opposite direction then, in mid flight, go back to original direction! How to I stop the fireball from going back the original direction?

    P.S. When I say fireball, I mean both big and small.

    Code:
    Code:java
    1. @EventHandler
    2. public void deflector(PlayerInteractEvent e) {
    3.  
    4. final Player player = e.getPlayer();
    5. List<Entity> entity = player.getNearbyEntities(3.9, 3.9, 3.9);
    6.  
    7. if (player.getItemInHand() != null && player.getItemInHand().getType() != Material.AIR) {
    8. if (player.getItemInHand().hasItemMeta() && player.getItemInHand().getItemMeta().hasDisplayName()) {
    9. if (player.getItemInHand().getType() == Material.CLAY_BALL && player.getInventory().getItemInHand().getItemMeta().getDisplayName().equalsIgnoreCase("§4Deflector Stone") && e.getAction() == e.getAction().RIGHT_CLICK_AIR || player.getItemInHand().getType() == Material.CLAY_BALL && player.getInventory().getItemInHand().getItemMeta().getDisplayName().equalsIgnoreCase("§4Deflector Stone") && e.getAction() == e.getAction().RIGHT_CLICK_BLOCK) {
    10. if (player.hasPermission("use.deflectorstone")) {
    11. for (final Entity x: entity) {
    12. if (x instanceof Projectile) {
    13. if (!(x instanceof WitherSkull) && x.isInsideVehicle() == false) {
    14. final Vector velocity = x.getVelocity();
    15. final Vector direction = x.getLocation().getDirection();
    16. final WitherSkull wither = x.getWorld().spawn(x.getLocation(), WitherSkull.class);
    17. player.sendMessage(direction.toString());
    18. wither.setDirection(new Vector(0, 0, 0));
    19. wither.setVelocity(new Vector(0, 0, 0));
    20. wither.setPassenger(x);
    21. //x.remove();
    22. Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
    23. public void run() {
    24. wither.remove();
    25. Vector dir = direction.multiply(-1);
    26. if (!(x instanceof SmallFireball)) {
    27. Vector vel = velocity.multiply(-1);
    28. x.setVelocity(vel);
    29. player.sendMessage("phail");
    30. }
    31. player.sendMessage(x.getLocation().setDirection(dir).toString());
    32. x.getLocation().setDirection(dir);
    33. }
    34. }, 150L);
    35. }
    36. }
    37. }
    38. }
    39. }
    40. }
    41. }
    42. }
     
  2. Offline

    mine-care

    Errors?
    Stacktraces?
    Have you tried debuging
     
  3. Offline

    Europia79

    moo3oo3oo3

    Try this:

    Code:java
    1. @EventHandler
    2. public void deflector(PlayerInteractEvent e) {
    3.  
    4. final Player player = e.getPlayer();
    5. List<Entity> entity = player.getNearbyEntities(3.9, 3.9, 3.9);
    6.  
    7. if (player.hasPermission("use.deflectorstone") && hasDeflectorStone(player)
    8. && (e.getAction() == e.getAction().RIGHT_CLICK_BLOCK || e.getAction() == e.getAction().RIGHT_CLICK_AIR)) {
    9. for (final Entity x : entity) {
    10. if (x instanceof Projectile) {
    11. if (!(x instanceof WitherSkull) && x.isInsideVehicle() == false) {
    12. final Vector velocity = x.getVelocity();
    13. final Vector direction = x.getLocation().getDirection();
    14. final WitherSkull wither = x.getWorld().spawn(x.getLocation(), WitherSkull.class);
    15. player.sendMessage(direction.toString());
    16. wither.setDirection(new Vector(0, 0, 0));
    17. wither.setVelocity(new Vector(0, 0, 0));
    18. wither.setPassenger(x);
    19. // x.remove();
    20. Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
    21. public void run() {
    22. wither.remove();
    23. Vector dir = direction.multiply(-1);
    24. if (!(x instanceof SmallFireball)) {
    25. Vector vel = velocity.multiply(-1);
    26. x.setVelocity(vel);
    27. player.sendMessage("phail");
    28. }
    29. player.sendMessage(x.getLocation().setDirection(dir).toString());
    30. x.getLocation().setDirection(dir);
    31. }
    32. }, 150L);
    33. }
    34. }
    35. }
    36. }
    37.  
    38. }
    39.  
    40. public boolean hasDeflectorStone(Player player) {
    41. if (player.getItemInHand() != null && player.getItemInHand().getType() != Material.AIR) {
    42. if (player.getItemInHand().hasItemMeta() && player.getItemInHand().getItemMeta().hasDisplayName()) {
    43. if (player.getItemInHand().getType() == Material.CLAY_BALL
    44. && player.getInventory().getItemInHand().getItemMeta().getDisplayName().equalsIgnoreCase("§4Deflector Stone")) {
    45. return true;
    46. }
    47. }
    48. }
    49. return false;
    50. }


    If it doesn't work, then please provide these details:
    1. What are you expecting to happen ?
    2. What do you observe happening ? (when you test it)

    Thanks, Good luck!
     
  4. Offline

    moo3oo3oo3

    I want the fireball to go the opposite direction it was originally going. There are no console errors
     
Thread Status:
Not open for further replies.

Share This Page