コード例 #1
0
ファイル: MinecraftServer.java プロジェクト: McSwede/XIV
  public void run() {
    try {
      if (this.startServer()) {
        this.currentTime = getCurrentTimeMillis();
        long var1 = 0L;
        this.statusResponse.setServerDescription(new ChatComponentText(this.motd));
        this.statusResponse.setProtocolVersionInfo(
            new ServerStatusResponse.MinecraftProtocolVersionIdentifier("1.8", 47));
        this.addFaviconToStatusResponse(this.statusResponse);

        while (this.serverRunning) {
          long var48 = getCurrentTimeMillis();
          long var5 = var48 - this.currentTime;

          if (var5 > 2000L && this.currentTime - this.timeOfLastWarning >= 15000L) {
            logger.warn(
                "Can\'t keep up! Did the system time change, or is the server overloaded? Running {}ms behind, skipping {} tick(s)",
                new Object[] {Long.valueOf(var5), Long.valueOf(var5 / 50L)});
            var5 = 2000L;
            this.timeOfLastWarning = this.currentTime;
          }

          if (var5 < 0L) {
            logger.warn("Time ran backwards! Did the system time change?");
            var5 = 0L;
          }

          var1 += var5;
          this.currentTime = var48;

          if (this.worldServers[0].areAllPlayersAsleep()) {
            this.tick();
            var1 = 0L;
          } else {
            while (var1 > 50L) {
              var1 -= 50L;
              this.tick();
            }
          }

          Thread.sleep(Math.max(1L, 50L - var1));
          this.serverIsRunning = true;
        }
      } else {
        this.finalTick((CrashReport) null);
      }
    } catch (Throwable var46) {
      logger.error("Encountered an unexpected exception", var46);
      CrashReport var2 = null;

      if (var46 instanceof ReportedException) {
        var2 = this.addServerInfoToCrashReport(((ReportedException) var46).getCrashReport());
      } else {
        var2 =
            this.addServerInfoToCrashReport(
                new CrashReport("Exception in server tick loop", var46));
      }

      File var3 =
          new File(
              new File(this.getDataDirectory(), "crash-reports"),
              "crash-"
                  + (new SimpleDateFormat("yyyy-MM-dd_HH.mm.ss")).format(new Date())
                  + "-server.txt");

      if (var2.saveToFile(var3)) {
        logger.error("This crash report has been saved to: " + var3.getAbsolutePath());
      } else {
        logger.error("We were unable to save this crash report to disk.");
      }

      this.finalTick(var2);
    } finally {
      try {
        this.stopServer();
        this.serverStopped = true;
      } catch (Throwable var44) {
        logger.error("Exception stopping the server", var44);
      } finally {
        this.systemExitNow();
      }
    }
  }
コード例 #2
0
ファイル: MinecraftServer.java プロジェクト: McSwede/XIV
 public boolean isCallingFromMinecraftThread() {
   return Thread.currentThread() == this.serverThread;
 }