Last active
August 29, 2015 14:26
-
-
Save vemacs/b760ab4002cfa5e8ddc3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import org.bukkit.plugin.Plugin; | |
| import org.bukkit.scheduler.BukkitRunnable; | |
| import java.util.ArrayDeque; | |
| import java.util.Collections; | |
| import java.util.Deque; | |
| public class TPSUtil extends BukkitRunnable { | |
| private long lastTick; | |
| private Deque<Long> tickIntervals; | |
| int resolution = 40; | |
| public TPSTask(Plugin plugin) { | |
| lastTick = System.currentTimeMillis(); | |
| tickIntervals = new ArrayDeque<>(Collections.nCopies(resolution, 50L)); | |
| this.runTaskTimer(plugin, 1, 1); | |
| } | |
| @Override | |
| public void run() { | |
| long curr = System.currentTimeMillis(); | |
| long delta = curr - lastTick; | |
| lastTick = curr; | |
| tickIntervals.removeFirst(); | |
| tickIntervals.addLast(delta); | |
| } | |
| public double getTPS() { | |
| int base = 0; | |
| for (long delta : tickIntervals) { | |
| base += delta; | |
| } | |
| return 1000D / ((double) base / resolution); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment