From bab56f895ad1a1d70db758e97ba35562ea5a9a30 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 21 Aug 2021 17:43:12 +0200 Subject: [PATCH] Add better AlertCommand --- .../bungeecore/commands/AlertCommand.java | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/src/de/steamwar/bungeecore/commands/AlertCommand.java b/src/de/steamwar/bungeecore/commands/AlertCommand.java index 02623cb8..db7c3b01 100644 --- a/src/de/steamwar/bungeecore/commands/AlertCommand.java +++ b/src/de/steamwar/bungeecore/commands/AlertCommand.java @@ -37,8 +37,33 @@ public class AlertCommand extends BasicCommand { return; } - String s = String.join(" ", args); + 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); + } + Message.broadcast("ALERT", ChatColor.translateAlternateColorCodes('&', s)); - SteamwarDiscordBot.instance().getAnnouncementListener().announce(s); + if (discordAnnounce) { + 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(); } }