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))));
}
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))));
}
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);
}
}
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));
}
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;
}
Aggregations