Advertisement
funkemunky

Proper run() Method for 1.7.10

Jul 22nd, 2019
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.54 KB | None | 0 0
  1. public void run() {
  2.         try {
  3.             if (this.init()) {
  4.                 long i = ar();
  5.                 long j = 0L;
  6.  
  7.                 this.q.setMOTD(new ChatComponentText(this.motd));
  8.                 this.q.setServerInfo(new ServerPingServerData("1.7.10", 5));
  9.                 this.a(this.q);
  10.  
  11.                 // Spigot start
  12.                 // PaperSpigot start - Further improve tick loop
  13.                 Arrays.fill( recentTps, 20 );
  14.                 //long lastTick = System.nanoTime(), catchupTime = 0, curTime, wait, tickSection = lastTick;
  15.                 long start = System.nanoTime(), lastTick = start - TICK_TIME, catchupTime = 0, curTime, wait, tickSection = start;
  16.  
  17.                 // PaperSpigot end
  18.                 while (this.isRunning) {
  19.                     curTime = System.nanoTime();
  20.                     // PaperSpigot start - Further improve tick loop
  21.                     wait = TICK_TIME - (curTime - lastTick);
  22.                     if (wait > 0) {
  23.                         if (catchupTime < 2E6) {
  24.                             wait += Math.abs(catchupTime);
  25.                         } else if (wait < catchupTime) {
  26.                             catchupTime -= wait;
  27.                             wait = 0;
  28.                         } else {
  29.                             wait -= catchupTime;
  30.                             catchupTime = 0;
  31.                         }
  32.                     }
  33.                     if (wait > 0L) {
  34.                         Thread.sleep(wait / 1000000L);
  35.                         curTime = System.nanoTime();
  36.                         wait = 50000000L - (curTime - lastTick);
  37.                     }
  38.                     catchupTime = Math.min(60000000000L, catchupTime - wait);
  39.                     // Paperspigot end
  40.  
  41.                     if ( ++MinecraftServer.currentTick % SAMPLE_INTERVAL == 0 ) // PaperSpigot - Further improve tick loop
  42.                     {
  43.                         // PaperSpigot start - Further improve tick loop
  44.                         final long diff = curTime - tickSection;
  45.                         double currentTps = 1E9 / diff * SAMPLE_INTERVAL;
  46.                         tps1.add(currentTps, diff);
  47.                         tps5.add(currentTps, diff);
  48.                         tps15.add(currentTps, diff);
  49.                         // Backwards compat with bad plugins
  50.                         recentTps[0] = tps1.getAverage();
  51.                         recentTps[1] = tps5.getAverage();
  52.                         recentTps[2] = tps15.getAverage();
  53.                         tickSection = curTime;
  54.                         // PaperSpigot end
  55.                     }
  56.                     lastTick = curTime;
  57.  
  58.                     this.u();
  59.                     this.O = true;
  60.                 }
  61.                 // Spigot end
  62.             } else {
  63.                 this.a((CrashReport) null);
  64.             }
  65.         } catch (Throwable throwable) {
  66.             i.error("Encountered an unexpected exception", throwable);
  67.             // Spigot Start
  68.             if ( throwable.getCause() != null )
  69.             {
  70.                 i.error( "\tCause of unexpected exception was", throwable.getCause() );
  71.             }
  72.             // Spigot End
  73.             CrashReport crashreport = null;
  74.  
  75.             if (throwable instanceof ReportedException) {
  76.                 crashreport = this.b(((ReportedException) throwable).a());
  77.             } else {
  78.                 crashreport = this.b(new CrashReport("Exception in server tick loop", throwable));
  79.             }
  80.  
  81.             File file1 = new File(new File(this.s(), "crash-reports"), "crash-" + (new SimpleDateFormat("yyyy-MM-dd_HH.mm.ss")).format(new Date()) + "-server.txt");
  82.  
  83.             if (crashreport.a(file1)) {
  84.                 i.error("This crash report has been saved to: " + file1.getAbsolutePath());
  85.             } else {
  86.                 i.error("We were unable to save this crash report to disk.");
  87.             }
  88.  
  89.             this.a(crashreport);
  90.         } finally {
  91.             try {
  92.                 org.spigotmc.WatchdogThread.doStop();
  93.                 this.stop();
  94.                 this.isStopped = true;
  95.             } catch (Throwable throwable1) {
  96.                 i.error("Exception stopping the server", throwable1);
  97.             } finally {
  98.                 // CraftBukkit start - Restore terminal to original settings
  99.                 try {
  100.                     this.reader.getTerminal().restore();
  101.                 } catch (Exception e) {
  102.                 }
  103.                 // CraftBukkit end
  104.                 this.t();
  105.             }
  106.         }
  107.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement