Search in sources :

Example 6 with User

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

the class EloHandler method handleGameEnd.

/**
 * Handles the elo calculation for generic games
 *
 * @param game  the game that ended
 * @param users the users which played this game, in order, first = winner
 */
public void handleGameEnd(@Nonnull Game game, @Nonnull User... users) {
    List<ITeam> teams = new ArrayList<>();
    for (User user : users) {
        teams.add(new jskills.Team(user, user.getRating(game.getGameMode())));
    }
    Map<IPlayer, Rating> newRatings = calculator.calculateNewRatings(game.getGameMode(), teams, IntStream.of(users.length).toArray());
    update(game, newRatings);
}
Also used : IPlayer(jskills.IPlayer) User(com.voxelgameslib.voxelgameslib.components.user.User) Rating(jskills.Rating) ArrayList(java.util.ArrayList) ITeam(jskills.ITeam)

Example 7 with User

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

the class TeamSelectFeature method disable.

@Override
public void disable() {
    Map<String, Integer> sizes = calcSizes();
    // add everyone who isn't in a team yet to the smallest team
    for (User user : getPhase().getGame().getPlayers()) {
        if (!getTeam(user).isPresent()) {
            Team t = getTeam(findSmallest(sizes)).orElseThrow(() -> new RuntimeException("Null team encountered"));
            t.join(user, user.getRating(getPhase().getGame().getGameMode()));
            Lang.msg(user, LangKey.TEAM_AUTO_ASSIGNED, t.getName());
            sizes.put(t.getName(), sizes.get(t.getName()) + 1);
        }
    }
    // make teams balanced
    balance();
    // save teams for next phase
    DefaultGameData defaultGameData = getPhase().getGame().getGameData(DefaultGameData.class).orElse(new DefaultGameData());
    defaultGameData.teams = teams;
    getPhase().getGame().putGameData(defaultGameData);
}
Also used : User(com.voxelgameslib.voxelgameslib.components.user.User) Team(com.voxelgameslib.voxelgameslib.components.team.Team) DefaultGameData(com.voxelgameslib.voxelgameslib.api.game.DefaultGameData)

Example 8 with User

use of com.voxelgameslib.voxelgameslib.components.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.components.user.User) GamePlayer(com.voxelgameslib.voxelgameslib.components.user.GamePlayer) Nonnull(javax.annotation.Nonnull)

Example 9 with User

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

Example 10 with User

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

the class SignListener method signBreakEvent.

@EventHandler
public void signBreakEvent(@Nonnull BlockBreakEvent event) {
    // is block a sign?
    if (event.getBlock().getState() instanceof Sign) {
        User user = userHandler.getUser(event.getPlayer().getUniqueId()).orElseThrow(() -> new UserException("Unknown user " + event.getPlayer().getDisplayName() + "(" + event.getPlayer().getUniqueId() + ")"));
        Sign sign = (Sign) event.getBlock().getState();
        for (int i = 0; i < sign.getLines().length; i++) {
            String line = sign.getLines()[i];
            for (String key : signHandler.getSignPlaceholders().getPlaceHolders().keySet()) {
                if (line.contains("%" + key + "%")) {
                    // has user permission for that?
                    if (user.hasPermission(placeHolderSignBreak)) {
                        Lang.msg(user, LangKey.SIGNS_BREAK_SUCCESS, key);
                        event.getBlock().setType(Material.AIR);
                        return;
                    } else {
                        event.setCancelled(true);
                        Lang.msg(user, LangKey.SIGNS_BREAK_NO_PERM, key, placeHolderSignBreak.getRole().getName());
                        return;
                    }
                }
            }
            for (String key : signHandler.getSignButtons().getButtons().keySet()) {
                if (line.contains("%" + key + "%")) {
                    // has user permission for that?
                    if (user.hasPermission(buttonSignBreak)) {
                        Lang.msg(user, LangKey.SIGNS_BREAK_SUCCESS, key);
                        event.getBlock().setType(Material.AIR);
                        return;
                    } else {
                        event.setCancelled(true);
                        Lang.msg(user, LangKey.SIGNS_BREAK_NO_PERM, key, buttonSignBreak.getRole().getName());
                        return;
                    }
                }
            }
        }
    }
}
Also used : User(com.voxelgameslib.voxelgameslib.components.user.User) Sign(org.bukkit.block.Sign) UserException(com.voxelgameslib.voxelgameslib.api.exception.UserException) EventHandler(org.bukkit.event.EventHandler)

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