@EventHandler(priority=EventPriority.MONITOR)
public void playerMove(PlayerMoveEvent event)
{
Player player = event.getPlayer();
AutoRefMatch match = plugin.getMatch(player.getWorld());
if (match == null) return;
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())