use of org.spongepowered.api.world.server.storage.ServerWorldProperties in project SpongeCommon by SpongePowered.
the class ServerChunkCacheMixin method impl$useSerializationBehaviorWhenSaving.
// @formatter:on
@Redirect(method = "save", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ChunkMap;saveAllChunks(Z)V"))
private void impl$useSerializationBehaviorWhenSaving(final ChunkMap chunkManager, final boolean flush) {
final ServerLevel world = this.level;
final SerializationBehavior serializationBehavior = ((ServerWorldProperties) world.getLevelData()).serializationBehavior();
if (serializationBehavior == SerializationBehavior.AUTOMATIC || serializationBehavior == SerializationBehavior.MANUAL) {
((ChunkMapAccessor) chunkManager).invoker$saveAllChunks(flush);
}
}
use of org.spongepowered.api.world.server.storage.ServerWorldProperties in project SpongeCommon by SpongePowered.
the class SpongeWorldManager method loadProperties.
@Override
public CompletableFuture<Optional<ServerWorldProperties>> loadProperties(final ResourceKey key) {
final net.minecraft.resources.ResourceKey<Level> registryKey = SpongeWorldManager.createRegistryKey(Objects.requireNonNull(key, "key"));
if (this.worlds.get(registryKey) != null) {
return CompletableFuture.completedFuture(Optional.empty());
}
if (!this.worldExists(key)) {
return CompletableFuture.completedFuture(Optional.empty());
}
final boolean isVanillaWorld = this.isVanillaWorld(key);
final String directoryName = this.getDirectoryName(key);
final LevelStorageSource.LevelStorageAccess storageSource;
try {
if (isVanillaWorld) {
storageSource = LevelStorageSource.createDefault(this.defaultWorldDirectory).createAccess(directoryName);
} else {
storageSource = LevelStorageSource.createDefault(this.customWorldsDirectory).createAccess(key.namespace() + File.separator + key.value());
}
} catch (final IOException e) {
return FutureUtil.completedWithException(e);
}
final WorldData levelData;
try {
final PrimaryLevelData defaultLevelData = (PrimaryLevelData) this.server.getWorldData();
final LevelSettings defaultLevelSettings = ((PrimaryLevelDataAccessor) defaultLevelData).accessor$settings();
try {
levelData = storageSource.getDataTag((DynamicOps<Tag>) BootstrapProperties.worldSettingsAdapter, defaultLevelSettings.getDataPackConfig());
} catch (final Exception ex) {
return FutureUtil.completedWithException(ex);
}
} finally {
try {
storageSource.close();
} catch (final IOException ex) {
return FutureUtil.completedWithException(ex);
}
}
return this.loadTemplate(key).thenCompose(r -> {
r.ifPresent(template -> {
final LevelStem scratch = ((SpongeWorldTemplate) template).asDimension();
((PrimaryLevelDataBridge) levelData).bridge$populateFromDimension(scratch);
});
return CompletableFuture.completedFuture(Optional.of((ServerWorldProperties) levelData));
});
}
use of org.spongepowered.api.world.server.storage.ServerWorldProperties in project SpongeCommon by SpongePowered.
the class DifficultyCommandMixin method setDifficulty.
// @formatter:on
/**
* @author Zidane
* @reason Only apply difficulty for the world the command was ran in (as in Sponge, all worlds have difficulties)
*/
@Overwrite
public static int setDifficulty(CommandSourceStack source, Difficulty difficulty) throws CommandSyntaxException {
if (source.getLevel().getDifficulty() == difficulty) {
throw DifficultyCommandMixin.ERROR_ALREADY_DIFFICULT.create(difficulty.getKey());
} else {
final LevelData levelData = source.getLevel().getLevelData();
((ServerWorldProperties) levelData).setDifficulty((org.spongepowered.api.world.difficulty.Difficulty) (Object) difficulty);
source.getLevel().setSpawnSettings(((MinecraftServerAccessor) SpongeCommon.server()).invoker$isSpawningMonsters(), SpongeCommon.server().isSpawningAnimals());
source.getLevel().getPlayers(p -> true).forEach(p -> p.connection.send(new ClientboundChangeDifficultyPacket(levelData.getDifficulty(), levelData.isDifficultyLocked())));
source.sendSuccess(new TranslatableComponent("commands.difficulty.success", difficulty.getDisplayName()), true);
return 0;
}
}
Aggregations