Search in sources :

Example 1 with UserRank

use of net.dzikoysk.funnyguilds.user.UserRank in project FunnyGuilds by FunnyGuilds.

the class DeathsCommand method execute.

@FunnyCommand(name = "${admin.deaths.name}", permission = "funnyguilds.admin", acceptsExceeded = true)
public void execute(CommandSender sender, String[] args) {
    when(args.length < 1, messages.generalNoNickGiven);
    when(args.length < 2, messages.adminNoDeathsGiven);
    int deaths = Option.attempt(NumberFormatException.class, () -> Integer.parseInt(args[1])).orThrow(() -> {
        throw new ValidationException(messages.adminErrorInNumber.replace("{ERROR}", args[1]));
    });
    User admin = AdminUtils.getAdminUser(sender);
    User user = UserValidation.requireUserByName(args[0]);
    UserRank userRank = user.getRank();
    int change = deaths - userRank.getDeaths();
    DeathsChangeEvent deathsChangeEvent = new DeathsChangeEvent(AdminUtils.getCause(admin), admin, user, change);
    if (!SimpleEventHandler.handle(deathsChangeEvent)) {
        return;
    }
    change = deathsChangeEvent.getDeathsChange();
    int finalDeaths = user.getRank().getDeaths() + change;
    user.getRank().setDeaths(finalDeaths);
    sendMessage(sender, (messages.adminDeathsChanged.replace("{PLAYER}", user.getName()).replace("{DEATHS}", Integer.toString(finalDeaths))));
}
Also used : UserRank(net.dzikoysk.funnyguilds.user.UserRank) ValidationException(net.dzikoysk.funnycommands.resources.ValidationException) User(net.dzikoysk.funnyguilds.user.User) DeathsChangeEvent(net.dzikoysk.funnyguilds.event.rank.DeathsChangeEvent) AbstractFunnyCommand(net.dzikoysk.funnyguilds.feature.command.AbstractFunnyCommand) FunnyCommand(net.dzikoysk.funnycommands.stereotypes.FunnyCommand)

Example 2 with UserRank

use of net.dzikoysk.funnyguilds.user.UserRank in project FunnyGuilds by FunnyGuilds.

the class KillsCommand method execute.

@FunnyCommand(name = "${admin.kills.name}", permission = "funnyguilds.admin", acceptsExceeded = true)
public void execute(CommandSender sender, String[] args) {
    when(args.length < 1, messages.generalNoNickGiven);
    when(args.length < 2, messages.adminNoKillsGiven);
    int kills = Option.attempt(NumberFormatException.class, () -> Integer.parseInt(args[1])).orThrow(() -> {
        throw new ValidationException(messages.adminErrorInNumber.replace("{ERROR}", args[1]));
    });
    User admin = AdminUtils.getAdminUser(sender);
    User user = UserValidation.requireUserByName(args[0]);
    UserRank userRank = user.getRank();
    int change = kills - userRank.getKills();
    KillsChangeEvent killsChangeEvent = new KillsChangeEvent(AdminUtils.getCause(admin), admin, user, change);
    if (!SimpleEventHandler.handle(killsChangeEvent)) {
        return;
    }
    change = killsChangeEvent.getKillsChange();
    int finalKills = user.getRank().getKills() + change;
    user.getRank().setKills(finalKills);
    sendMessage(sender, (messages.adminKillsChanged.replace("{PLAYER}", user.getName()).replace("{KILLS}", Integer.toString(finalKills))));
}
Also used : UserRank(net.dzikoysk.funnyguilds.user.UserRank) ValidationException(net.dzikoysk.funnycommands.resources.ValidationException) User(net.dzikoysk.funnyguilds.user.User) KillsChangeEvent(net.dzikoysk.funnyguilds.event.rank.KillsChangeEvent) AbstractFunnyCommand(net.dzikoysk.funnyguilds.feature.command.AbstractFunnyCommand) FunnyCommand(net.dzikoysk.funnycommands.stereotypes.FunnyCommand)

Example 3 with UserRank

use of net.dzikoysk.funnyguilds.user.UserRank in project FunnyGuilds by FunnyGuilds.

the class PlayerInfoCommand method sendInfoMessage.

