Search in sources :

Example 11 with User

use of com.voxelgameslib.voxelgameslib.components.user.User in project VoxelGamesLibv2 by VoxelGamesLib.

the class EloHandler method update.

private void update(@Nonnull Game game, @Nonnull Map<IPlayer, Rating> newRatings) {
    for (IPlayer iPlayer : newRatings.keySet()) {
        if (!(iPlayer instanceof User)) {
            log.warning("WTF");
            continue;
        }
        User user = (User) iPlayer;
        user.saveRating(game.getGameMode(), newRatings.get(iPlayer));
        // TODO fixme
        log.info("New Rating for " + user.getRawDisplayName() + " is " + newRatings.get(iPlayer).getMean() + "(" + newRatings.get(iPlayer).getStandardDeviation() + ")");
    }
}
Also used : IPlayer(jskills.IPlayer) User(com.voxelgameslib.voxelgameslib.components.user.User)

Example 12 with User

use of com.voxelgameslib.voxelgameslib.components.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.components.user.User) VoxelGameLibException(com.voxelgameslib.voxelgameslib.api.exception.VoxelGameLibException) Team(com.voxelgameslib.voxelgameslib.components.team.Team) EmptyVictoryCondition(com.voxelgameslib.voxelgameslib.api.condition.conditions.EmptyVictoryCondition) VictoryCondition(com.voxelgameslib.voxelgameslib.api.condition.VictoryCondition)

Example 13 with User

use of com.voxelgameslib.voxelgameslib.components.user.User in project VoxelGamesLibv2 by VoxelGamesLib.

the class TeamSelectFeature method balance.

private void balance() {
    // TODO Balancing by rating
    Map<String, Integer> sizes = calcSizes();
    String large = findLargest(sizes);
    if (large == null || large.equals("")) {
        log.finer("no balancing");
        teams.stream().map(t -> t.getName() + ": " + t.getPlayers().size()).forEach(log::finer);
        return;
    }
    int largeCount = sizes.get(large);
    String small = findSmallest(sizes);
    int smallCount = sizes.get(small);
    log.finer("LARGE: " + large + " : " + largeCount);
    log.finer("SMALL: " + small + " : " + smallCount);
    if (!(largeCount == smallCount || largeCount == smallCount + 1)) {
        Team largeT = getTeam(large).orElseThrow(() -> new RuntimeException("Null team encountered"));
        Team smallT = getTeam(small).orElseThrow(() -> new RuntimeException("Null team encountered"));
        boolean switched = false;
        for (int i = largeT.getPlayers().size() - 1; i > 0; i--) {
            User player = largeT.getPlayers().get(i);
            // if(playerIsInParty) {TODO party handling for team select
            log.finer("SWITCH: " + player + " from " + large + " to " + small);
            largeT.leave(player);
            smallT.join(player, player.getRating(getPhase().getGame().getGameMode()));
            Lang.msg(player, LangKey.TEAM_AUTO_BALANCED, largeT.getName(), smallT.getName());
            switched = true;
            break;
        // }
        }
        if (!switched) {
            log.finer(largeT.getName());
            log.finer(largeT.getPlayers().size() + "");
            User player = largeT.getPlayers().get(largeT.getPlayers().size() - 1);
            largeT.leave(player);
            smallT.join(player, player.getRating(getPhase().getGame().getGameMode()));
            Lang.msg(player, LangKey.TEAM_AUTO_BALANCED, largeT.getName(), smallT.getName());
        }
        balance();
    }
}
Also used : User(com.voxelgameslib.voxelgameslib.components.user.User) CommandAlias(co.aikar.commands.annotation.CommandAlias) Expose(com.google.gson.annotations.Expose) GamePreLeaveEvent(com.voxelgameslib.voxelgameslib.api.event.events.game.GamePreLeaveEvent) HashMap(java.util.HashMap) AbstractFeatureCommand(com.voxelgameslib.voxelgameslib.api.feature.AbstractFeatureCommand) Logger(java.util.logging.Logger) Singleton(javax.inject.Singleton) Lang(com.voxelgameslib.voxelgameslib.internal.lang.Lang) ArrayList(java.util.ArrayList) List(java.util.List) AbstractFeature(com.voxelgameslib.voxelgameslib.api.feature.AbstractFeature) DefaultGameData(com.voxelgameslib.voxelgameslib.api.game.DefaultGameData) Map(java.util.Map) Team(com.voxelgameslib.voxelgameslib.components.team.Team) Optional(java.util.Optional) FeatureCommandImplementor(com.voxelgameslib.voxelgameslib.api.feature.FeatureCommandImplementor) ChatColor(org.bukkit.ChatColor) LangKey(com.voxelgameslib.voxelgameslib.internal.lang.LangKey) CommandPermission(co.aikar.commands.annotation.CommandPermission) GameEvent(com.voxelgameslib.voxelgameslib.api.event.GameEvent) Nonnull(javax.annotation.Nonnull) User(com.voxelgameslib.voxelgameslib.components.user.User) Team(com.voxelgameslib.voxelgameslib.components.team.Team)

Example 14 with User

use of com.voxelgameslib.voxelgameslib.components.user.User in project VoxelGamesLibv2 by VoxelGamesLib.

the class DuelFeature method enable.

@Override
public void enable() {
    if (getPhase().getGame().getPlayers().size() != 2) {
        getPhase().getGame().broadcastMessage(LangKey.DUEL_WRONG_PLAYER_COUNT, getPhase().getGame().getPlayers().size());
        getPhase().getGame().abortGame();
        return;
    }
    one = getPhase().getGame().getPlayers().get(0);
    two = getPhase().getGame().getPlayers().get(1);
    if (ThreadLocalRandom.current().nextBoolean()) {
        User temp = one;
        one = two;
        two = temp;
    }
}
Also used : User(com.voxelgameslib.voxelgameslib.components.user.User)

Aggregations

User (com.voxelgameslib.voxelgameslib.components.user.User)14 Nonnull (javax.annotation.Nonnull)5 Logger (java.util.logging.Logger)4 EventHandler (org.bukkit.event.EventHandler)4 UserException (com.voxelgameslib.voxelgameslib.api.exception.UserException)3 Team (com.voxelgameslib.voxelgameslib.components.team.Team)3 Lang (com.voxelgameslib.voxelgameslib.internal.lang.Lang)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Optional (java.util.Optional)3 Inject (javax.inject.Inject)3 Singleton (javax.inject.Singleton)3 Sign (org.bukkit.block.Sign)3 CommandAlias (co.aikar.commands.annotation.CommandAlias)2 CommandPermission (co.aikar.commands.annotation.CommandPermission)2 VoxelGamesLib (com.voxelgameslib.voxelgameslib.VoxelGamesLib)2 VoxelGameLibException (com.voxelgameslib.voxelgameslib.api.exception.VoxelGameLibException)2 DefaultGameData (com.voxelgameslib.voxelgameslib.api.game.DefaultGameData)2 UserHandler (com.voxelgameslib.voxelgameslib.components.user.UserHandler)2 Bukkit (org.bukkit.Bukkit)2