From 0ef4fc147cbcd8d2f3f069dd9c46361639cd4280 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 28 Jun 2024 13:24:12 +0200 Subject: [PATCH] Fix Discord bot shutdown, fight broadcasts, ErrorLogger, autoreconnect Signed-off-by: Lixfel --- src/de/steamwar/velocitycore/ErrorLogger.java | 4 +++- src/de/steamwar/velocitycore/VelocityCore.java | 2 +- .../velocitycore/commands/ChallengeCommand.java | 2 +- .../velocitycore/commands/FightCommand.java | 2 +- .../velocitycore/commands/HistoricCommand.java | 7 ++++--- .../listeners/ConnectionListener.java | 16 ++++------------ 6 files changed, 14 insertions(+), 19 deletions(-) diff --git a/src/de/steamwar/velocitycore/ErrorLogger.java b/src/de/steamwar/velocitycore/ErrorLogger.java index 99b06a8..a032b6c 100644 --- a/src/de/steamwar/velocitycore/ErrorLogger.java +++ b/src/de/steamwar/velocitycore/ErrorLogger.java @@ -72,7 +72,9 @@ public class ErrorLogger extends AbstractAppender { SWException.log(message, stacktrace); } - private static final List filteredMessages = List.of(); + private static final List filteredMessages = List.of( + "read timed out" + ); private static final List filteredStacktraces = List.of( "ErrorLogger", "Connection reset by peer" diff --git a/src/de/steamwar/velocitycore/VelocityCore.java b/src/de/steamwar/velocitycore/VelocityCore.java index 7c35ecf..3944271 100644 --- a/src/de/steamwar/velocitycore/VelocityCore.java +++ b/src/de/steamwar/velocitycore/VelocityCore.java @@ -250,7 +250,7 @@ public class VelocityCore implements ReloadablePlugin { @Override public void onProxyShutdown(ProxyShutdownEvent event) { try { - DiscordBot.withBot(bot -> bot.getJda().shutdown()); + DiscordBot.withBot(bot -> bot.getJda().shutdownNow()); } catch (Throwable e) { logger.log(Level.SEVERE, "Could not shutdown discord bot", e); } diff --git a/src/de/steamwar/velocitycore/commands/ChallengeCommand.java b/src/de/steamwar/velocitycore/commands/ChallengeCommand.java index d720f9d..ddc3365 100644 --- a/src/de/steamwar/velocitycore/commands/ChallengeCommand.java +++ b/src/de/steamwar/velocitycore/commands/ChallengeCommand.java @@ -51,7 +51,7 @@ public class ChallengeCommand extends SWCommand { challenges.remove(p); new ServerStarter().arena(mode, map).blueLeader(sender.getPlayer()).redLeader(target).callback( - arena -> Chatter.broadcast().system("CHALLENGE_BROADCAST", "CHALLENGE_BROADCAST_HOVER", ClickEvent.runCommand("/arena " + arena.getServer().getName()), mode.getGameName(), p, target) + arena -> Chatter.broadcast().system("CHALLENGE_BROADCAST", new Message("CHALLENGE_BROADCAST_HOVER"), ClickEvent.runCommand("/arena " + arena.getServer().getName()), mode.getGameName(), p, target) ).start(); }else{ if(!challenges.containsKey(p)){ diff --git a/src/de/steamwar/velocitycore/commands/FightCommand.java b/src/de/steamwar/velocitycore/commands/FightCommand.java index 9b6ffd2..1d5283e 100644 --- a/src/de/steamwar/velocitycore/commands/FightCommand.java +++ b/src/de/steamwar/velocitycore/commands/FightCommand.java @@ -130,7 +130,7 @@ public class FightCommand extends SWCommand { public void fight(@Validator("arenaPlayer") PlayerChatter sender, @Mapper("nonHistoricArenaMode") @OptionalValue("") @AllowNull ArenaMode arenaMode, @Mapper("arenaMap") @OptionalValue("") @AllowNull String map) { createArena(sender, "/fight ", true, arenaMode, map, false, (p, mode, m) -> new ServerStarter().arena(mode, m).blueLeader(p.getPlayer()).callback( - arena -> Chatter.broadcast().system("FIGHT_BROADCAST", "FIGHT_BROADCAST_HOVER", ClickEvent.runCommand("/arena " + arena.getServer().getName()), mode.getGameName(), p.getPlayer().getUsername()) + arena -> Chatter.broadcast().system("FIGHT_BROADCAST", new Message("FIGHT_BROADCAST_HOVER"), ClickEvent.runCommand("/arena " + arena.getServer().getName()), mode.getGameName(), p.getPlayer().getUsername()) ).start() ); } diff --git a/src/de/steamwar/velocitycore/commands/HistoricCommand.java b/src/de/steamwar/velocitycore/commands/HistoricCommand.java index 74972e7..7176da8 100644 --- a/src/de/steamwar/velocitycore/commands/HistoricCommand.java +++ b/src/de/steamwar/velocitycore/commands/HistoricCommand.java @@ -19,11 +19,12 @@ package de.steamwar.velocitycore.commands; -import de.steamwar.velocitycore.ArenaMode; -import de.steamwar.velocitycore.ServerStarter; import de.steamwar.command.SWCommand; import de.steamwar.messages.Chatter; +import de.steamwar.messages.Message; import de.steamwar.messages.PlayerChatter; +import de.steamwar.velocitycore.ArenaMode; +import de.steamwar.velocitycore.ServerStarter; import net.kyori.adventure.text.event.ClickEvent; public class HistoricCommand extends SWCommand { @@ -34,7 +35,7 @@ public class HistoricCommand extends SWCommand { @Register public void historic(@Validator("arenaPlayer") PlayerChatter player, @Mapper("historicArenaMode") @OptionalValue("") @AllowNull ArenaMode arenaMode, @Mapper("arenaMap") @OptionalValue("") @AllowNull String map) { FightCommand.createArena(player, "/historic ", true, arenaMode, map, true, (p, mode, m) -> new ServerStarter().arena(mode, m).blueLeader(p.getPlayer()).callback( - arena -> Chatter.broadcast().system("HISTORIC_BROADCAST", "HISTORIC_BROADCAST_HOVER", ClickEvent.runCommand("/arena " + arena.getServer().getName()), mode.getGameName(), p.getPlayer()) + arena -> Chatter.broadcast().system("HISTORIC_BROADCAST", new Message("HISTORIC_BROADCAST_HOVER"), ClickEvent.runCommand("/arena " + arena.getServer().getName()), mode.getGameName(), p.getPlayer()) ).start()); } } diff --git a/src/de/steamwar/velocitycore/listeners/ConnectionListener.java b/src/de/steamwar/velocitycore/listeners/ConnectionListener.java index 35a4967..f73e54d 100644 --- a/src/de/steamwar/velocitycore/listeners/ConnectionListener.java +++ b/src/de/steamwar/velocitycore/listeners/ConnectionListener.java @@ -23,12 +23,14 @@ import com.velocitypowered.api.event.Subscribe; import com.velocitypowered.api.event.connection.DisconnectEvent; import com.velocitypowered.api.event.connection.PostLoginEvent; import com.velocitypowered.api.event.permission.PermissionsSetupEvent; -import com.velocitypowered.api.event.player.KickedFromServerEvent; import com.velocitypowered.api.permission.Tristate; import com.velocitypowered.api.proxy.Player; +import de.steamwar.messages.Chatter; +import de.steamwar.messages.Message; import de.steamwar.persistent.Servertype; import de.steamwar.persistent.Subserver; -import de.steamwar.velocitycore.VelocityCore; +import de.steamwar.sql.SteamwarUser; +import de.steamwar.sql.UserPerm; import de.steamwar.velocitycore.commands.ChallengeCommand; import de.steamwar.velocitycore.commands.CheckCommand; import de.steamwar.velocitycore.commands.ModCommand; @@ -36,10 +38,6 @@ import de.steamwar.velocitycore.commands.MsgCommand; import de.steamwar.velocitycore.discord.DiscordBot; import de.steamwar.velocitycore.discord.util.DiscordRanks; import de.steamwar.velocitycore.mods.ModUtils; -import de.steamwar.messages.Chatter; -import de.steamwar.messages.Message; -import de.steamwar.sql.SteamwarUser; -import de.steamwar.sql.UserPerm; import net.kyori.adventure.text.event.ClickEvent; import java.util.HashSet; @@ -95,12 +93,6 @@ public class ConnectionListener extends BasicListener { DiscordBot.withBot(bot -> DiscordRanks.update(user)); } - /** To redirect players to the lobby in case of server closure. */ //TODO still necessary? - @Subscribe - public void onServerKickEvent(KickedFromServerEvent e) { - e.setResult(KickedFromServerEvent.RedirectPlayer.create(VelocityCore.get().getConfig().lobbyserver(), e.getServerKickReason().orElse(null))); - } - @Subscribe public void onDisconnect(DisconnectEvent e){ ChallengeCommand.remove(e.getPlayer());