public void sendInfoMessage(List<String> baseMessage, User infoUser, CommandSender messageTarget) {
    UserRank rank = infoUser.getRank();
    for (String messageLine : baseMessage) {
        if (infoUser.hasGuild()) {
            Guild guild = infoUser.getGuild().get();
            messageLine = StringUtils.replace(messageLine, "{GUILD}", guild.getName());
            messageLine = StringUtils.replace(messageLine, "{TAG}", guild.getTag());
        } else {
            messageLine = StringUtils.replace(messageLine, "{GUILD}", messages.gNameNoValue);
            messageLine = StringUtils.replace(messageLine, "{TAG}", messages.gTagNoValue);
        }
        messageLine = StringUtils.replace(messageLine, "{PLAYER}", infoUser.getName());
        messageLine = StringUtils.replace(messageLine, "{POINTS-FORMAT}", NumberRange.inRangeToString(rank.getPoints(), config.pointsFormat));
        messageLine = StringUtils.replace(messageLine, "{POINTS}", Integer.toString(rank.getPoints()));
        messageLine = StringUtils.replace(messageLine, "{KILLS}", Integer.toString(rank.getKills()));
        messageLine = StringUtils.replace(messageLine, "{DEATHS}", Integer.toString(rank.getDeaths()));
        messageLine = StringUtils.replace(messageLine, "{ASSISTS}", Integer.toString(rank.getAssists()));
        messageLine = StringUtils.replace(messageLine, "{LOGOUTS}", Integer.toString(rank.getLogouts()));
        messageLine = StringUtils.replace(messageLine, "{KDR}", String.format(Locale.US, "%.2f", rank.getKDR()));
        messageLine = StringUtils.replace(messageLine, "{RANK}", Integer.toString(rank.getPosition(DefaultTops.USER_POINTS_TOP)));
        sendMessage(messageTarget, messageLine);
    }
}
Also used : UserRank(net.dzikoysk.funnyguilds.user.UserRank) Guild(net.dzikoysk.funnyguilds.guild.Guild)

Example 4 with UserRank

use of net.dzikoysk.funnyguilds.user.UserRank in project FunnyGuilds by FunnyGuilds.

the class PointsCommand method execute.

@FunnyCommand(name = "${admin.points.name}", permission = "funnyguilds.admin", acceptsExceeded = true)
public void execute(CommandSender sender, String[] args) {
    when(args.length < 1, messages.generalNoNickGiven);
    when(args.length < 2, messages.adminNoPointsGiven);
    int points;
    try {
        points = Integer.parseInt(args[1]);
    } catch (NumberFormatException numberFormatException) {
        sendMessage(sender, (messages.adminErrorInNumber.replace("{ERROR}", args[1])));
        return;
    }
    User user = UserValidation.requireUserByName(args[0]);
    UserRank userRank = user.getRank();
    User admin = AdminUtils.getAdminUser(sender);
    int change = points - userRank.getPoints();
    PointsChangeEvent pointsChangeEvent = new PointsChangeEvent(AdminUtils.getCause(admin), admin, user, change);
    if (!SimpleEventHandler.handle(pointsChangeEvent)) {
        return;
    }
    change = pointsChangeEvent.getPointsChange();
    int finalPoints = user.getRank().getPoints() + change;
    user.getRank().setPoints(finalPoints);
    String message = messages.adminPointsChanged.replace("{PLAYER}", user.getName());
    message = message.replace("{POINTS-FORMAT}", NumberRange.inRangeToString(finalPoints, config.pointsFormat));
    message = message.replace("{POINTS}", String.valueOf(finalPoints));
    sendMessage(sender, (message));
}
Also used : UserRank(net.dzikoysk.funnyguilds.user.UserRank) User(net.dzikoysk.funnyguilds.user.User) PointsChangeEvent(net.dzikoysk.funnyguilds.event.rank.PointsChangeEvent) AbstractFunnyCommand(net.dzikoysk.funnyguilds.feature.command.AbstractFunnyCommand) FunnyCommand(net.dzikoysk.funnycommands.stereotypes.FunnyCommand)

Example 5 with UserRank

use of net.dzikoysk.funnyguilds.user.UserRank in project FunnyGuilds by FunnyGuilds.

the class UserRecalculation method apply.

@Override
public NavigableSet<UserRank> apply(String id, TopComparator<UserRank> topComparator) {
    NavigableSet<UserRank> usersRank = new TreeSet<>(topComparator);
    PandaStream.of(userManager.getUsers()).filterNot(user -> this.pluginConfiguration.skipPrivilegedPlayersInRankPositions && PermissionUtils.isPrivileged(user, "funnyguilds.ranking.exempt")).map(User::getRank).forEach(usersRank::add);
    int position = 0;
    for (UserRank userRank : usersRank) {
        userRank.setPosition(id, ++position);
    }
    return usersRank;
}
Also used : UserRank(net.dzikoysk.funnyguilds.user.UserRank) TreeSet(java.util.TreeSet)

Aggregations

UserRank (net.dzikoysk.funnyguilds.user.UserRank)5 FunnyCommand (net.dzikoysk.funnycommands.stereotypes.FunnyCommand)3 AbstractFunnyCommand (net.dzikoysk.funnyguilds.feature.command.AbstractFunnyCommand)3 User (net.dzikoysk.funnyguilds.user.User)3 ValidationException (net.dzikoysk.funnycommands.resources.ValidationException)2 TreeSet (java.util.TreeSet)1 DeathsChangeEvent (net.dzikoysk.funnyguilds.event.rank.DeathsChangeEvent)1 KillsChangeEvent (net.dzikoysk.funnyguilds.event.rank.KillsChangeEvent)1 PointsChangeEvent (net.dzikoysk.funnyguilds.event.rank.PointsChangeEvent)1 Guild (net.dzikoysk.funnyguilds.guild.Guild)1