Advertisement
Guest User

Get TPS Rate of Bukkit Server

a guest
Jan 3rd, 2013
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.21 KB | None | 0 0
  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.     static <mainclass> plugin;
  14.     public TPS(<mainclass> plugin) {
  15.         TPS.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) {
  36.                         ticks++;
  37.                     } else {
  38.                         second = sec;
  39.                         tps = tps == 0 ? ticks : (tps + ticks) / 2;
  40.                         ticks = 0;
  41.                     }
  42.                 }
  43.             }, 20, 1);
  44.         }
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement