Ticks per second is the measure of a server's lag, essentially, here's a quick way to find it: Lag.java Code: public class Lag implements Runnable { public static int TICK_COUNT= 0; public static long[] TICKS= new long[600]; public static long LAST_TICK= 0L; public static double getTPS() { return getTPS(100); } public static double getTPS(int ticks) { if (TICK_COUNT< ticks) { return 20.0D; } int target = (TICK_COUNT- 1 - ticks) % TICKS.length; long elapsed = System.currentTimeMillis() - TICKS[target]; return ticks / (elapsed / 1000.0D); } public static long getElapsed(int tickID) { if (TICK_COUNT- tickID >= TICKS.length) { } long time = TICKS[(tickID % TICKS.length)]; return System.currentTimeMillis() - time; } public void run() { TICKS[(TICK_COUNT% TICKS.length)] = System.currentTimeMillis(); TICK_COUNT+= 1; } } Start the task in your onEnable() method : Code: Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Lag(), 100L, 1L); And to get the TPS whenever you need : Code: Lag.getTPS(); Another nifty thing is to get the server lag percentage, like so: Code: double tps = Lag.getTPS(); double lag = Math.round((1.0D - tps / 20.0D) * 100.0D);
That makes sense, yes you probably can. Although what he is working out is the percentage lag, what you are working out is the percentage of TPS you're getting out of what the TPS should be (20). E.g. If you get 19TPS, his would result in: 5% Yours would result in: 95% His shows the percentage it is lagging by, whereas yours shows how... stable... it is I guess. Both can show percentage lag. What I would do to show the lag (which is what he does but even more simple) is: Code: double percentage = Double.valueOf(String.format("%.2f", (100 - tps * 5))); If the TPS is 20, this would return 0, meaning 0% lag. If the TPS was 10, this would return 50, meaning 50% lag, and so on. Edit: The reason I did the String.format() bit was because we want it to be to two decimal places only. I did the same with TPS as otherwise it gives a long number, usually the TPS is 19.99999999 or so on most normal servers with a fair amount of plugins. Question: What's the point of the "LAST_TICK" variable if it's never being used? EDIT by Moderator: merged posts, please use the edit button instead of double posting.
Obviously it means your server is running extra good! Jk,jk If you have essentials, do /lag to get the TPS
It's possible that it returns > 20 ticks if the server has recovered from a short lag spike and is making up for lost time. It was going be to used for something else, at this point it's just redundant. EDIT by Moderator: merged posts, please use the edit button instead of double posting.
Yes you could, But lets say you have 18.5 TPS, It would show as 92.5 Percent, to fix this, you would do as you were doing, but after that, subtract the result from 100, this will give you the lag percentage