예제 #1
0
  /** Main function called by run() every loop. */
  public void tick() {
    long var1 = System.nanoTime();
    ++this.tickCounter;

    if (this.startProfiling) {
      this.startProfiling = false;
      this.theProfiler.profilingEnabled = true;
      this.theProfiler.clearProfiling();
    }

    this.theProfiler.startSection("root");
    this.updateTimeLightAndEntities();

    if (var1 - this.nanoTimeSinceStatusRefresh >= 5000000000L) {
      this.nanoTimeSinceStatusRefresh = var1;
      this.statusResponse.setPlayerCountData(
          new ServerStatusResponse.PlayerCountData(
              this.getMaxPlayers(), this.getCurrentPlayerCount()));
      GameProfile[] var3 = new GameProfile[Math.min(this.getCurrentPlayerCount(), 12)];
      int var4 =
          MathHelper.getRandomIntegerInRange(
              this.random, 0, this.getCurrentPlayerCount() - var3.length);

      for (int var5 = 0; var5 < var3.length; ++var5) {
        var3[var5] =
            ((EntityPlayerMP) this.serverConfigManager.playerEntityList.get(var4 + var5))
                .getGameProfile();
      }

      Collections.shuffle(Arrays.asList(var3));
      this.statusResponse.getPlayerCountData().setPlayers(var3);
    }

    if (this.tickCounter % 900 == 0) {
      this.theProfiler.startSection("save");
      this.serverConfigManager.saveAllPlayerData();
      this.saveAllWorlds(true);
      this.theProfiler.endSection();
    }

    this.theProfiler.startSection("tallying");
    this.tickTimeArray[this.tickCounter % 100] = System.nanoTime() - var1;
    this.theProfiler.endSection();
    this.theProfiler.startSection("snooper");

    if (!this.usageSnooper.isSnooperRunning() && this.tickCounter > 100) {
      this.usageSnooper.startSnooper();
    }

    if (this.tickCounter % 6000 == 0) {
      this.usageSnooper.addMemoryStatsToSnooper();
    }

    this.theProfiler.endSection();
    this.theProfiler.endSection();
  }
예제 #2
0
  public void updateTimeLightAndEntities() {
    this.theProfiler.startSection("jobs");
    Queue var1 = this.futureTaskQueue;

    synchronized (this.futureTaskQueue) {
      while (!this.futureTaskQueue.isEmpty()) {
        try {
          ((FutureTask) this.futureTaskQueue.poll()).run();
        } catch (Throwable var9) {
          logger.fatal(var9);
        }
      }
    }

    this.theProfiler.endStartSection("levels");
    int var11;

    for (var11 = 0; var11 < this.worldServers.length; ++var11) {
      long var2 = System.nanoTime();

      if (var11 == 0 || this.getAllowNether()) {
        WorldServer var4 = this.worldServers[var11];
        this.theProfiler.startSection(var4.getWorldInfo().getWorldName());

        if (this.tickCounter % 20 == 0) {
          this.theProfiler.startSection("timeSync");
          this.serverConfigManager.sendPacketToAllPlayersInDimension(
              new S03PacketTimeUpdate(
                  var4.getTotalWorldTime(),
                  var4.getWorldTime(),
                  var4.getGameRules().getGameRuleBooleanValue("doDaylightCycle")),
              var4.provider.getDimensionId());
          this.theProfiler.endSection();
        }

        this.theProfiler.startSection("tick");
        CrashReport var6;

        try {
          var4.tick();
        } catch (Throwable var8) {
          var6 = CrashReport.makeCrashReport(var8, "Exception ticking world");
          var4.addWorldInfoToCrashReport(var6);
          throw new ReportedException(var6);
        }

        try {
          var4.updateEntities();
        } catch (Throwable var7) {
          var6 = CrashReport.makeCrashReport(var7, "Exception ticking world entities");
          var4.addWorldInfoToCrashReport(var6);
          throw new ReportedException(var6);
        }

        this.theProfiler.endSection();
        this.theProfiler.startSection("tracker");
        var4.getEntityTracker().updateTrackedEntities();
        this.theProfiler.endSection();
        this.theProfiler.endSection();
      }

      this.timeOfLastDimensionTick[var11][this.tickCounter % 100] = System.nanoTime() - var2;
    }

    this.theProfiler.endStartSection("connection");
    this.getNetworkSystem().networkTick();
    this.theProfiler.endStartSection("players");
    this.serverConfigManager.onTick();
    this.theProfiler.endStartSection("tickables");

    for (var11 = 0; var11 < this.playersOnline.size(); ++var11) {
      ((IUpdatePlayerListBox) this.playersOnline.get(var11)).update();
    }

    this.theProfiler.endSection();
  }
예제 #3
0
 public static long getCurrentTimeMillis() {
   return System.currentTimeMillis();
 }
