Search in sources :

Example 1 with KillsChangeEvent

use of net.dzikoysk.funnyguilds.event.rank.KillsChangeEvent in project FunnyGuilds by FunnyGuilds.

the class AxcKills 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.adminNoKillsGiven);
        return;
    }
    int kills;
    try {
        kills = 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 = kills - userRank.getDeaths();
    User admin = (sender instanceof Player) ? User.get(sender.getName()) : null;
    if (!SimpleEventHandler.handle(new KillsChangeEvent(admin == null ? EventCause.CONSOLE : EventCause.ADMIN, userRank, admin, change))) {
        return;
    }
    user.getRank().setKills(kills);
    sender.sendMessage(messages.adminKillsChanged.replace("{PLAYER}", user.getName()).replace("{KILLS}", Integer.toString(kills)));
}
Also used : Player(org.bukkit.entity.Player) User(net.dzikoysk.funnyguilds.basic.User) Rank(net.dzikoysk.funnyguilds.basic.Rank) MessagesConfig(net.dzikoysk.funnyguilds.data.configs.MessagesConfig) KillsChangeEvent(net.dzikoysk.funnyguilds.event.rank.KillsChangeEvent)

Aggregations

Rank (net.dzikoysk.funnyguilds.basic.Rank)1 User (net.dzikoysk.funnyguilds.basic.User)1 MessagesConfig (net.dzikoysk.funnyguilds.data.configs.MessagesConfig)1 KillsChangeEvent (net.dzikoysk.funnyguilds.event.rank.KillsChangeEvent)1 Player (org.bukkit.entity.Player)1