Better handling for players entering a gate with their head only.
This commit is contained in:
parent
8f54c0acc2
commit
e84130a8fe
@ -244,13 +244,23 @@ public class GatesManager
|
||||
|
||||
protected void fillGatesByLocation()
|
||||
{
|
||||
int numGateBlocks = 0;
|
||||
Set<Location> gateBlocks = new HashSet<Location>();
|
||||
|
||||
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<SimpleLocation, Gate>((int)(numGateBlocks*1.25));
|
||||
gatesByLocation = new HashMap<SimpleLocation, Gate>((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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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()) {
|
||||
|
@ -38,6 +38,22 @@ public class SimpleLocation
|
||||
}
|
||||
|
||||
|
||||
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
|
||||
public boolean equals(final Object o)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user