예제 #4
0
  @Override
  public World createWorld(WorldCreator creator) {
    if (creator == null) {
      throw new IllegalArgumentException("Creator may not be null");
    }

    String name = creator.name();
    World world = getWorld(name);

    //		WorldType type = WorldType.parseWorldType(creator.type().getName());

    if (world != null) { // Existing forge world
      return world;
    }

    if (firstBukkitWorld) {
      DimensionManager.registerProviderType(
          CraftWorldProvider.ProviderID, CraftWorldProvider.class, false);
      firstBukkitWorld = false;
    }

    int dimension = -1000;

    if (CraftWorldProvider.hasDimensionIdForName(name)) {
      dimension = CraftWorldProvider.getDimensionIdForName(name);
    } else {
      dimension = DimensionManager.getNextFreeDimId();
      CraftWorldProvider.setDimensionIdForName(name, dimension);
    }

    DimensionManager.registerDimension(dimension, CraftWorldProvider.ProviderID);

    CraftWorldProvider wp = (CraftWorldProvider) DimensionManager.createProviderFor(dimension);
    wp.setName(creator.name());

    File folder = new File(getWorldContainer(), wp.getDimName());
    if ((folder.exists()) && (!folder.isDirectory())) {
      throw new IllegalArgumentException(
          "File exists with the name '" + name + "' and isn't a folder");
    }

    ChunkGenerator generator = creator.generator();
    boolean generateStructures = creator.generateStructures();

    AnvilSaveConverter converter = new AnvilSaveConverter(folder);
    if (converter.isOldMapFormat(wp.getDimensionName())) {
      getLogger().info("Converting world '" + name + "'");
      converter.convertMapFormat(name, new ConvertingProgressUpdate(theServer));
    }

    WorldType type = WorldType.parseWorldType(creator.type().getName());

    // WorldServer internal = new WorldServer(theServer, new
    // AnvilSaveHandler(getWorldContainer().getParentFile(), name, true), name, dimension, new
    // WorldSettings(creator.seed(), EnumGameType.getByID(getDefaultGameMode().getValue()),
    // generateStructures, false, type), theServer.theProfiler);
    // WorldServerMulti internal = new WorldServerMulti(theServer, new
    // AnvilSaveHandler(getWorldContainer()                , name, true), name, dimension, new
    // WorldSettings(creator.seed(), EnumGameType.getByID(getDefaultGameMode().getValue()),
    // generateStructures, false,    type), theServer.theProfiler, creator.environment(),
    // generator);
    WorldServer internal =
        new WorldServerMulti(
            theServer,
            new AnvilSaveHandler(getWorldContainer(), wp.getDimName(), true),
            name,
            dimension,
            new WorldSettings(
                creator.seed(),
                EnumGameType.getByID(getDefaultGameMode().getValue()),
                generateStructures,
                false,
                type),
            worlds.get(0).getHandle(),
            theServer.theProfiler);

    internal.addWorldAccess((IWorldAccess) new WorldManager(theServer, internal));
    internal.difficultySetting = 1;
    internal.provider = wp;

    wp.registerWorld(internal);

    // DimensionManager.setWorld(dimension, internal);  not necessary, done in constructor of
    // WorldServer
    worlds.cacheIfNotPresent(dimension);
    if (generator != null) {
      (worlds.get(dimension))
          .getPopulators()
          .addAll(generator.getDefaultPopulators(worlds.get(dimension)));
    }

    pluginManager.callEvent(new WorldInitEvent((worlds.get(dimension))));
    System.out.print(
        "Preparing start region for level "
            + (theServer.worldServers.length - 1)
            + " (Seed: "
            + internal.getSeed()
            + ")");

    if (DimensionManager.shouldLoadSpawn(dimension)) {
      short short1 = 196;
      long i = System.currentTimeMillis();
      for (int j = -short1; j <= short1; j += 16) {
        for (int k = -short1; k <= short1; k += 16) {
          long l = System.currentTimeMillis();

          if (l < i) {
            i = l;
          }

          if (l > i + 1000L) {
            int i1 = (short1 * 2 + 1) * (short1 * 2 + 1);
            int j1 = (j + short1) * (short1 * 2 + 1) + k + 1;

            System.out.println("Preparing spawn area for " + name + ", " + (j1 * 100 / i1) + "%");
            i = l;
          }

          ChunkCoordinates chunkcoordinates = internal.getSpawnPoint();
          internal.theChunkProviderServer.provideChunk(
              chunkcoordinates.posX + j >> 4, chunkcoordinates.posZ + k >> 4);
        } //
      }
    }

    MinecraftForge.EVENT_BUS.post(new WorldEvent.Load(internal));
    pluginManager.callEvent(new WorldLoadEvent(worlds.get(dimension)));
    return worlds.get(dimension);
  }