From 7b055a37be47b751466b737db2c13e1d49413bad Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Wed, 30 Dec 2020 17:11:02 +0100 Subject: [PATCH] Improve Tracking --- .../fightsystem/listener/ArrowStopper.java | 34 +++++++------------ 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/ArrowStopper.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/ArrowStopper.java index b44b38e..8a9ac68 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/ArrowStopper.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/ArrowStopper.java @@ -37,7 +37,7 @@ public class ArrowStopper extends BasicListener { private BukkitTask task; private static final Vector NULL_VECTOR = new Vector(0, 0, 0); - + private static final BlockFace[] BLOCK_FACES = {BlockFace.UP, BlockFace.DOWN, BlockFace.EAST, BlockFace.WEST, BlockFace.NORTH, BlockFace.SOUTH}; public ArrowStopper() { super(Config.TechhiderActive ? EnumSet.of(FightState.RUNNING) : EnumSet.noneOf(FightState.class)); } @@ -74,28 +74,20 @@ public class ArrowStopper extends BasicListener { private boolean checkBlocks(Block start, Block end) { Block cursor = start; - while (cursor.getY() != end.getY()) { - boolean negativ = cursor.getY() - end.getY() < 0; - BlockFace face = negativ?BlockFace.UP:BlockFace.DOWN; + while (!cursor.getLocation().equals(end.getLocation())) { + BlockFace nearest = BlockFace.SELF; + double nearestDistance = cursor.getLocation().distance(end.getLocation()); + for (BlockFace face : BLOCK_FACES) { + Block relative = cursor.getRelative(face); + double distance = relative.getLocation().distance(end.getLocation()); + if(distance < nearestDistance) { + nearestDistance = distance; + nearest = face; + } + } + cursor = cursor.getRelative(nearest); if(checkBlock(cursor)) return true; - cursor = cursor.getRelative(face); - } - - while (cursor.getX() != end.getX()) { - boolean negativ = cursor.getX() - end.getX() < 0; - BlockFace face = negativ?BlockFace.EAST:BlockFace.WEST; - if(checkBlock(cursor)) - return true; - cursor = cursor.getRelative(face); - } - - while (cursor.getZ() != end.getZ()) { - boolean negativ = cursor.getZ() - end.getZ() < 0; - BlockFace face = negativ?BlockFace.SOUTH:BlockFace.NORTH; - if(checkBlock(cursor)) - return true; - cursor = cursor.getRelative(face); } return false;