diff --git a/src/de/craftinc/gates/GatesManager.java b/src/de/craftinc/gates/GatesManager.java index a7adac7..a7eaf78 100644 --- a/src/de/craftinc/gates/GatesManager.java +++ b/src/de/craftinc/gates/GatesManager.java @@ -244,13 +244,23 @@ public class GatesManager protected void fillGatesByLocation() { - int numGateBlocks = 0; + Set gateBlocks = new HashSet(); for (Gate g : gates) { - numGateBlocks += g.gateBlockLocations.size(); + + for (Location l : g.getGateBlockLocations()) { + gateBlocks.add(l); + + Location headLocation = new Location(l.getWorld(), + l.getX(), + l.getY()+1, + l.getZ()); + + gateBlocks.add(headLocation); + } } - gatesByLocation = new HashMap((int)(numGateBlocks*1.25)); + gatesByLocation = new HashMap((int)(gateBlocks.size()*1.25)); for (Gate g : gates) { this.addGateByLocations(g); @@ -291,8 +301,12 @@ public class GatesManager if (gateBlocks != null) { for (Location l : gateBlocks) { + SimpleLocation sl = new SimpleLocation(l); gatesByLocation.remove(sl); + + SimpleLocation headLocation = new SimpleLocation(l, true); + gatesByLocation.remove(headLocation); } } } @@ -313,8 +327,12 @@ public class GatesManager protected void addGateByLocations(final Gate g) { for (Location l : g.getGateBlockLocations()) { + SimpleLocation sl = new SimpleLocation(l); gatesByLocation.put(sl, g); + + SimpleLocation headLocation = new SimpleLocation(l, true); + gatesByLocation.put(headLocation, g); } } diff --git a/src/de/craftinc/gates/listeners/PlayerMoveListener.java b/src/de/craftinc/gates/listeners/PlayerMoveListener.java index 6332ceb..b7c23de 100644 --- a/src/de/craftinc/gates/listeners/PlayerMoveListener.java +++ b/src/de/craftinc/gates/listeners/PlayerMoveListener.java @@ -52,16 +52,16 @@ public class PlayerMoveListener implements Listener Gate gateAtLocation = gateManager.getGateAtLocation(event.getTo()); if (gateAtLocation == null) { - Location headTo = new Location(event.getTo().getWorld(), - event.getTo().getX(), - event.getTo().getY()+1.0, - event.getTo().getZ()); +// Location headTo = new Location(event.getTo().getWorld(), +// event.getTo().getX(), +// event.getTo().getY()+1.0, +// event.getTo().getZ()); +// +// gateAtLocation = gateManager.getGateAtLocation(headTo); - gateAtLocation = gateManager.getGateAtLocation(headTo); - - if (gateAtLocation == null) { +// if (gateAtLocation == null) { return; - } +// } } if (!gateAtLocation.isOpen()) { diff --git a/src/de/craftinc/gates/util/SimpleLocation.java b/src/de/craftinc/gates/util/SimpleLocation.java index b1986c3..ae75ff9 100644 --- a/src/de/craftinc/gates/util/SimpleLocation.java +++ b/src/de/craftinc/gates/util/SimpleLocation.java @@ -36,6 +36,22 @@ public class SimpleLocation this.y = l.getBlockY(); this.z = l.getBlockZ(); } + + + public SimpleLocation(Location l, boolean isHeadPosition) + { + this.world = l.getWorld().getName(); + + // Using Block coordinates makes it possible to compare block locations with player locations. + // There might be an offset of 1 otherwise. + this.x = l.getBlockX(); + this.y = l.getBlockY(); + this.z = l.getBlockZ(); + + if (isHeadPosition) { + this.y--; + } + } @Override