Search in sources :

Example 1 with User

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

the class ChatHandler method removeChannel.

/**
 * Removes a channel
 *
 * @param id the id of the channel that should be removed
 */
public void removeChannel(@Nonnull String id) {
    // remove any existing listeners from the channel, set them to the default channel.
    // you should *really* handle this yourself if you're removing a channel
    getChannel(id).ifPresent(chatChannel -> {
        Iterator<User> itr = chatChannel.getListeners().iterator();
        while (itr.hasNext()) {
            User user = itr.next();
            user.removeListeningChannel(id);
            if (user.getActiveChannel().equals(chatChannel)) {
                user.setActiveChannel("default");
            }
        }
    });
    activeChannels.remove(id);
}
Also used : User(com.voxelgameslib.voxelgameslib.user.User)

Example 2 with User

use of com.voxelgameslib.voxelgameslib.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 : CommandAlias(co.aikar.commands.annotation.CommandAlias) Expose(com.google.gson.annotations.Expose) LangKey(com.voxelgameslib.voxelgameslib.lang.LangKey) GameEvent(com.voxelgameslib.voxelgameslib.event.GameEvent) HashMap(java.util.HashMap) Logger(java.util.logging.Logger) Singleton(javax.inject.Singleton) DefaultGameData(com.voxelgameslib.voxelgameslib.game.DefaultGameData) Lang(com.voxelgameslib.voxelgameslib.lang.Lang) ArrayList(java.util.ArrayList) GameLeaveEvent(com.voxelgameslib.voxelgameslib.event.events.game.GameLeaveEvent) List(java.util.List) AbstractFeature(com.voxelgameslib.voxelgameslib.feature.AbstractFeature) Map(java.util.Map) Team(com.voxelgameslib.voxelgameslib.components.team.Team) Optional(java.util.Optional) FeatureCommandImplementor(com.voxelgameslib.voxelgameslib.feature.FeatureCommandImplementor) User(com.voxelgameslib.voxelgameslib.user.User) ChatColor(org.bukkit.ChatColor) CommandPermission(co.aikar.commands.annotation.CommandPermission) Nonnull(javax.annotation.Nonnull) AbstractFeatureCommand(com.voxelgameslib.voxelgameslib.feature.AbstractFeatureCommand) User(com.voxelgameslib.voxelgameslib.user.User) Team(com.voxelgameslib.voxelgameslib.components.team.Team)

Example 3 with User

use of com.voxelgameslib.voxelgameslib.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.user.User)

Example 4 with User

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

the class FeatureTest method getMockUser.

@Nonnull
public User getMockUser(@Nonnull String name) {
    User user = Mockito.spy(new GamePlayer());
    user.setDisplayName(name);
    return user;
}
Also used : User(com.voxelgameslib.voxelgameslib.user.User) GamePlayer(com.voxelgameslib.voxelgameslib.user.GamePlayer) Nonnull(javax.annotation.Nonnull)

Example 5 with User

use of com.voxelgameslib.voxelgameslib.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.user.User)

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