package gq.unurled.raxen.utils; import gq.unurled.raxen.Raxen; import net.kyori.adventure.text.Component; import org.bukkit.Bukkit; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.server.ServerListPingEvent; import java.io.*; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; public class Reload implements Listener { private static FileConfiguration config = Raxen.getPlugin().getConfig(); private static boolean serverReloading = true; public static void kickAll() { for(Player player : Bukkit.getOnlinePlayers()) { player.kick(Component.text(Raxen.getPrefix() + "\n§cServer is Restarting\n §cPlease Wait a few Minutes to reconnect.")); } } @EventHandler public static void pingList(ServerListPingEvent e) throws IOException { setPingList(e); } public static void setPingList(ServerListPingEvent e) throws IOException { if(serverReloading) { List newLines = new ArrayList<>(); for(String line : Files.readAllLines(Paths.get("server.properties"), StandardCharsets.UTF_8)) { if(line.contains("motd=")) { newLines.add("motd=" + config.get("motd-reload")); } else { newLines.add(line); } } Files.write(Paths.get("server.properties"), newLines, StandardCharsets.UTF_8); e.motd(Component.text((String) config.get("motd-reload"))); } else { e.motd(Component.text((String) config.get("motd"))); } } }