From 08fdc1603eab41dd2341e10b2fae63422684ff1d Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 14 Jun 2022 20:03:40 +0200 Subject: [PATCH] Update AlertCommand --- .../bungeecore/commands/AlertCommand.java | 39 +++++-------------- 1 file changed, 9 insertions(+), 30 deletions(-) diff --git a/src/de/steamwar/bungeecore/commands/AlertCommand.java b/src/de/steamwar/bungeecore/commands/AlertCommand.java index a271cf8..9eb32d3 100644 --- a/src/de/steamwar/bungeecore/commands/AlertCommand.java +++ b/src/de/steamwar/bungeecore/commands/AlertCommand.java @@ -21,49 +21,28 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.bot.SteamwarDiscordBot; +import de.steamwar.command.SWCommand; +import de.steamwar.messages.ChatSender; import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.CommandSender; -public class AlertCommand extends BasicCommand { +public class AlertCommand extends SWCommand { public AlertCommand() { super("alert", "bungeecore.alert", "broadcast", "bbc"); } - @Override - public void execute(CommandSender sender, String[] args) { - if(args.length == 0){ - Message.send("USAGE_ALERT", sender); + @Register(description = "USAGE_ALERT") + public void broadcast(CommandSender sender, @OptionalValue("") @StaticValue("-discord") String sendToDiscord, String... message) { + if (message.length == 0) { + ChatSender.of(sender).system(new Message("USAGE_ALERT")); return; } - String s; - boolean discordAnnounce = false; - if (args[0].equals("-discord")) { - if (args.length == 1) { - Message.send("USAGE_ALERT", sender); - return; - } - discordAnnounce = true; - s = join(1, args); - } else { - s = join(0, args); - } - + String s = String.join(" ", message); Message.broadcast("ALERT", ChatColor.translateAlternateColorCodes('&', s)); - if (discordAnnounce && SteamwarDiscordBot.instance() != null) { + if ("-discord".equals(sendToDiscord) && SteamwarDiscordBot.instance() != null) { SteamwarDiscordBot.instance().getAnnouncementListener().announce(s); } } - - private String join(int startIndex, String... strings) { - StringBuilder st = new StringBuilder(); - for (int i = startIndex; i < strings.length; i++) { - if (i != startIndex) { - st.append(" "); - } - st.append(strings[i]); - } - return st.toString(); - } }