Hi, i want to make a Lag Relever Code: package code.combed.storyrpgmanager.alerts; import code.combed.storyrpgmanager.Main; import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitRunnable; public class LagAlert { private static boolean lagging = false; // Aggiungiamo una variabile per tenere traccia dello stato dell'avvisopublic static void LagRelever(Player p) { new BukkitRunnable() { private long lastTick = 0; @Overridepublic void run() { long currentTick = System.currentTimeMillis(); if (lastTick != 0) { double ticksPerSecond = 1000.0 / (currentTick - lastTick); String tps = String.valueOf(1000.0 / (currentTick - lastTick)); if (ticksPerSecond < 18.0) { if (!lagging) { // Il TPS è sceso sotto 18, ma non avevamo ancora inviato il messaggiolagging = true; p.sendMessage("§6§m-------------------------------------"); p.sendMessage(" §cAttenzione "); p.sendMessage(" §aIl server sta iniziando a laggare"); p.sendMessage(" §cI tps sono scesi sotto i 18 (§6%tps%§7/§a20.0)".replace("%tps%", tps)); p.sendMessage("§6§m-------------------------------------"); } } else { // Il TPS è risalito a 20, reimposta lo stato dell'avvisolagging = false; } } lastTick = currentTick; } }.runTaskTimer(Main.getInstance(), 0, 20 * 60); // Controlla il TPS ogni 60 secondi} } but i cant make the system for calculate the tps, i want to make if tps is < than 18 it send me a message
i would add the actual System.currentTimeMillis() to a list on each tick, then will be able to get all the entries in the last second or the last minute or... all the time you want store. Don't forget to delete old registers
@CombedHoney Code to get TPS of a server 5 second Google search. Keep your current runnable, and sample the tps field every 60 seconds, if it's < 18, send a message.