private boolean citizenFinalElectionHandler(List<Message> messages, Game game) { Map<Player, List<Player>> votes = game.getPlayerVote(); List<Player> usersEqualMaxVote = findMaxVoted(game, false); if (usersEqualMaxVote == null) { game.clearElection(); messages.add(new Message("nobody.was.killed.with.maximum.votes")); return true; } else { Player maxVoted = usersEqualMaxVote.get(0); int maxVoteNum = votes.get(maxVoted).size(); if (usersEqualMaxVote.size() == 1) { game.killPlayer(maxVoted); game.clearElection(); messages.add( new Message("player.was.killed.with.maximum.votes") .setArgs(maxVoted.getAccount().getUsername(), String.valueOf(maxVoteNum))); return true; } else { messages.add( new Message("nobody.was.killed.because.more.than.one.user.has.equal.vote") .setArgs( ListToString.toString( usersEqualMaxVote .stream() .map(Player::getAccount) .map(Account::getUsername) .collect(Collectors.toList())), String.valueOf(maxVoteNum))); return false; } } }
@Override public ResultMessage execute(ElectionFinishedCommandContext context) { List<Message> messages = new ArrayList<>(); if (context.isOnTimer()) messages.add(new Message("election.time.is.over")); Game game = context.getGame(); electionResult(messages, game, context); if (game.getElectionMood() == ElectionMood.FINAL_ELECTION) { boolean electionOver = citizenFinalElectionHandler(messages, game); if (electionOver) { messages.add(new Message("night.started.be.silent")); commandExecutor.run( context.getInterfaceContext(), Constants.CMD.Internal.NEXT_MOOD, new EmptyContext(context.getInterfaceContext(), game)); } } game.clearElection(); return new ResultMessage(messages, ChannelType.GENERAL, context.getInterfaceContext()); }