示例#1
0
	@Override
	public World createWorld(WorldCreator creator) {
		if (creator == null) {
			throw new IllegalArgumentException("Creator may not be null");
		}

		String name = creator.name();
		ChunkGenerator generator = creator.generator();
		File folder = new File(getWorldContainer().getParentFile(), name);
		int dimension = DimensionManager.getNextFreeDimId();
		World world = getWorld(dimension);
		WorldType type = WorldType.parseWorldType(creator.type().getName());
		boolean generateStructures = creator.generateStructures();

		if (world != null) {
			return world;
		}

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

		if (generator == null) {
			generator = getGenerator(dimension);
		}

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


		boolean hardcore = false;

		WorldServer internal = new WorldServer(theServer, new AnvilSaveHandler(getWorldContainer().getParentFile(), name, true), name, dimension, new WorldSettings(creator.seed(), EnumGameType.getByID(getDefaultGameMode().getValue()), generateStructures, hardcore, type), theServer.theProfiler);

		if (!(worlds.containsKey(dimension))) {
			return null;
		}

		//internal.getWorldInfo().get = console.worldServerForDimension(0).worldMaps;

		//internal. = new EntityTracker(internal); // CraftBukkit
		internal.addWorldAccess((IWorldAccess) new WorldManager(theServer, internal));
		internal.difficultySetting = 1;
		//internal.(true, true);
		//theServer.worldServers[theServer.worldServers.length] = internal;
		DimensionManager.setWorld(dimension, internal);
		this.worlds.put(dimension, new BukkitWorld(internal, creator.generator(), creator.environment()));
		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);

					//while (internal.updateLights()) {
					//  ;
				}//
			}
		}
		pluginManager.callEvent( new WorldLoadEvent(worlds.get(dimension)));
		return worlds.get(dimension);
	}
示例#2
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);
  }