Search in sources :

Example 1 with GuildBanEvent

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

the class AxcBan method execute.

@Override
public void execute(CommandSender sender, String[] args) {
    MessagesConfig messages = Messages.getInstance();
    if (args.length < 1) {
        sender.sendMessage(messages.generalNoTagGiven);
        return;
    } else if (args.length < 2) {
        sender.sendMessage(messages.adminNoBanTimeGiven);
        return;
    } else if (args.length < 3) {
        sender.sendMessage(messages.adminNoReasonGiven);
        return;
    }
    Guild guild = GuildUtils.getByTag(args[0]);
    if (guild == null) {
        sender.sendMessage(messages.generalNoGuildFound);
        return;
    }
    if (guild.isBanned()) {
        sender.sendMessage(messages.adminGuildBanned);
        return;
    }
    long time = Parser.parseTime(args[1]);
    if (time < 1) {
        sender.sendMessage(messages.adminTimeError);
        return;
    }
    StringBuilder reasonBuilder = new StringBuilder();
    for (int i = 2; i < args.length; i++) {
        reasonBuilder.append(args[i]);
        reasonBuilder.append(" ");
    }
    String reason = reasonBuilder.toString();
    User admin = (sender instanceof Player) ? User.get(sender.getName()) : null;
    if (!SimpleEventHandler.handle(new GuildBanEvent(admin == null ? EventCause.CONSOLE : EventCause.ADMIN, admin, guild, time, reason))) {
        return;
    }
    BanUtils.ban(guild, time, reason);
    MessageTranslator translator = new MessageTranslator().register("{GUILD", guild.getName()).register("{TAG}", guild.getTag()).register("{TIME}", args[1]).register("{REASON}", StringUtils.colored(reason));
    sender.sendMessage(translator.translate(messages.adminGuildBan));
    Bukkit.broadcastMessage(translator.translate(messages.broadcastBan));
}
Also used : GuildBanEvent(net.dzikoysk.funnyguilds.event.guild.GuildBanEvent) Player(org.bukkit.entity.Player) User(net.dzikoysk.funnyguilds.basic.User) MessagesConfig(net.dzikoysk.funnyguilds.data.configs.MessagesConfig) Guild(net.dzikoysk.funnyguilds.basic.Guild) MessageTranslator(net.dzikoysk.funnyguilds.data.util.MessageTranslator)

Aggregations

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