// Cast the sender, grab the argument, if any.
Player p = (Player) sender;
String arg1 = (args.length > 0 ? args[0] : null);
// Run some rough sanity checks, and grab the arena to join.
Arena toArena = Commands.getArenaToJoinOrSpec(am, p, arg1);
if (toArena == null) {
return true;
}
// Deny joining from other arenas
Arena fromArena = am.getArenaWithPlayer(p);
if (fromArena != null && (fromArena.inArena(p) || fromArena.inLobby(p))) {
Messenger.tell(p, Msg.JOIN_ALREADY_PLAYING);
return true;
}
// Per-arena sanity checks
if (!toArena.canJoin(p)) {
return true;
}
// Force leave previous arena
if (fromArena != null) fromArena.playerLeave(p);
// Join the arena!
return toArena.playerJoin(p, p.getLocation());
}