From bab56f895ad1a1d70db758e97ba35562ea5a9a30 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 21 Aug 2021 17:43:12 +0200 Subject: [PATCH 1/2] 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(); } } From d623f474107339b45ccd36479811e0282688491e Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 22 Aug 2021 22:05:57 +0200 Subject: [PATCH 2/2] Fixup async Chat problems --- src/de/steamwar/bungeecore/bot/events/SchematicsManager.java | 2 +- .../steamwar/bungeecore/bot/listeners/IngameChatListener.java | 2 +- .../bungeecore/bot/listeners/ServerTeamChatListener.java | 2 +- src/de/steamwar/bungeecore/bot/util/DiscordSchemAlert.java | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/de/steamwar/bungeecore/bot/events/SchematicsManager.java b/src/de/steamwar/bungeecore/bot/events/SchematicsManager.java index 4052d84f..64809e18 100644 --- a/src/de/steamwar/bungeecore/bot/events/SchematicsManager.java +++ b/src/de/steamwar/bungeecore/bot/events/SchematicsManager.java @@ -67,7 +67,7 @@ public class SchematicsManager { if (message == null) { message = textChannel.sendMessage(messageBuilder.build()).complete(); } else { - message.editMessage(messageBuilder.build()).complete(); + message.editMessage(messageBuilder.build()).queue(); } } } diff --git a/src/de/steamwar/bungeecore/bot/listeners/IngameChatListener.java b/src/de/steamwar/bungeecore/bot/listeners/IngameChatListener.java index 626a26e2..ce635f30 100644 --- a/src/de/steamwar/bungeecore/bot/listeners/IngameChatListener.java +++ b/src/de/steamwar/bungeecore/bot/listeners/IngameChatListener.java @@ -63,6 +63,6 @@ public class IngameChatListener extends BasicDiscordListener { assert textChannel != null; MessageBuilder messageBuilder = new MessageBuilder(); messageBuilder.append(message.replace("&", "").replace("@everyone", "`@everyone`").replace("@here", "`@here`").replaceAll("<[@#]!?\\d+>", "`$0`")); - textChannel.sendMessage(messageBuilder.build()).complete(); + textChannel.sendMessage(messageBuilder.build()).queue(); } } diff --git a/src/de/steamwar/bungeecore/bot/listeners/ServerTeamChatListener.java b/src/de/steamwar/bungeecore/bot/listeners/ServerTeamChatListener.java index 432c2872..0f826735 100644 --- a/src/de/steamwar/bungeecore/bot/listeners/ServerTeamChatListener.java +++ b/src/de/steamwar/bungeecore/bot/listeners/ServerTeamChatListener.java @@ -54,6 +54,6 @@ public class ServerTeamChatListener extends BasicDiscordListener { assert textChannel != null; MessageBuilder messageBuilder = new MessageBuilder(); messageBuilder.append(message.replace("&", "")); - textChannel.sendMessage(messageBuilder.build()).complete(); + textChannel.sendMessage(messageBuilder.build()).queue(); } } diff --git a/src/de/steamwar/bungeecore/bot/util/DiscordSchemAlert.java b/src/de/steamwar/bungeecore/bot/util/DiscordSchemAlert.java index a01121bd..b4b4261e 100644 --- a/src/de/steamwar/bungeecore/bot/util/DiscordSchemAlert.java +++ b/src/de/steamwar/bungeecore/bot/util/DiscordSchemAlert.java @@ -49,7 +49,7 @@ public class DiscordSchemAlert { MessageBuilder messageBuilder = new MessageBuilder(); messageBuilder.setEmbeds(builder.build()); try { - dcUser.openPrivateChannel().complete().sendMessage(messageBuilder.build()).complete(); + dcUser.openPrivateChannel().complete().sendMessage(messageBuilder.build()).queue(); } catch (Exception e) { // Ignored } @@ -70,7 +70,7 @@ public class DiscordSchemAlert { messageBuilder.setEmbeds(builder.build()); messageBuilder.setActionRows(ActionRow.of(Button.success("tada", Emoji.fromUnicode("U+1F389")))); try { - dcUser.openPrivateChannel().complete().sendMessage(messageBuilder.build()).complete(); + dcUser.openPrivateChannel().complete().sendMessage(messageBuilder.build()).queue(); } catch (Exception e) { // Ignored }