Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void run() {
- try {
- if (this.init()) {
- long i = ar();
- long j = 0L;
- this.q.setMOTD(new ChatComponentText(this.motd));
- this.q.setServerInfo(new ServerPingServerData("1.7.10", 5));
- this.a(this.q);
- // Spigot start
- // PaperSpigot start - Further improve tick loop
- Arrays.fill( recentTps, 20 );
- //long lastTick = System.nanoTime(), catchupTime = 0, curTime, wait, tickSection = lastTick;
- long start = System.nanoTime(), lastTick = start - TICK_TIME, catchupTime = 0, curTime, wait, tickSection = start;
- // PaperSpigot end
- while (this.isRunning) {
- curTime = System.nanoTime();
- // PaperSpigot start - Further improve tick loop
- wait = TICK_TIME - (curTime - lastTick);
- if (wait > 0) {
- if (catchupTime < 2E6) {
- wait += Math.abs(catchupTime);
- } else if (wait < catchupTime) {
- catchupTime -= wait;
- wait = 0;
- } else {
- wait -= catchupTime;
- catchupTime = 0;
- }
- }
- if (wait > 0L) {
- Thread.sleep(wait / 1000000L);
- curTime = System.nanoTime();
- wait = 50000000L - (curTime - lastTick);
- }
- catchupTime = Math.min(60000000000L, catchupTime - wait);
- // Paperspigot end
- if ( ++MinecraftServer.currentTick % SAMPLE_INTERVAL == 0 ) // PaperSpigot - Further improve tick loop
- {
- // PaperSpigot start - Further improve tick loop
- final long diff = curTime - tickSection;
- double currentTps = 1E9 / diff * SAMPLE_INTERVAL;
- tps1.add(currentTps, diff);
- tps5.add(currentTps, diff);
- tps15.add(currentTps, diff);
- // Backwards compat with bad plugins
- recentTps[0] = tps1.getAverage();
- recentTps[1] = tps5.getAverage();
- recentTps[2] = tps15.getAverage();
- tickSection = curTime;
- // PaperSpigot end
- }
- lastTick = curTime;
- this.u();
- this.O = true;
- }
- // Spigot end
- } else {
- this.a((CrashReport) null);
- }
- } catch (Throwable throwable) {
- i.error("Encountered an unexpected exception", throwable);
- // Spigot Start
- if ( throwable.getCause() != null )
- {
- i.error( "\tCause of unexpected exception was", throwable.getCause() );
- }
- // Spigot End
- CrashReport crashreport = null;
- if (throwable instanceof ReportedException) {
- crashreport = this.b(((ReportedException) throwable).a());
- } else {
- crashreport = this.b(new CrashReport("Exception in server tick loop", throwable));
- }
- File file1 = new File(new File(this.s(), "crash-reports"), "crash-" + (new SimpleDateFormat("yyyy-MM-dd_HH.mm.ss")).format(new Date()) + "-server.txt");
- if (crashreport.a(file1)) {
- i.error("This crash report has been saved to: " + file1.getAbsolutePath());
- } else {
- i.error("We were unable to save this crash report to disk.");
- }
- this.a(crashreport);
- } finally {
- try {
- org.spigotmc.WatchdogThread.doStop();
- this.stop();
- this.isStopped = true;
- } catch (Throwable throwable1) {
- i.error("Exception stopping the server", throwable1);
- } finally {
- // CraftBukkit start - Restore terminal to original settings
- try {
- this.reader.getTerminal().restore();
- } catch (Exception e) {
- }
- // CraftBukkit end
- this.t();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement