SteamWar/BungeeCore
Archiviert
13
2

Update AlertCommand #372

Zusammengeführt
Lixfel hat 1 Commits von CommandAlert nach master 2022-06-16 12:39:53 +02:00 zusammengeführt

Datei anzeigen

@ -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();
}
}