if (uid == null) {
uid = UUID.randomUUID();
}
// read in world information
CompoundTag level = new CompoundTag();
File levelFile = new File(dir, "level.dat");
if (levelFile.exists()) {
try (NBTInputStream in = new NBTInputStream(new FileInputStream(levelFile))) {
level = in.readCompound();
if (level.isCompound("Data")) {
level = level.getCompound("Data");
} else {
server.getLogger().warning("Loading world \"" + world.getName() + "\": reading from root, not Data");
}
} catch (IOException e) {
handleWorldException("level.dat", e);
}
}
// seed
long seed = 0L;
if (level.isLong("RandomSeed")) {
seed = level.getLong("RandomSeed");
level.remove("RandomSeed");
}
// time of day and weather status
if (level.isByte("thundering")) {
world.setThundering(level.getBool("thundering"));
level.remove("thundering");
}
if (level.isByte("raining")) {
world.setStorm(level.getBool("raining"));
level.remove("raining");
}
if (level.isInt("thunderTime")) {
world.setThunderDuration(level.getInt("thunderTime"));
level.remove("thunderTime");
}
if (level.isInt("rainTime")) {
world.setWeatherDuration(level.getInt("rainTime"));
level.remove("rainTime");
}
if (level.isLong("Time")) {
world.setFullTime(level.getLong("Time"));
level.remove("Time");
}
if (level.isLong("DayTime")) {
world.setTime(level.getLong("DayTime"));
level.remove("DayTime");
}
// spawn position
if (level.isInt("SpawnX") && level.isInt("SpawnY") && level.isInt("SpawnZ")) {
world.setSpawnLocation(level.getInt("SpawnX"), level.getInt("SpawnY"), level.getInt("SpawnZ"));
level.remove("SpawnX");
level.remove("SpawnY");
level.remove("SpawnZ");
}
// game rules
if (level.isCompound("GameRules")) {
CompoundTag gameRules = level.getCompound("GameRules");
for (String key : gameRules.getValue().keySet()) {
if (gameRules.isString(key)) {
world.setGameRuleValue(key, gameRules.getString(key));
}
}
level.remove("GameRules");
}