From 6148583fb267d96b69f137a71e1060e4edd6cbaa Mon Sep 17 00:00:00 2001 From: snowleo Date: Tue, 23 Apr 2013 08:51:25 +0300 Subject: [PATCH] Fix tps after Timer changes --- .../earth2me/essentials/EssentialsTimer.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/EssentialsTimer.java b/Essentials/src/com/earth2me/essentials/EssentialsTimer.java index fe04c1cbc..941dc6482 100644 --- a/Essentials/src/com/earth2me/essentials/EssentialsTimer.java +++ b/Essentials/src/com/earth2me/essentials/EssentialsTimer.java @@ -12,11 +12,12 @@ public class EssentialsTimer implements Runnable { private final transient IEssentials ess; private final transient Set onlineUsers = new HashSet(); - private transient long lastPoll = System.currentTimeMillis(); - private final transient LinkedList history = new LinkedList(); + private transient long lastPoll = System.nanoTime(); + private final LinkedList history = new LinkedList(); private int skip1 = 0; private int skip2 = 0; private final long maxTime = 10 * 1000000; + private final long tickInterval = 50; EssentialsTimer(final IEssentials ess) { @@ -27,8 +28,8 @@ public class EssentialsTimer implements Runnable public void run() { final long startTime = System.nanoTime(); - final long currentTime = System.currentTimeMillis(); - long timeSpent = (currentTime - lastPoll) / 1000; + //final long currentTime = System.currentTimeMillis(); + long timeSpent = (startTime - lastPoll) / 1000; if (timeSpent == 0) { timeSpent = 1; @@ -37,7 +38,7 @@ public class EssentialsTimer implements Runnable { history.remove(); } - float tps = 100f / timeSpent; + double tps = tickInterval * 1000000.0 / timeSpent; if (tps <= 20) { history.add(tps); @@ -104,10 +105,10 @@ public class EssentialsTimer implements Runnable } } - public float getAverageTPS() + public double getAverageTPS() { - float avg = 0; - for (Float f : history) + double avg = 0; + for (Double f : history) { if (f != null) {