From 4c641b196f54451a763f05b47402f36f54a76b56 Mon Sep 17 00:00:00 2001 From: Eleksploded Date: Sun, 28 Apr 2024 11:38:47 -0700 Subject: [PATCH 1/3] Add configurable restart delay --- .../geyserupdater/bungee/util/GeyserBungeeDownloader.java | 7 ++++--- .../geyserupdater/spigot/util/GeyserSpigotDownloader.java | 7 ++++--- .../velocity/util/GeyserVelocityDownloader.java | 7 ++++--- src/main/resources/config.toml | 7 ++++--- src/main/resources/config.yml | 8 +++++--- 5 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/projectg/geyserupdater/bungee/util/GeyserBungeeDownloader.java b/src/main/java/com/projectg/geyserupdater/bungee/util/GeyserBungeeDownloader.java index 9121acba..ef50a8db 100644 --- a/src/main/java/com/projectg/geyserupdater/bungee/util/GeyserBungeeDownloader.java +++ b/src/main/java/com/projectg/geyserupdater/bungee/util/GeyserBungeeDownloader.java @@ -82,10 +82,11 @@ private static boolean downloadGeyser() { * Attempt to restart the server */ private static void restartServer() { - logger.warn("The server will be restarting in 10 seconds!"); + long restartTime = plugin.getConfig().getLong("Auto-Restart-Timer"); + logger.warn("The server will be restarting in %d seconds!".formatted(restartTime)); for (ProxiedPlayer player : plugin.getProxy().getPlayers()) { - player.sendMessage(new TextComponent(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("Restart-Message-Players")))); + player.sendMessage(new TextComponent(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("Restart-Message-Players").formatted(restartTime)))); } - plugin.getProxy().getScheduler().schedule(plugin, () -> plugin.getProxy().stop(), 10L, TimeUnit.SECONDS); + plugin.getProxy().getScheduler().schedule(plugin, () -> plugin.getProxy().stop(), restartTime, TimeUnit.SECONDS); } } \ No newline at end of file diff --git a/src/main/java/com/projectg/geyserupdater/spigot/util/GeyserSpigotDownloader.java b/src/main/java/com/projectg/geyserupdater/spigot/util/GeyserSpigotDownloader.java index e0b208be..5e77afb5 100644 --- a/src/main/java/com/projectg/geyserupdater/spigot/util/GeyserSpigotDownloader.java +++ b/src/main/java/com/projectg/geyserupdater/spigot/util/GeyserSpigotDownloader.java @@ -97,9 +97,10 @@ private static boolean downloadGeyser() { * Attempt to restart the server */ private static void restartServer() { - logger.warn("The server will be restarting in 10 seconds!"); + long restartTimer = plugin.getConfig().getLong("Auto-Restart-Timer"); + logger.warn("The server will be restarting in %d seconds!".formatted(restartTimer)); for (Player player : Bukkit.getOnlinePlayers()) { - player.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("Restart-Message-Players"))); + player.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("Restart-Message-Players").formatted(restartTimer))); } // Attempt to restart the server 10 seconds after the message new BukkitRunnable() { @@ -122,6 +123,6 @@ public void run() { logger.error("Failed to restart the server!", e); } } - }.runTaskLater(plugin, 200); // 200 ticks is around 10 seconds (at 20 TPS) + }.runTaskLater(plugin, restartTimer * 20); // 200 ticks is around 10 seconds (at 20 TPS) } } \ No newline at end of file diff --git a/src/main/java/com/projectg/geyserupdater/velocity/util/GeyserVelocityDownloader.java b/src/main/java/com/projectg/geyserupdater/velocity/util/GeyserVelocityDownloader.java index 697165ab..07b57499 100644 --- a/src/main/java/com/projectg/geyserupdater/velocity/util/GeyserVelocityDownloader.java +++ b/src/main/java/com/projectg/geyserupdater/velocity/util/GeyserVelocityDownloader.java @@ -86,13 +86,14 @@ private static boolean downloadGeyser() { * Attempt to restart the server */ private static void restartServer() { - logger.warn("The server will be restarting in 10 seconds!"); + long restartTime = plugin.getConfig().getLong("Auto-Restart-Timer"); + logger.warn("The server will be restarting in %d seconds!".formatted(restartTime)); for (Player player : server.getAllPlayers()) { - player.sendMessage(Component.text(plugin.getConfig().getString("Restart-Message-Players"))); + player.sendMessage(Component.text(plugin.getConfig().getString("Restart-Message-Players").formatted(restartTime))); } server.getScheduler() .buildTask(plugin, server::shutdown) - .delay(10L, TimeUnit.SECONDS) + .delay(restartTime, TimeUnit.SECONDS) .schedule(); } } diff --git a/src/main/resources/config.toml b/src/main/resources/config.toml index 24a572d7..971fefa4 100644 --- a/src/main/resources/config.toml +++ b/src/main/resources/config.toml @@ -9,15 +9,16 @@ Auto-Update-Geyser=false # The interval in hours between each auto update check. Auto-Update-Interval=24 -# If enabled, GeyserUpdater will attempt to restart the server 10 seconds after a new version of Geyser has been successfully downloaded. +# If enabled, GeyserUpdater will attempt to restart the server a number of seconds in Auto-Restart-Timer (default 10) after a new version of Geyser has been successfully downloaded. # If you aren't using a hosting provider or a server wrapper, you will need a restart script. Auto-Restart-Server=false +Auto-Restart-Timer=10 # When enabled, GeyserUpdater will automatically generate a restart script for you. If you are using CraftBukkit or a proxy # you will need to use the generated script to start your server! If you are using a hosting provider or a server wrapper you probably don't need this. Auto-Script-Generating=false -# Configure the message that is sent to all online players warning them that the server will be restarting in 10 seconds. -Restart-Message-Players='&2This server will be restarting in 10 seconds!' +# Configure the message that is sent to all online players warning them that the server will be restarting in some seconds. Use '%d' as the seconds placeholder. +Restart-Message-Players='&2This server will be restarting in %d seconds!' # Enable debug logging Enable-Debug=false diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 78e0f5e8..129c4775 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -9,15 +9,17 @@ Auto-Update-Geyser: false # The interval in hours between each auto update check. Auto-Update-Interval: 24 -# If enabled, GeyserUpdater will attempt to restart the server 10 seconds after a new version of Geyser has been successfully downloaded. +# If enabled, GeyserUpdater will attempt to restart the server a number of seconds in Auto-Restart-Timer (default 10) after a new version of Geyser has been successfully downloaded. # If you aren't using a hosting provider or a server wrapper, you will need a restart script. Auto-Restart-Server: false +Auto-Restart-Timer: 10 + # When enabled, GeyserUpdater will automatically generate a restart script for you. If you are using CraftBukkit or a proxy # you will need to use the generated script to start your server! If you are using a hosting provider or a server wrapper you probably don't need this. Auto-Script-Generating: false -# Configure the message that is sent to all online players warning them that the server will be restarting in 10 seconds. -Restart-Message-Players: '&2This server will be restarting in 10 seconds!' +# Configure the message that is sent to all online players warning them that the server will be restarting in some seconds. Use '%d' as the seconds placeholder. +Restart-Message-Players: '&2This server will be restarting in %d seconds!' # Enable debug logging Enable-Debug: false From 230fcb91af2e43f9c9702ba92e8e8ae0128e56cc Mon Sep 17 00:00:00 2001 From: Eleksploded Date: Wed, 1 May 2024 11:33:40 -0700 Subject: [PATCH 2/3] extract component creation --- .../geyserupdater/bungee/util/GeyserBungeeDownloader.java | 3 ++- .../geyserupdater/spigot/util/GeyserSpigotDownloader.java | 3 ++- .../geyserupdater/velocity/util/GeyserVelocityDownloader.java | 4 +++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/projectg/geyserupdater/bungee/util/GeyserBungeeDownloader.java b/src/main/java/com/projectg/geyserupdater/bungee/util/GeyserBungeeDownloader.java index ef50a8db..a11d5de9 100644 --- a/src/main/java/com/projectg/geyserupdater/bungee/util/GeyserBungeeDownloader.java +++ b/src/main/java/com/projectg/geyserupdater/bungee/util/GeyserBungeeDownloader.java @@ -84,8 +84,9 @@ private static boolean downloadGeyser() { private static void restartServer() { long restartTime = plugin.getConfig().getLong("Auto-Restart-Timer"); logger.warn("The server will be restarting in %d seconds!".formatted(restartTime)); + TextComponent message = new TextComponent(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("Restart-Message-Players").formatted(restartTime))); for (ProxiedPlayer player : plugin.getProxy().getPlayers()) { - player.sendMessage(new TextComponent(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("Restart-Message-Players").formatted(restartTime)))); + player.sendMessage(message); } plugin.getProxy().getScheduler().schedule(plugin, () -> plugin.getProxy().stop(), restartTime, TimeUnit.SECONDS); } diff --git a/src/main/java/com/projectg/geyserupdater/spigot/util/GeyserSpigotDownloader.java b/src/main/java/com/projectg/geyserupdater/spigot/util/GeyserSpigotDownloader.java index 5e77afb5..bf274954 100644 --- a/src/main/java/com/projectg/geyserupdater/spigot/util/GeyserSpigotDownloader.java +++ b/src/main/java/com/projectg/geyserupdater/spigot/util/GeyserSpigotDownloader.java @@ -99,8 +99,9 @@ private static boolean downloadGeyser() { private static void restartServer() { long restartTimer = plugin.getConfig().getLong("Auto-Restart-Timer"); logger.warn("The server will be restarting in %d seconds!".formatted(restartTimer)); + String message = ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("Restart-Message-Players").formatted(restartTimer)); for (Player player : Bukkit.getOnlinePlayers()) { - player.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("Restart-Message-Players").formatted(restartTimer))); + player.sendMessage(message); } // Attempt to restart the server 10 seconds after the message new BukkitRunnable() { diff --git a/src/main/java/com/projectg/geyserupdater/velocity/util/GeyserVelocityDownloader.java b/src/main/java/com/projectg/geyserupdater/velocity/util/GeyserVelocityDownloader.java index 07b57499..07a5d969 100644 --- a/src/main/java/com/projectg/geyserupdater/velocity/util/GeyserVelocityDownloader.java +++ b/src/main/java/com/projectg/geyserupdater/velocity/util/GeyserVelocityDownloader.java @@ -11,6 +11,7 @@ import com.velocitypowered.api.proxy.ProxyServer; import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.TextComponent; import net.kyori.adventure.text.format.TextColor; import java.util.concurrent.TimeUnit; @@ -88,8 +89,9 @@ private static boolean downloadGeyser() { private static void restartServer() { long restartTime = plugin.getConfig().getLong("Auto-Restart-Timer"); logger.warn("The server will be restarting in %d seconds!".formatted(restartTime)); + TextComponent message = Component.text(plugin.getConfig().getString("Restart-Message-Players").formatted(restartTime)); for (Player player : server.getAllPlayers()) { - player.sendMessage(Component.text(plugin.getConfig().getString("Restart-Message-Players").formatted(restartTime))); + player.sendMessage(message); } server.getScheduler() .buildTask(plugin, server::shutdown) From aef8ab2cf7b802212c3e55a09d8b26badc7c4301 Mon Sep 17 00:00:00 2001 From: Julia Date: Wed, 1 May 2024 11:34:14 -0700 Subject: [PATCH 3/3] fix comment Co-authored-by: Konicai <71294714+Konicai@users.noreply.github.com> --- .../geyserupdater/spigot/util/GeyserSpigotDownloader.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/projectg/geyserupdater/spigot/util/GeyserSpigotDownloader.java b/src/main/java/com/projectg/geyserupdater/spigot/util/GeyserSpigotDownloader.java index bf274954..c945d3a8 100644 --- a/src/main/java/com/projectg/geyserupdater/spigot/util/GeyserSpigotDownloader.java +++ b/src/main/java/com/projectg/geyserupdater/spigot/util/GeyserSpigotDownloader.java @@ -124,6 +124,6 @@ public void run() { logger.error("Failed to restart the server!", e); } } - }.runTaskLater(plugin, restartTimer * 20); // 200 ticks is around 10 seconds (at 20 TPS) + }.runTaskLater(plugin, restartTimer * 20); // 20 ticks per second } } \ No newline at end of file