Archiviert
1
0

Encapsulate DiscordBot errors

Signed-off-by: Lixfel <agga-games@gmx.de>
Dieser Commit ist enthalten in:
Lixfel 2021-10-01 10:38:48 +02:00
Ursprung f9b42ad0c1
Commit c3c666c305
4 geänderte Dateien mit 27 neuen und 4 gelöschten Zeilen

Datei anzeigen

@ -157,7 +157,11 @@ public class BungeeCore extends Plugin {
}, 1, 1, TimeUnit.HOURS); }, 1, 1, TimeUnit.HOURS);
if (SteamwarDiscordBotConfig.loaded) { if (SteamwarDiscordBotConfig.loaded) {
try {
new SteamwarDiscordBot(); new SteamwarDiscordBot();
} catch (Exception e) {
getLogger().log(Level.SEVERE, "Could not initialize discord bot", e);
}
} }
} }
@ -168,6 +172,8 @@ public class BungeeCore extends Plugin {
SteamwarDiscordBot.instance().getJda().awaitStatus(JDA.Status.SHUTDOWN); SteamwarDiscordBot.instance().getJda().awaitStatus(JDA.Status.SHUTDOWN);
} catch (InterruptedException e) { } catch (InterruptedException e) {
Thread.currentThread().interrupt(); Thread.currentThread().interrupt();
} catch (Exception e) {
getLogger().log(Level.SEVERE, "Could not shutdown discord bot", e);
} }
errorLogger.unregister(); errorLogger.unregister();

Datei anzeigen

@ -44,6 +44,7 @@ import javax.security.auth.login.LoginException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
public class SteamwarDiscordBot { public class SteamwarDiscordBot {
@ -84,7 +85,11 @@ public class SteamwarDiscordBot {
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); e.printStackTrace();
} }
try {
activity(); activity();
} catch (Exception e) {
BungeeCore.get().getLogger().log(Level.SEVERE, "Could not set initial activity to discord", e);
}
EventManager.update(); EventManager.update();
SchematicsManager.update(); SchematicsManager.update();
ProxyServer.getInstance().getScheduler().schedule(BungeeCore.get(), () -> { ProxyServer.getInstance().getScheduler().schedule(BungeeCore.get(), () -> {

Datei anzeigen

@ -19,6 +19,7 @@
package de.steamwar.bungeecore.commands; package de.steamwar.bungeecore.commands;
import de.steamwar.bungeecore.BungeeCore;
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.bungeecore.listeners.ChatListener; import de.steamwar.bungeecore.listeners.ChatListener;
@ -28,6 +29,8 @@ import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.ProxiedPlayer;
import java.util.logging.Level;
public class ServerTeamchatCommand extends BasicCommand { public class ServerTeamchatCommand extends BasicCommand {
public ServerTeamchatCommand() { public ServerTeamchatCommand() {
@ -51,7 +54,11 @@ public class ServerTeamchatCommand extends BasicCommand {
String msg = msgBuilder.toString(); String msg = msgBuilder.toString();
msg = ChatColor.translateAlternateColorCodes('&', msg); msg = ChatColor.translateAlternateColorCodes('&', msg);
try {
SteamwarDiscordBot.instance().getServerTeamChatListener().send("<t:" + (System.currentTimeMillis() / 1000) + "> " + (player.getName() + "» " + msg).replaceAll("§[a-f0-9r]", "")); SteamwarDiscordBot.instance().getServerTeamChatListener().send("<t:" + (System.currentTimeMillis() / 1000) + "> " + (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); sendToTeam(msg, player);
} }
} }

Datei anzeigen

@ -37,6 +37,7 @@ import net.md_5.bungee.event.EventHandler;
import java.util.List; import java.util.List;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
public class ChatListener extends BasicListener { public class ChatListener extends BasicListener {
@ -203,7 +204,11 @@ public class ChatListener extends BasicListener {
msg = "§" + team.getTeamColor() + team.getTeamKuerzel() + " §r" + msg; msg = "§" + team.getTeamColor() + team.getTeamKuerzel() + " §r" + msg;
} }
try {
SteamwarDiscordBot.instance().getIngameChatListener().send("<t:" + (System.currentTimeMillis() / 1000) + "> " + msg.replaceAll("§[a-f0-9r]", "")); SteamwarDiscordBot.instance().getIngameChatListener().send("<t:" + (System.currentTimeMillis() / 1000) + "> " + 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()){ for(ProxiedPlayer target : ProxyServer.getInstance().getPlayers()){
Subserver targetServer = Subserver.getSubserver(target); Subserver targetServer = Subserver.getSubserver(target);
if(!(targetServer == null || targetServer.getType() != Servertype.ARENA || targetServer.getServer() != target.getServer().getInfo())) continue; if(!(targetServer == null || targetServer.getType() != Servertype.ARENA || targetServer.getServer() != target.getServer().getInfo())) continue;