private void autoSideboard() { for (MatchPlayer player : match.getPlayers()) { if (!player.isDoneSideboarding()) { match.submitDeck(player.getPlayer().getId(), player.generateDeck()); } } }
public synchronized void leaveTable(UUID userId) { if (table == null) { logger.error("No table object - userId: " + userId); return; } if (table.isTournament() && tournament == null) { logger.error("No tournament object - userId: " + userId + " table: " + table.getId()); return; } if (table != null && this.userId != null && this.userId.equals(userId) // tourn. sub tables have no creator user && (table.getState().equals(TableState.WAITING) || table.getState().equals(TableState.READY_TO_START))) { // table not started yet and user is the owner, remove the table TableManager.getInstance().removeTable(table.getId()); } else { UUID playerId = userPlayerMap.get(userId); if (playerId != null) { if (table.getState() == TableState.WAITING || table.getState() == TableState.READY_TO_START) { table.leaveNotStartedTable(playerId); if (table.isTournament()) { tournament.removePlayer(playerId); } else { match.quitMatch(playerId); } User user = UserManager.getInstance().getUser(userId); if (user != null) { ChatManager.getInstance() .broadcast( chatId, user.getName(), "has left the table", ChatMessage.MessageColor.BLUE, true, ChatMessage.MessageType.STATUS, ChatMessage.SoundToPlay.PlayerLeft); if (!table.isTournamentSubTable()) { user.removeTable(playerId); } } else { logger.debug("User not found - userId: " + userId + " tableId:" + table.getId()); } userPlayerMap.remove(userId); } else if (!table.getState().equals(TableState.FINISHED)) { if (table.isTournament()) { logger.debug("Quit tournament sub tables for userId: " + userId); TableManager.getInstance().userQuitTournamentSubTables(tournament.getId(), userId); logger.debug( "Quit tournament Id: " + table.getTournament().getId() + "(" + table.getTournament().getTournamentState() + ")"); TournamentManager.getInstance().quit(tournament.getId(), userId); } else { MatchPlayer matchPlayer = match.getPlayer(playerId); if (matchPlayer != null && !match.hasEnded() && !matchPlayer.hasQuit()) { Game game = match.getGame(); if (game != null && !game.hasEnded()) { Player player = match.getPlayer(playerId).getPlayer(); if (player != null && player.isInGame()) { GameManager.getInstance().quitMatch(game.getId(), userId); } match.quitMatch(playerId); } else { if (table.getState().equals(TableState.SIDEBOARDING)) { if (!matchPlayer.isDoneSideboarding()) { // submit deck to finish sideboarding and trigger match start / end matchPlayer.submitDeck(matchPlayer.getDeck()); } } match.quitMatch(playerId); } } } } } else { logger.error("No playerId found for userId: " + userId); } } }