From d4123d137a2e63b690c5331c7070bb01354384d0 Mon Sep 17 00:00:00 2001 From: Tobias Ottenweller Date: Mon, 12 Mar 2012 22:44:24 +0100 Subject: [PATCH] PluginPlayerListener cleanup --- .../listeners/PluginPlayerListener.java | 28 ++++++++----------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/src/org/mcteam/ancientgates/listeners/PluginPlayerListener.java b/src/org/mcteam/ancientgates/listeners/PluginPlayerListener.java index 70573ce..e3f1c20 100644 --- a/src/org/mcteam/ancientgates/listeners/PluginPlayerListener.java +++ b/src/org/mcteam/ancientgates/listeners/PluginPlayerListener.java @@ -34,25 +34,24 @@ public class PluginPlayerListener implements Listener // Find the nearest gate! Gate nearestGate = null; Location playerLocation = event.getPlayer().getLocation(); - //double shortestDistance = -1; for (Gate gate : Gate.getAll()) { - if (gate.getFrom() == null || gate.getTo() == null) + if (gate.getFrom() == null || + gate.getTo() == null || + gate.isOpen() == false || + !gate.getFrom().getWorld().equals(playerLocation.getWorld())) + { continue; - - - if (! gate.getFrom().getWorld().equals(playerLocation.getWorld())) - continue; // We can only be close to gates in the same world - - + } + double distance = GeometryUtil.distanceBetweenLocations(playerLocation, gate.getFrom()); if (distance > Conf.getGateSearchRadius()) continue; + Plugin.log(Level.ALL, "in gate search radius of " + gate.getId()); - Plugin.log(Level.ALL, "in gate search radius."); for (Integer[] blockXYZ: gate.getGateBlocks()) { if ((blockTo.getX() == blockXYZ[0] || blockToUp.getX() == blockXYZ[0]) && @@ -63,15 +62,10 @@ public class PluginPlayerListener implements Listener break; } } - - /*if (shortestDistance == -1 || shortestDistance > distance) { - nearestGate = gate; - shortestDistance = distance; - }*/ - } + } - if (nearestGate != null && nearestGate.isOpen()) - { + if (nearestGate != null) + { checkChunkLoad(nearestGate.getTo().getBlock()); Float newYaw = nearestGate.getFrom().getYaw() - nearestGate.getTo().getYaw() + playerLocation.getYaw(); Location teleportToLocation = new Location( nearestGate.getTo().getWorld(),