Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,12 @@ 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));
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"))));
player.sendMessage(message);
}
plugin.getProxy().getScheduler().schedule(plugin, () -> plugin.getProxy().stop(), 10L, TimeUnit.SECONDS);
plugin.getProxy().getScheduler().schedule(plugin, () -> plugin.getProxy().stop(), restartTime, TimeUnit.SECONDS);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,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 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")));
player.sendMessage(message);
}
// Attempt to restart the server 10 seconds after the message
new BukkitRunnable() {
Expand All @@ -122,6 +124,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); // 20 ticks per second
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -86,13 +87,15 @@ 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));
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")));
player.sendMessage(message);
}
server.getScheduler()
.buildTask(plugin, server::shutdown)
.delay(10L, TimeUnit.SECONDS)
.delay(restartTime, TimeUnit.SECONDS)
.schedule();
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/main/resources/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down