use of net.dzikoysk.funnyguilds.event.rank.DeathsChangeEvent in project FunnyGuilds by FunnyGuilds.
the class AxcDeaths method execute.
@Override
public void execute(CommandSender sender, String[] args) {
MessagesConfig messages = Messages.getInstance();
if (args.length < 1) {
sender.sendMessage(messages.generalNoNickGiven);
return;
}
if (!UserUtils.playedBefore(args[0])) {
sender.sendMessage(messages.generalNotPlayedBefore);
return;
}
if (args.length < 2) {
sender.sendMessage(messages.adminNoDeathsGiven);
return;
}
int deaths;
try {
deaths = Integer.valueOf(args[1]);
} catch (NumberFormatException e) {
sender.sendMessage(messages.adminErrorInNumber.replace("{ERROR}", args[1]));
return;
}
User user = User.get(args[0]);
Rank userRank = user.getRank();
int change = deaths - userRank.getDeaths();
User admin = (sender instanceof Player) ? User.get(sender.getName()) : null;
if (!SimpleEventHandler.handle(new DeathsChangeEvent(admin == null ? EventCause.CONSOLE : EventCause.ADMIN, userRank, admin, change))) {
return;
}
userRank.setDeaths(deaths);
sender.sendMessage(messages.adminDeathsChanged.replace("{PLAYER}", user.getName()).replace("{DEATHS}", Integer.toString(deaths)));
}
Aggregations