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