for (TournamentPairing pair: round.getPairs()) {
Match match = pair.getMatch();
if (match != null && match.hasEnded()) {
TournamentPlayer tp1 = pair.getPlayer1();
TournamentPlayer tp2 = pair.getPlayer2();
MatchPlayer mp1 = match.getPlayer(pair.getPlayer1().getPlayer().getId());
MatchPlayer mp2 = match.getPlayer(pair.getPlayer2().getPlayer().getId());
// set player state if he finished the round
if (round.getRoundNumber() == rounds.size()) { // for elimination getRoundNumber = 0 so never true here
match.setTournamentRound(round.getRoundNumber());
if (tp1.getState().equals(TournamentPlayerState.DUELING)) {
if (round.getRoundNumber() == getNumberRounds()) {
tp1.setState(TournamentPlayerState.FINISHED);
} else {
tp1.setState(TournamentPlayerState.WAITING);
}
}
if (tp2.getState().equals(TournamentPlayerState.DUELING)) {
if (round.getRoundNumber() == getNumberRounds()) {
tp2.setState(TournamentPlayerState.FINISHED);
} else {
tp2.setState(TournamentPlayerState.WAITING);
}
}
}
// Add round result
tp1.setResults(addRoundResult(round.getRoundNumber(), pair, tp1, tp2));
tp2.setResults(addRoundResult(round.getRoundNumber(), pair, tp2, tp1));
// Add points
if (mp2.hasQuit() || mp1.getWins() > mp2.getWins()) {
tp1.setPoints(tp1.getPoints() + 3);
} else if (mp1.hasQuit() || mp1.getWins() < mp2.getWins()) {
tp2.setPoints(tp2.getPoints() + 3);
} else {
tp1.setPoints(tp1.getPoints() + 1);
tp2.setPoints(tp2.getPoints() + 1);
}