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()
|
protected void fillGatesByLocation()
|
||||||
{
|
{
|
||||||
int numGateBlocks = 0;
|
Set<Location> gateBlocks = new HashSet<Location>();
|
||||||
|
|
||||||
for (Gate g : gates) {
|
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) {
|
for (Gate g : gates) {
|
||||||
this.addGateByLocations(g);
|
this.addGateByLocations(g);
|
||||||
@ -291,8 +301,12 @@ public class GatesManager
|
|||||||
if (gateBlocks != null) {
|
if (gateBlocks != null) {
|
||||||
|
|
||||||
for (Location l : gateBlocks) {
|
for (Location l : gateBlocks) {
|
||||||
|
|
||||||
SimpleLocation sl = new SimpleLocation(l);
|
SimpleLocation sl = new SimpleLocation(l);
|
||||||
gatesByLocation.remove(sl);
|
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)
|
protected void addGateByLocations(final Gate g)
|
||||||
{
|
{
|
||||||
for (Location l : g.getGateBlockLocations()) {
|
for (Location l : g.getGateBlockLocations()) {
|
||||||
|
|
||||||
SimpleLocation sl = new SimpleLocation(l);
|
SimpleLocation sl = new SimpleLocation(l);
|
||||||
gatesByLocation.put(sl, g);
|
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());
|
Gate gateAtLocation = gateManager.getGateAtLocation(event.getTo());
|
||||||
|
|
||||||
if (gateAtLocation == null) {
|
if (gateAtLocation == null) {
|
||||||
Location headTo = new Location(event.getTo().getWorld(),
|
// Location headTo = new Location(event.getTo().getWorld(),
|
||||||
event.getTo().getX(),
|
// event.getTo().getX(),
|
||||||
event.getTo().getY()+1.0,
|
// event.getTo().getY()+1.0,
|
||||||
event.getTo().getZ());
|
// event.getTo().getZ());
|
||||||
|
//
|
||||||
|
// gateAtLocation = gateManager.getGateAtLocation(headTo);
|
||||||
|
|
||||||
gateAtLocation = gateManager.getGateAtLocation(headTo);
|
// if (gateAtLocation == null) {
|
||||||
|
|
||||||
if (gateAtLocation == null) {
|
|
||||||
return;
|
return;
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!gateAtLocation.isOpen()) {
|
if (!gateAtLocation.isOpen()) {
|
||||||
|
@ -36,6 +36,22 @@ public class SimpleLocation
|
|||||||
this.y = l.getBlockY();
|
this.y = l.getBlockY();
|
||||||
this.z = l.getBlockZ();
|
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
|
@Override
|
||||||
|
Loading…
x
Reference in New Issue
Block a user