}
public void quit(UUID userId) {
UUID playerId = userPlayerMap.get(userId);
if (playerId != null) {
TournamentPlayer tPlayer = tournament.getPlayer(playerId);
if (tPlayer != null) {
if (started) {
if (tPlayer.isInTournament()) {
String info;
if (tournament.isDoneConstructing()) {
info = new StringBuilder("during round ").append(tournament.getRounds().size()).toString();
// quit active matches of that tournament
TableManager.getInstance().userQuitTournamentSubTables(tournament.getId(), userId);
} else {
if (tPlayer.getState().equals(TournamentPlayerState.DRAFTING)) {
info = "during Draft phase";
if (!checkToReplaceDraftPlayerByAi(userId, tPlayer)) {
this.abortDraftTournament();
} else {
DraftController draftController = DraftManager.getInstance().getController(tableId);
if (draftController != null) {
DraftSession draftSession = draftController.getDraftSession(playerId);
if (draftSession != null) {
DraftManager.getInstance().kill(draftSession.getDraftId(), userId);
}
}
}
} else if (tPlayer.getState().equals(TournamentPlayerState.CONSTRUCTING)) {
info = "during Construction phase";
} else {
info = "";
}
}
tPlayer.setQuit(info);
tournament.quit(playerId);
if (tournamentSessions.containsKey(playerId)) {
tournamentSessions.get(tPlayer.getPlayer().getId()).quit();
}
ChatManager.getInstance().broadcast(chatId, "", tPlayer.getPlayer().getName() + " has quit the tournament", MessageColor.BLACK, true, MessageType.STATUS, SoundToPlay.PlayerQuitTournament);
}
} else {
tournament.leave(playerId);
}
}