@EventHandler(priority=EventPriority.MONITOR)
public void playerQuit(PlayerQuitEvent event)
{
Player player = event.getPlayer();
AutoRefMatch match = plugin.getMatch(player.getWorld());
if (match == null) return;
// leave the team, if necessary
AutoRefTeam team = plugin.getTeam(player);
if (team != null) match.messageReferees("player", player.getName(), "logout");
if (team != null && !match.getCurrentState().inProgress()) team.leave(player);
AutoRefPlayer apl = match.getPlayer(player);
if (apl != null && player.getLocation() != null)
apl.setLastLogoutLocation(player.getLocation());
// if this player was damaged recently (during the match), notify
if (match.getCurrentState().inProgress() && apl != null && !apl.isDead() && apl.wasDamagedRecently())
{
String message = apl.getDisplayName() + ChatColor.GRAY + " logged out during combat " +
String.format("with %2.1f hearts remaining", apl.getPlayer().getHealth() / 2.0);
for (Player ref : match.getReferees(true)) ref.sendMessage(message);
}
}