From a5669ef7e2b1baa77398b5db48b55061096652e0 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 5 Mar 2022 12:25:45 +0100 Subject: [PATCH] Fix possible exceptions --- src/de/steamwar/bungeecore/commands/AlertCommand.java | 2 +- .../bungeecore/commands/ServerTeamchatCommand.java | 10 ++++++---- src/de/steamwar/bungeecore/listeners/ChatListener.java | 10 ++++++---- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/de/steamwar/bungeecore/commands/AlertCommand.java b/src/de/steamwar/bungeecore/commands/AlertCommand.java index db7c3b0..a271cf8 100644 --- a/src/de/steamwar/bungeecore/commands/AlertCommand.java +++ b/src/de/steamwar/bungeecore/commands/AlertCommand.java @@ -51,7 +51,7 @@ public class AlertCommand extends BasicCommand { } Message.broadcast("ALERT", ChatColor.translateAlternateColorCodes('&', s)); - if (discordAnnounce) { + if (discordAnnounce && SteamwarDiscordBot.instance() != null) { SteamwarDiscordBot.instance().getAnnouncementListener().announce(s); } } diff --git a/src/de/steamwar/bungeecore/commands/ServerTeamchatCommand.java b/src/de/steamwar/bungeecore/commands/ServerTeamchatCommand.java index f9c589b..7207e0a 100644 --- a/src/de/steamwar/bungeecore/commands/ServerTeamchatCommand.java +++ b/src/de/steamwar/bungeecore/commands/ServerTeamchatCommand.java @@ -54,10 +54,12 @@ public class ServerTeamchatCommand extends BasicCommand { String msg = msgBuilder.toString(); msg = ChatColor.translateAlternateColorCodes('&', msg); - try { - SteamwarDiscordBot.instance().getServerTeamChatListener().send(" " + (player.getName() + "» " + msg).replaceAll("§[a-f0-9r]", "")); - } catch (Exception e) { - BungeeCore.get().getLogger().log(Level.SEVERE, "Could not send stc message to discord", e); + if (SteamwarDiscordBot.instance() != null) { + try { + SteamwarDiscordBot.instance().getServerTeamChatListener().send(" " + (player.getName() + "» " + msg).replaceAll("§[a-f0-9r]", "")); + } catch (Exception e) { + BungeeCore.get().getLogger().log(Level.SEVERE, "Could not send stc message to discord", e); + } } sendToTeam(msg, player); } diff --git a/src/de/steamwar/bungeecore/listeners/ChatListener.java b/src/de/steamwar/bungeecore/listeners/ChatListener.java index f66e71c..96c628a 100644 --- a/src/de/steamwar/bungeecore/listeners/ChatListener.java +++ b/src/de/steamwar/bungeecore/listeners/ChatListener.java @@ -212,10 +212,12 @@ public class ChatListener extends BasicListener { msg = "§" + team.getTeamColor() + team.getTeamKuerzel() + " §r" + msg; } - try { - SteamwarDiscordBot.instance().getIngameChatListener().send(" " + msg.replaceAll("§[a-f0-9r]", "")); - } catch (Exception e) { - BungeeCore.get().getLogger().log(Level.SEVERE, "Could not send chat message to discord", e); + if (SteamwarDiscordBot.instance() != null) { + try { + SteamwarDiscordBot.instance().getIngameChatListener().send(" " + msg.replaceAll("§[a-f0-9r]", "")); + } catch (Exception e) { + BungeeCore.get().getLogger().log(Level.SEVERE, "Could not send chat message to discord", e); + } } for(ProxiedPlayer target : ProxyServer.getInstance().getPlayers()){ Subserver targetServer = Subserver.getSubserver(target); -- 2.39.2