use of net.glowstone.GlowWorldBorder in project Glowstone by GlowstoneMC.
the class NbtWorldMetadataService method readWorldData.
@Override
public WorldFinalValues readWorldData() {
// determine UUID of world
UUID uid = null;
File uuidFile = new File(dir, UUID_FILE);
if (uuidFile.exists()) {
try (DataInputStream in = new DataInputStream(new FileInputStream(uuidFile))) {
uid = new UUID(in.readLong(), in.readLong());
} catch (IOException e) {
handleWorldException(UUID_FILE, e);
}
}
if (uid == null) {
uid = UUID.randomUUID();
}
// read in world information
CompoundTag level = new CompoundTag();
File levelFile = new File(dir, LEVEL_FILE);
if (levelFile.exists()) {
try (NbtInputStream in = new NbtInputStream(new FileInputStream(levelFile))) {
CompoundTag levelOuter = in.readCompound();
level = levelOuter.tryGetCompound("Data").orElseGet(() -> {
ConsoleMessages.Warn.Io.NO_WORLD_DATA_TAG.log(world.getName());
return levelOuter;
});
} catch (IOException e) {
handleWorldException(LEVEL_FILE, e);
}
}
// seed
final long seed = level.tryGetLong("RandomSeed").orElse(0L);
// time of day and weather status
if (level.readBoolean("thundering", world::setThundering)) {
level.remove("thundering");
}
if (level.readBoolean("raining", world::setStorm)) {
level.remove("raining");
}
if (level.readInt("thunderTime", world::setThunderDuration)) {
level.remove("thunderTime");
}
if (level.readInt("rainTime", world::setWeatherDuration)) {
level.remove("rainTime");
}
if (level.readLong("Time", world::setFullTime)) {
level.remove("Time");
}
if (level.readLong("DayTime", world::setTime)) {
level.remove("DayTime");
}
if (level.readString("generatorName", generatorName -> world.setWorldType(WorldType.getByName(generatorName)))) {
level.remove("generatorName");
}
// spawn position
if (level.isInt("SpawnX") && level.isInt("SpawnY") && level.isInt("SpawnZ")) {
world.setSpawnLocation(level.getInt("SpawnX"), level.getInt("SpawnY"), level.getInt("SpawnZ"), false);
level.remove("SpawnX");
level.remove("SpawnY");
level.remove("SpawnZ");
}
// game rules
if (level.readCompound("GameRules", gameRules -> gameRules.getValue().keySet().stream().filter(gameRules::isString).forEach(key -> world.setGameRuleValue(key, gameRules.getString(key))))) {
level.remove("GameRules");
}
// world border
Location borderCenter = new Location(world, 0, 0, 0);
if (level.readDouble("BorderCenterX", borderCenter::setX)) {
level.remove("BorderCenterX");
}
if (level.readDouble("BorderCenterZ", borderCenter::setZ)) {
level.remove("BorderCenterZ");
}
GlowWorldBorder worldBorder = world.getWorldBorder();
worldBorder.setCenter(borderCenter);
if (level.readDouble("BorderSize", worldBorder::setSize)) {
level.remove("BorderSize");
}
if (level.isDouble("BorderSizeLerpTarget") && level.isLong("BorderSizeLerpTime")) {
worldBorder.setSize(level.getDouble("BorderSizeLerpTarget"), level.getLong("BorderSizeLerpTime"));
level.remove("BorderSizeLerpTarget");
level.remove("BorderSizeLerpTime");
}
if (level.readDouble("BorderSafeZone", worldBorder::setDamageBuffer)) {
level.remove("BorderSafeZone");
}
if (level.readDouble("BorderWarningTime", time -> worldBorder.setWarningTime((int) time))) {
level.remove("BorderWarningTime");
}
if (level.readDouble("BorderWarningBlocks", distance -> worldBorder.setWarningDistance((int) distance))) {
level.remove("BorderWarningBlocks");
}
if (level.readDouble("BorderDamagePerBlock", worldBorder::setDamageAmount)) {
level.remove("BorderDamagePerBlock");
}
// strip single-player Player tag if it exists
if (level.isCompound("Player")) {
ConsoleMessages.Warn.Io.REMOVING_SINGLE_PLAYER.log(world.getName());
level.remove("Player");
}
// save unknown tags for later
unknownTags = level;
return new WorldFinalValues(seed, uid);
}
Aggregations