SteamWar/BungeeCore
Archiviert
13
2

Update AlertCommand
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Dieser Commit ist enthalten in:
yoyosource 2022-06-14 20:03:40 +02:00
Ursprung 8823368f0d
Commit 08fdc1603e

Datei anzeigen

@ -21,49 +21,28 @@ package de.steamwar.bungeecore.commands;
import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.Message;
import de.steamwar.bungeecore.bot.SteamwarDiscordBot; 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.ChatColor;
import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.CommandSender;
public class AlertCommand extends BasicCommand { public class AlertCommand extends SWCommand {
public AlertCommand() { public AlertCommand() {
super("alert", "bungeecore.alert", "broadcast", "bbc"); super("alert", "bungeecore.alert", "broadcast", "bbc");
} }
@Override @Register(description = "USAGE_ALERT")
public void execute(CommandSender sender, String[] args) { public void broadcast(CommandSender sender, @OptionalValue("") @StaticValue("-discord") String sendToDiscord, String... message) {
if(args.length == 0){ if (message.length == 0) {
Message.send("USAGE_ALERT", sender); ChatSender.of(sender).system(new Message("USAGE_ALERT"));
return; return;
} }
String s; String s = String.join(" ", message);
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)); Message.broadcast("ALERT", ChatColor.translateAlternateColorCodes('&', s));
if (discordAnnounce && SteamwarDiscordBot.instance() != null) { if ("-discord".equals(sendToDiscord) && SteamwarDiscordBot.instance() != null) {
SteamwarDiscordBot.instance().getAnnouncementListener().announce(s); 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();
}
} }