SHOW:
|
|
- or go back to the newest paste.
| 1 | package ; | |
| 2 | ||
| 3 | import org.bukkit.Bukkit; | |
| 4 | import org.bukkit.event.EventHandler; | |
| 5 | import org.bukkit.event.Listener; | |
| 6 | import org.bukkit.event.server.PluginEnableEvent; | |
| 7 | ||
| 8 | /* | |
| 9 | * | |
| 10 | * @author KeybordPiano459 | |
| 11 | */ | |
| 12 | public class TPS implements Listener {
| |
| 13 | public TPS(Plugin plugin) {
| |
| 14 | this.plugin = plugin; | |
| 15 | } | |
| 16 | ||
| 17 | public int tps = 0; | |
| 18 | public long sec = 0; | |
| 19 | ||
| 20 | public float getServerTPS() {
| |
| 21 | return tps; | |
| 22 | } | |
| 23 | ||
| 24 | @EventHandler | |
| 25 | public void onPluginEnable(PluginEnableEvent event) {
| |
| 26 | if (event.getPlugin() == plugin) {
| |
| 27 | Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
| |
| 28 | long seconds; | |
| 29 | int ticks; | |
| 30 | ||
| 31 | @Override | |
| 32 | public void run() {
| |
| 33 | seconds = System.currentTimeMillis() / 1000; | |
| 34 | if (sec == seconds) ticks++; | |
| 35 | else {
| |
| 36 | sec = seconds; | |
| 37 | - | tps = tps == 0 ? ticks : (tps + ticks) / 2; |
| 37 | + | if (tps == 0) tps = ticks; |
| 38 | else tps = tps + ticks / 2; | |
| 39 | ticks = 0; | |
| 40 | } | |
| 41 | } | |
| 42 | }, 20, 1); | |
| 43 | } | |
| 44 | } | |
| 45 | } |