use of com.voxelgameslib.voxelgameslib.user.User in project VoxelGamesLibv2 by VoxelGamesLib.
the class AbstractPhase method checkEnd.
private void checkEnd() {
// check all victory conditions
User winner = null;
Team winnerTeam = null;
for (VictoryCondition victoryCondition : victoryConditions) {
if (!victoryCondition.completed()) {
return;
}
if (victoryCondition.getWinner() != null) {
if (!victoryCondition.getWinner().equals(winner)) {
if (winner == null) {
if (winnerTeam != null && !winnerTeam.contains(victoryCondition.getWinner())) {
throw new VoxelGameLibException(victoryCondition.getName() + " defined a winner even tho we already have a winning team!");
}
winner = victoryCondition.getWinner();
} else {
throw new VoxelGameLibException(victoryCondition.getName() + " defined a different winner than one of the conditions before it!");
}
}
}
if (victoryCondition.getWinnerTeam() != null) {
if (!victoryCondition.getWinnerTeam().equals(winnerTeam)) {
if (winnerTeam == null) {
if (winner != null && !victoryCondition.getWinnerTeam().contains(winner)) {
throw new VoxelGameLibException(victoryCondition.getName() + " defined a winning team even tho we already have a winning user!");
} else {
winnerTeam = victoryCondition.getWinnerTeam();
}
} else {
throw new VoxelGameLibException(victoryCondition.getName() + " defined a different winning team than one of the conditions before it!");
}
}
}
}
// all done, end this game
getGame().endGame(winnerTeam, winner);
}
use of com.voxelgameslib.voxelgameslib.user.User in project VoxelGamesLibv2 by VoxelGamesLib.
the class GameListener method onLeave.
@EventHandler
public void onLeave(@Nonnull PlayerQuitEvent event) {
User user = userHandler.getUser(event.getPlayer().getUniqueId()).orElseThrow(() -> new UserException("Unknown user " + event.getPlayer().getDisplayName() + "(" + event.getPlayer().getUniqueId() + ")"));
gameHandler.getGames(event.getPlayer().getUniqueId(), true).forEach((game -> game.leave(user)));
}
Aggregations