Search in sources :

Example 11 with User

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);
}
Also used : User(com.voxelgameslib.voxelgameslib.user.User) VoxelGameLibException(com.voxelgameslib.voxelgameslib.exception.VoxelGameLibException) Team(com.voxelgameslib.voxelgameslib.components.team.Team) VictoryCondition(com.voxelgameslib.voxelgameslib.condition.VictoryCondition) EmptyVictoryCondition(com.voxelgameslib.voxelgameslib.condition.conditions.EmptyVictoryCondition)

Example 12 with User

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)));
}
Also used : PlayerJoinEvent(org.bukkit.event.player.PlayerJoinEvent) UserHandler(com.voxelgameslib.voxelgameslib.user.UserHandler) Logger(java.util.logging.Logger) GameLeaveEvent(com.voxelgameslib.voxelgameslib.event.events.game.GameLeaveEvent) Inject(javax.inject.Inject) EventHandler(org.bukkit.event.EventHandler) VoxelGamesLib(com.voxelgameslib.voxelgameslib.VoxelGamesLib) UserException(com.voxelgameslib.voxelgameslib.exception.UserException) PlayerQuitEvent(org.bukkit.event.player.PlayerQuitEvent) User(com.voxelgameslib.voxelgameslib.user.User) Nonnull(javax.annotation.Nonnull) GameJoinEvent(com.voxelgameslib.voxelgameslib.event.events.game.GameJoinEvent) Bukkit(org.bukkit.Bukkit) Listener(org.bukkit.event.Listener) User(com.voxelgameslib.voxelgameslib.user.User) UserException(com.voxelgameslib.voxelgameslib.exception.UserException) EventHandler(org.bukkit.event.EventHandler)

Aggregations

User (com.voxelgameslib.voxelgameslib.user.User)12 Nonnull (javax.annotation.Nonnull)4 EventHandler (org.bukkit.event.EventHandler)4 Team (com.voxelgameslib.voxelgameslib.components.team.Team)3 UserException (com.voxelgameslib.voxelgameslib.exception.UserException)3 Logger (java.util.logging.Logger)3 Sign (org.bukkit.block.Sign)3 VoxelGamesLib (com.voxelgameslib.voxelgameslib.VoxelGamesLib)2 GameLeaveEvent (com.voxelgameslib.voxelgameslib.event.events.game.GameLeaveEvent)2 DefaultGameData (com.voxelgameslib.voxelgameslib.game.DefaultGameData)2 UserHandler (com.voxelgameslib.voxelgameslib.user.UserHandler)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Optional (java.util.Optional)2 Inject (javax.inject.Inject)2 Singleton (javax.inject.Singleton)2 IPlayer (jskills.IPlayer)2 Bukkit (org.bukkit.Bukkit)2 Listener (org.bukkit.event.Listener)2