Advertisement
Guest User

Untitled

a guest
Jul 24th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.74 KB | None | 0 0
  1. public World createWorld(WorldCreator creator) {
  2.         Validate.notNull(creator, "Creator may not be null");
  3.  
  4.         String name = creator.name();
  5.         ChunkGenerator generator = creator.generator();
  6.         File folder = new File(getWorldContainer(), name);
  7.         World world = getWorld(name);
  8.         WorldType type = WorldType.getType(creator.type().getName());
  9.         boolean generateStructures = creator.generateStructures();
  10.  
  11.         if (world != null) {
  12.             return world;
  13.         }
  14.  
  15.         if ((folder.exists()) && (!folder.isDirectory())) {
  16.             throw new IllegalArgumentException("File exists with the name '" + name + "' and isn't a folder");
  17.         }
  18.  
  19.         if (generator == null) {
  20.             generator = getGenerator(name);
  21.         }
  22.  
  23.         Convertable converter = new WorldLoaderServer(getWorldContainer(), getHandle().getServer().getDataConverterManager());
  24.         if (converter.isConvertable(name)) {
  25.             getLogger().info("Converting world '" + name + "'");
  26.             converter.convert(name, new IProgressUpdate() {
  27.                 private long b = System.currentTimeMillis();
  28.  
  29.                 public void a(String s) {}
  30.  
  31.                 public void a(int i) {
  32.                     if (System.currentTimeMillis() - this.b >= 1000L) {
  33.                         this.b = System.currentTimeMillis();
  34.                         MinecraftServer.LOGGER.info("Converting... " + i + "%");
  35.                     }
  36.  
  37.                 }
  38.  
  39.                 public void c(String s) {}
  40.             });
  41.         }
  42.  
  43.         int dimension = CraftWorld.CUSTOM_DIMENSION_OFFSET + console.worlds.size();
  44.         boolean used = false;
  45.         do {
  46.             for (WorldServer server : console.worlds) {
  47.                 used = server.dimension == dimension;
  48.                 if (used) {
  49.                     dimension++;
  50.                     break;
  51.                 }
  52.             }
  53.         } while(used);
  54.         boolean hardcore = false;
  55.  
  56.         IDataManager sdm = new ServerNBTManager(getWorldContainer(), name, true, getHandle().getServer().getDataConverterManager());
  57.         WorldData worlddata = sdm.getWorldData();
  58.         WorldSettings worldSettings = null;
  59.         if (worlddata == null) {
  60.             worldSettings = new WorldSettings(creator.seed(), EnumGamemode.getById(getDefaultGameMode().getValue()), generateStructures, hardcore, type);
  61.             worldSettings.setGeneratorSettings(creator.generatorSettings());
  62.             worlddata = new WorldData(worldSettings, name);
  63.         }
  64.         worlddata.checkName(name); // CraftBukkit - Migration did not rewrite the level.dat; This forces 1.8 to take the last loaded world as respawn (in this case the end)
  65.         WorldServer internal = (WorldServer) new WorldServer(console, sdm, worlddata, dimension, consolef.methodProfiler, creator.environment(), generator).b();
  66.  
  67.         if (!(worlds.containsKey(name.toLowerCase(java.util.Locale.ENGLISH)))) {
  68.             return null;
  69.         }
  70.  
  71.         if (worldSettings != null) {
  72.             internal.a(worldSettings);
  73.         }
  74.         internal.scoreboard = getScoreboardManager().getMainScoreboard().getHandle();
  75.  
  76.         internal.tracker = new EntityTracker(internal);
  77.         internal.addIWorldAccess(new WorldManager(console, internal));
  78.         internal.worldData.setDifficulty(EnumDifficulty.EASY);
  79.         internal.setSpawnFlags(true, true);
  80.         console.worlds.add(internal);
  81.  
  82.         pluginManager.callEvent(new WorldInitEvent(internal.getWorld()));
  83.         System.out.print("Preparing start region for level " + (console.worlds.size() - 1) + " (Seed: " + internal.getSeed() + ")");
  84.  
  85.         if (internal.getWorld().getKeepSpawnInMemory()) {
  86.             short short1 = 196;
  87.             long i = System.currentTimeMillis();
  88.             for (int j = -short1; j <= short1; j += 16) {
  89.                 for (int k = -short1; k <= short1; k += 16) {
  90.                     long l = System.currentTimeMillis();
  91.  
  92.                     if (l < i) {
  93.                         i = l;
  94.                     }
  95.  
  96.                     if (l > i + 1000L) {
  97.                         int i1 = (short1 * 2 + 1) * (short1 * 2 + 1);
  98.                         int j1 = (j + short1) * (short1 * 2 + 1) + k + 1;
  99.  
  100.                         System.out.println("Preparing spawn area for " + name + ", " + (j1 * 100 / i1) + "%");
  101.                         i = l;
  102.                     }
  103.  
  104.                     BlockPosition chunkcoordinates = internal.getSpawn();
  105.                     internal.getChunkProviderServer().getChunkAt(chunkcoordinates.getX() + j >> 4, chunkcoordinates.getZ() + k >> 4);
  106.                 }
  107.             }
  108.         }
  109.         pluginManager.callEvent(new WorldLoadEvent(internal.getWorld()));
  110.         return internal.getWorld();
  111.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement