public synchronized void startTournament(UUID userId) { try { if (userId.equals(this.userId) && table.getState().equals(TableState.STARTING)) { tournament.setStartTime(); TournamentManager.getInstance() .createTournamentSession(tournament, userPlayerMap, table.getId()); for (Entry<UUID, UUID> entry : userPlayerMap.entrySet()) { User user = UserManager.getInstance().getUser(entry.getKey()); if (user != null) { logger.info( new StringBuilder("User ") .append(user.getName()) .append(" tournament started: ") .append(tournament.getId()) .append(" userId: ") .append(user.getId())); user.ccTournamentStarted(tournament.getId(), entry.getValue()); } } ServerMessagesUtil.getInstance().incTournamentsStarted(); } } catch (Exception ex) { logger.fatal("Error starting tournament", ex); TableManager.getInstance().removeTable(table.getId()); TournamentManager.getInstance().quit(tournament.getId(), userId); } }
private void submitDeck(UUID userId, UUID playerId, Deck deck) { if (table.getState() == TableState.SIDEBOARDING) { match.submitDeck(playerId, deck); UserManager.getInstance().getUser(userId).removeSideboarding(table.getId()); } else { TournamentManager.getInstance().submitDeck(tournament.getId(), playerId, deck); UserManager.getInstance().getUser(userId).removeConstructing(playerId); } }
private void updateDeck(UUID userId, UUID playerId, Deck deck) { if (table.isTournament()) { if (tournament != null) { TournamentManager.getInstance().updateDeck(tournament.getId(), playerId, deck); } else { logger.fatal("Tournament == null table: " + table.getId() + " userId: " + userId); } } else if (TableState.SIDEBOARDING.equals(table.getState())) { match.updateDeck(playerId, deck); } else { // deck was meanwhile submitted so the autoupdate can be ignored } }
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); } } }