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 | <mainclass> plugin; | |
14 | public TPS(<mainclass> plugin) { | |
15 | this.plugin = plugin; | |
16 | } | |
17 | ||
18 | public int tps = 0; | |
19 | public long second = 0; | |
20 | ||
21 | public float getServerTPS() { | |
22 | return tps; | |
23 | } | |
24 | ||
25 | @EventHandler | |
26 | public void onPluginEnable(PluginEnableEvent event) { | |
27 | if (event.getPlugin() == plugin) { | |
28 | Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() { | |
29 | long sec; | |
30 | int ticks; | |
31 | ||
32 | @Override | |
33 | public void run() { | |
34 | sec = System.currentTimeMillis() / 1000; | |
35 | - | if (second == sec) { |
35 | + | if (second == sec) ticks++; |
36 | - | ticks++; |
36 | + | else { |
37 | - | } else { |
37 | + | |
38 | if (tps == 0) tps = ticks; | |
39 | else tps = (tps + ticks) / 2; | |
40 | ticks = 0; | |
41 | } | |
42 | } | |
43 | }, 20, 1); | |
44 | } | |
45 | } | |
46 | } |