Guest User

Untitled

a guest
Jan 6th, 2017
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. package de.payne.classes;
  2.  
  3. import org.bukkit.Bukkit;
  4.  
  5. public class TPS
  6. implements Runnable
  7. {
  8. public static int TICK_COUNT = 0;
  9. public static long[] TICKS = new long['»'];
  10. public static long LAST_TICK = 0L;
  11.  
  12. public static double getTPS()
  13. {
  14. return getTPS(100);
  15. }
  16.  
  17. public static double getTPS(int ticks)
  18. {
  19. try
  20. {
  21. if (TICK_COUNT < ticks) {
  22. return 20.0D;
  23. }
  24. int target = (TICK_COUNT - 1 - ticks) % TICKS.length;
  25. long elapsed = System.currentTimeMillis() - TICKS[target];
  26.  
  27. return ticks / (elapsed / 1000.0D);
  28. }
  29. catch (Exception e)
  30. {
  31. if ((e instanceof ArrayIndexOutOfBoundsException)) {
  32. return 20.0D;
  33. }
  34. Bukkit.getLogger().severe("[Clearlag] Beim abrufen des TPS ist ein Fehler aufgetreten");
  35. }
  36. return 20.0D;
  37. }
  38.  
  39. public static long getElapsed(int tickID)
  40. {
  41.  
  42. long time = TICKS[(tickID % TICKS.length)];
  43. return System.currentTimeMillis() - time;
  44. }
  45.  
  46. public void run()
  47. {
  48. TICKS[(TICK_COUNT % TICKS.length)] = System.currentTimeMillis();
  49.  
  50. TICK_COUNT += 1;
  51. }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment