Location locUnder = event.getTo().clone().add(0.0, -0.1, 0.0);
int blockUnder = match.getWorld().getBlockTypeIdAt(locUnder);
boolean onGround = (blockUnder != Material.AIR.getId());
AutoRefPlayer apl = match.getPlayer(player);
if (apl == null)
{
// if the player is not on a team and has left the start area, teleport back
if (!match.isSpectator(player) && !match.inStartRegion(event.getTo()) && onGround)
{
player.teleport(match.getWorldSpawn());
player.setFallDistance(0.0f);
}
return;
}
AutoRefTeam team = apl.getTeam();
if (team == null) return;
// announce region (for cosmetic regions)
for (AutoRefRegion reg : team.getRegions())
if (reg.getName() != null && reg.isEnterEvent(event)) reg.announceRegion(apl);
double fallspeed = event.getFrom().getY() - event.getTo().getY();
Location exit = apl.getExitLocation();
// don't bother if the player isn't in survival mode
if (player.getGameMode() != GameMode.SURVIVAL
|| match.inStartRegion(event.getTo())) return;
// if a player leaves the start region...
if (!match.inStartRegion(event.getTo()))
{
if (match.getCurrentState().inProgress())
{
// if they are leaving the start region, clear everything
if (match.inStartRegion(event.getFrom()) && !apl.isActive()) apl.reset();
// one way or another, the player is now active
apl.setActive();
}
else if (match.getCurrentState().isBeforeMatch())
{ if (onGround) apl.die(null, false); return; }
}
// if they have left their region, mark their exit location
if (!team.canEnter(event.getTo(), 0.3) && !player.isSleeping())
{
// player is sneaking off the edge and not in freefall
if (player.isSneaking() && team.canEnter(event.getTo()) && fallspeed < FREEFALL_THRESHOLD);
// if there is no exit position, set the exit position
else if (exit == null) apl.setExitLocation(player.getLocation());
// if there is an exit position and they aren't falling, kill them
else if (exit != null && fallspeed < FREEFALL_THRESHOLD && onGround)
apl.die(AutoRefPlayer.VOID_DEATH, true);
}
// player inside region
else
{
// if there is an exit location
if (exit != null)
{
// if the player traveled too far through the void, kill them
if (player.getLocation().distance(exit) > SAFE_TRAVEL_DISTANCE)
apl.die(AutoRefPlayer.VOID_DEATH, true);
// reset exit location since player in region
apl.setExitLocation(null);
}
}
}