Advertisement
funkemunky

Proper run() Method for 1.8.8

Jul 22nd, 2019
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.39 KB | None | 0 0
  1. public void run() {
  2. try {
  3. if(this.init()) {
  4. this.ab = az();
  5. this.r.setMOTD(new ChatComponentText(this.motd));
  6. this.r.setServerInfo(new ServerData("1.8.8", 47));
  7. this.a(this.r);
  8. Arrays.fill(this.recentTps, 20.0D);
  9. long start = System.nanoTime();
  10. long lastTick = start - 50000000L;
  11. long catchupTime = 0L;
  12.  
  13. for(long tickSection = start; this.isRunning; this.Q = true) {
  14. long curTime = System.nanoTime();
  15. long wait = 50000000L - (curTime - lastTick);
  16. if(wait > 0L) {
  17. if((double)catchupTime < 2000000.0D) {
  18. wait += Math.abs(catchupTime);
  19. } else if(wait < catchupTime) {
  20. catchupTime -= wait;
  21. wait = 0L;
  22. } else {
  23. wait -= catchupTime;
  24. catchupTime = 0L;
  25. }
  26. }
  27.  
  28. if(wait > 0L) {
  29. Thread.sleep(wait / 1000000L);
  30. curTime = System.nanoTime();
  31. wait = 50000000L - (curTime - lastTick);
  32. }
  33.  
  34. catchupTime = Math.min(60000000000L, catchupTime - wait);
  35. if(++currentTick % 20 == 0) {
  36. long diff = curTime - tickSection;
  37. double currentTps = 1.0E9D / (double)diff * 20.0D;
  38. this.tps1.add(currentTps, diff);
  39. this.tps5.add(currentTps, diff);
  40. this.tps15.add(currentTps, diff);
  41. this.recentTps[0] = this.tps1.getAverage();
  42. this.recentTps[1] = this.tps5.getAverage();
  43. this.recentTps[2] = this.tps15.getAverage();
  44. tickSection = curTime;
  45. }
  46.  
  47. lastTick = curTime;
  48. this.A();
  49. }
  50. } else {
  51. this.a((CrashReport)null);
  52. }
  53. } catch (Throwable var82) {
  54. LOGGER.error("Encountered an unexpected exception", var82);
  55. if(var82.getCause() != null) {
  56. LOGGER.error("\tCause of unexpected exception was", var82.getCause());
  57. }
  58.  
  59. CrashReport crashreport = null;
  60. if(var82 instanceof ReportedException) {
  61. crashreport = this.b(((ReportedException)var82).a());
  62. } else {
  63. crashreport = this.b(new CrashReport("Exception in server tick loop", var82));
  64. }
  65.  
  66. File file = new File(new File(this.y(), "crash-reports"), "crash-" + (new SimpleDateFormat("yyyy-MM-dd_HH.mm.ss")).format(new Date()) + "-server.txt");
  67. if(crashreport.a(file)) {
  68. LOGGER.error("This crash report has been saved to: " + file.getAbsolutePath());
  69. } else {
  70. LOGGER.error("We were unable to save this crash report to disk.");
  71. }
  72.  
  73. this.a(crashreport);
  74. } finally {
  75. try {
  76. WatchdogThread.doStop();
  77. this.isStopped = true;
  78. this.stop();
  79. } catch (Throwable var80) {
  80. LOGGER.error("Exception stopping the server", var80);
  81. } finally {
  82. try {
  83. this.reader.getTerminal().restore();
  84. } catch (Exception var79) {
  85. ;
  86. }
  87.  
  88. this.z();
  89. }
  90.  
  91. }
  92.  
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement