Search in sources :

Example 1 with GuildLivesChangeEvent

use of net.dzikoysk.funnyguilds.event.guild.GuildLivesChangeEvent in project FunnyGuilds by FunnyGuilds.

the class AxcLives method execute.

@Override
public void execute(CommandSender sender, String[] args) {
    MessagesConfig messages = Messages.getInstance();
    if (args.length < 1) {
        sender.sendMessage(messages.generalNoTagGiven);
        return;
    }
    if (args.length < 2) {
        sender.sendMessage(messages.adminNoLivesGiven);
        return;
    }
    Guild guild = GuildUtils.getByTag(args[0]);
    if (guild == null) {
        sender.sendMessage(messages.generalNoGuildFound);
        return;
    }
    int lives;
    try {
        lives = Integer.valueOf(args[1]);
    } catch (NumberFormatException e) {
        sender.sendMessage(messages.adminErrorInNumber.replace("{ERROR}", args[1]));
        return;
    }
    User admin = (sender instanceof Player) ? User.get(sender.getName()) : null;
    if (!SimpleEventHandler.handle(new GuildLivesChangeEvent(admin == null ? EventCause.CONSOLE : EventCause.ADMIN, admin, guild, lives))) {
        return;
    }
    guild.setLives(lives);
    sender.sendMessage(messages.adminLivesChanged.replace("{GUILD}", guild.getTag()).replace("{LIVES}", Integer.toString(lives)));
}
Also used : Player(org.bukkit.entity.Player) User(net.dzikoysk.funnyguilds.basic.User) GuildLivesChangeEvent(net.dzikoysk.funnyguilds.event.guild.GuildLivesChangeEvent) MessagesConfig(net.dzikoysk.funnyguilds.data.configs.MessagesConfig) Guild(net.dzikoysk.funnyguilds.basic.Guild)

Aggregations

Guild (net.dzikoysk.funnyguilds.basic.Guild)1 User (net.dzikoysk.funnyguilds.basic.User)1 MessagesConfig (net.dzikoysk.funnyguilds.data.configs.MessagesConfig)1 GuildLivesChangeEvent (net.dzikoysk.funnyguilds.event.guild.GuildLivesChangeEvent)1 Player (org.bukkit.entity.Player)1