Archiviert
1
0

Merge pull request 'Update AlertCommand' (#372) from CommandAlert into master

Reviewed-on: SteamWar/BungeeCore#372
Reviewed-by: Lixfel <lixfel@steamwar.de>
Dieser Commit ist enthalten in:
Lixfel 2022-06-16 12:39:52 +02:00
Commit df9f6e44e3

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