Ejemplo n.º 1
0
  protected void y() throws ExceptionWorldConflict { // CraftBukkit - added throws
    SpigotTimings.serverTickTimer.startTiming(); // Spigot
    long i = System.nanoTime();

    ++this.ticks;
    if (this.T) {
      this.T = false;
      this.methodProfiler.a = true;
      this.methodProfiler.a();
    }

    this.methodProfiler.a("root");
    this.z();
    if (i - this.X >= 5000000000L) {
      this.X = i;
      this.r.setPlayerSample(new ServerPingPlayerSample(this.H(), this.G()));
      GameProfile[] agameprofile = new GameProfile[Math.min(this.G(), 12)];
      int j = MathHelper.nextInt(this.s, 0, this.G() - agameprofile.length);

      for (int k = 0; k < agameprofile.length; ++k) {
        agameprofile[k] = ((EntityPlayer) this.v.players.get(j + k)).getProfile();
      }

      Collections.shuffle(Arrays.asList(agameprofile));
      this.r.b().a(agameprofile);
    }

    if (autosavePeriod > 0 && this.ticks % autosavePeriod == 0) { // CraftBukkit
      SpigotTimings.worldSaveTimer.startTiming(); // Spigot
      this.methodProfiler.a("save");
      this.v.savePlayers();
      // Spigot Start
      // We replace this with saving each individual world as this.saveChunks(...) is broken,
      // and causes the main thread to sleep for random amounts of time depending on chunk activity
      // Also pass flag to only save modified chunks
      server.playerCommandState = true;
      for (World world : worlds) {
        world.getWorld().save(false);
      }
      server.playerCommandState = false;
      // this.saveChunks(true);
      // Spigot End
      this.methodProfiler.b();
      SpigotTimings.worldSaveTimer.stopTiming(); // Spigot
    }

    this.methodProfiler.a("tallying");
    this.g[this.ticks % 100] = System.nanoTime() - i;
    this.methodProfiler.b();
    this.methodProfiler.a("snooper");
    if (getSnooperEnabled() && !this.m.d() && this.ticks > 100) { // Spigot
      this.m.a();
    }

    if (getSnooperEnabled() && this.ticks % 6000 == 0) { // Spigot
      this.m.b();
    }

    this.methodProfiler.b();
    this.methodProfiler.b();
    org.spigotmc.WatchdogThread.tick(); // Spigot
    SpigotTimings.serverTickTimer.stopTiming(); // Spigot
    org.spigotmc.CustomTimingsHandler.tick(); // Spigot
  }
Ejemplo n.º 2
0
  public void run() {
    try {
      if (this.init()) {
        this.ab = ax();
        long i = 0L;

        this.r.setMOTD(new ChatComponentText(this.motd));
        this.r.setServerInfo(new ServerPingServerData("1.8", 47));
        this.a(this.r);

        // Spigot start
        Arrays.fill(recentTps, 20);
        long lastTick = System.nanoTime(), catchupTime = 0, curTime, wait, tickSection = lastTick;
        while (this.isRunning) {
          curTime = System.nanoTime();
          wait = TICK_TIME - (curTime - lastTick) - catchupTime;
          if (wait > 0) {
            Thread.sleep(wait / 1000000);
            catchupTime = 0;
            continue;
          } else {
            catchupTime = Math.min(1000000000, Math.abs(wait));
          }

          if (MinecraftServer.currentTick++ % SAMPLE_INTERVAL == 0) {
            double currentTps = 1E9 / (curTime - tickSection) * SAMPLE_INTERVAL;
            recentTps[0] = calcTps(recentTps[0], 0.92, currentTps); // 1/exp(5sec/1min)
            recentTps[1] = calcTps(recentTps[1], 0.9835, currentTps); // 1/exp(5sec/5min)
            recentTps[2] = calcTps(recentTps[2], 0.9945, currentTps); // 1/exp(5sec/15min)
            tickSection = curTime;
          }
          lastTick = curTime;

          this.y();
          this.Q = true;
        }
        // Spigot end
      } else {
        this.a((CrashReport) null);
      }
    } catch (Throwable throwable) {
      MinecraftServer.LOGGER.error("Encountered an unexpected exception", throwable);
      // Spigot Start
      if (throwable.getCause() != null) {
        MinecraftServer.LOGGER.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 file =
          new File(
              new File(this.w(), "crash-reports"),
              "crash-"
                  + (new SimpleDateFormat("yyyy-MM-dd_HH.mm.ss")).format(new Date())
                  + "-server.txt");

      if (crashreport.a(file)) {
        MinecraftServer.LOGGER.error(
            "This crash report has been saved to: " + file.getAbsolutePath());
      } else {
        MinecraftServer.LOGGER.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) {
        MinecraftServer.LOGGER.error("Exception stopping the server", throwable1);
      } finally {
        // CraftBukkit start - Restore terminal to original settings
        try {
          reader.getTerminal().restore();
        } catch (Exception ignored) {
        }
        // CraftBukkit end
        this.x();
      }
    }
  }