use of org.spongepowered.api.world.SerializationBehavior 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.SerializationBehavior in project SpongeCommon by SpongePowered.
the class ServerLevelMixin method save.
/**
* @author zidane - December 17th, 2020 - Minecraft 1.16.4
* @reason Honor our serialization behavior in performing saves
*/
@Overwrite
public void save(@Nullable final ProgressListener progress, final boolean flush, final boolean skipSave) {
final Cause currentCause = Sponge.server().causeStackManager().currentCause();
if (Sponge.eventManager().post(SpongeEventFactory.createSaveWorldEventPre(currentCause, ((ServerWorld) this)))) {
// cancelled save
return;
}
final PrimaryLevelData levelData = (PrimaryLevelData) this.shadow$getLevelData();
final ServerChunkCache chunkProvider = ((ServerLevel) (Object) this).getChunkSource();
if (!skipSave) {
final SerializationBehavior behavior = ((PrimaryLevelDataBridge) levelData).bridge$serializationBehavior().orElse(SerializationBehavior.AUTOMATIC);
if (progress != null) {
progress.progressStartNoAbort(new TranslatableComponent("menu.savingLevel"));
}
// We always save the metadata unless it is NONE
if (behavior != SerializationBehavior.NONE) {
this.shadow$saveLevelData();
// Sponge Start - We do per-world WorldInfo/WorldBorders/BossBars
levelData.setWorldBorder(this.getWorldBorder().createSettings());
levelData.setCustomBossEvents(((ServerLevelBridge) this).bridge$getBossBarManager().save());
((ServerLevelBridge) this).bridge$getLevelSave().saveDataTag(SpongeCommon.server().registryAccess(), (PrimaryLevelData) this.shadow$getLevelData(), this.shadow$dimension() == Level.OVERWORLD ? SpongeCommon.server().getPlayerList().getSingleplayerData() : null);
// Sponge End
}
if (progress != null) {
progress.progressStage(new TranslatableComponent("menu.savingChunks"));
}
final boolean canAutomaticallySave = !this.impl$isManualSave && behavior == SerializationBehavior.AUTOMATIC;
final boolean canManuallySave = this.impl$isManualSave && behavior == SerializationBehavior.MANUAL;
if (canAutomaticallySave || canManuallySave) {
chunkProvider.save(flush);
}
Sponge.eventManager().post(SpongeEventFactory.createSaveWorldEventPost(currentCause, ((ServerWorld) this)));
}
this.impl$isManualSave = false;
}
use of org.spongepowered.api.world.SerializationBehavior in project SpongeCommon by SpongePowered.
the class ChunkMapMixin method impl$useSerializationBehaviorForChunkSave.
@Redirect(method = "save", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/chunk/storage/ChunkSerializer;write(Lnet/minecraft/server/level/ServerLevel;" + "Lnet/minecraft/world/level/chunk/ChunkAccess;)Lnet/minecraft/nbt/CompoundTag;"))
private CompoundTag impl$useSerializationBehaviorForChunkSave(final ServerLevel worldIn, final ChunkAccess chunkIn) {
final PrimaryLevelDataBridge infoBridge = (PrimaryLevelDataBridge) this.level.getLevelData();
final SerializationBehavior serializationBehavior = infoBridge.bridge$serializationBehavior().orElse(SerializationBehavior.AUTOMATIC);
if (serializationBehavior == SerializationBehavior.AUTOMATIC || serializationBehavior == SerializationBehavior.MANUAL) {
return ChunkSerializer.write(worldIn, chunkIn);
}
return null;
}
use of org.spongepowered.api.world.SerializationBehavior in project SpongeCommon by SpongePowered.
the class ChunkMapMixin method impl$useSerializationBehaviorForPOI.
@Redirect(method = "save", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/ai/village/poi/PoiManager;flush(Lnet/minecraft/world/level/ChunkPos;)V"))
private void impl$useSerializationBehaviorForPOI(final PoiManager pointOfInterestManager, final ChunkPos p_219112_1_) {
final PrimaryLevelDataBridge infoBridge = (PrimaryLevelDataBridge) this.level.getLevelData();
final SerializationBehavior serializationBehavior = infoBridge.bridge$serializationBehavior().orElse(SerializationBehavior.AUTOMATIC);
if (serializationBehavior == SerializationBehavior.AUTOMATIC || serializationBehavior == SerializationBehavior.MANUAL) {
pointOfInterestManager.flush(p_219112_1_);
}
}
use of org.spongepowered.api.world.SerializationBehavior in project SpongeCommon by SpongePowered.
the class MinecraftServerMixin method saveAllChunks.
/**
* @author Zidane - November, 24th 2020 - Minecraft 1.15
* @reason To allow per-world auto-save tick intervals or disable auto-saving entirely
*/
@Overwrite
public boolean saveAllChunks(final boolean suppressLog, final boolean flush, final boolean isForced) {
boolean var0 = false;
for (final ServerLevel world : this.shadow$getAllLevels()) {
final SerializationBehavior serializationBehavior = ((PrimaryLevelDataBridge) world.getLevelData()).bridge$serializationBehavior().orElse(SerializationBehavior.AUTOMATIC);
final InheritableConfigHandle<WorldConfig> adapter = ((PrimaryLevelDataBridge) world.getLevelData()).bridge$configAdapter();
// Sponge start - use our own config
boolean log = adapter.get().world.logAutoSave;
// by a command, save our configs
if (!this.shadow$isRunning() || this.tickCount % 6000 == 0 || isForced) {
((PrimaryLevelDataBridge) world.getLevelData()).bridge$configAdapter().save();
}
final boolean canSaveAtAll = serializationBehavior != SerializationBehavior.NONE;
// This world is set to not save of any time, no reason to check the auto-save/etc, skip it
if (!canSaveAtAll) {
continue;
}
// Only run auto-save skipping if the server is still running and the save is not forced
if (this.bridge$performAutosaveChecks() && !isForced) {
final int autoSaveInterval = adapter.get().world.autoSaveInterval;
// Do not process properties or chunks if the world is not set to do so unless the server is shutting down
if (autoSaveInterval <= 0 || serializationBehavior != SerializationBehavior.AUTOMATIC) {
continue;
}
// Now check the interval vs the tick counter and skip it
if (this.tickCount % autoSaveInterval != 0) {
continue;
}
}
if (log) {
LOGGER.info("Saving chunks for level '{}'/{}", world, world.dimension().location());
}
world.save((ProgressListener) null, flush, world.noSave && !isForced);
var0 = true;
}
// Save the usercache.json file every 10 minutes or if forced to
if (isForced || this.tickCount % 6000 == 0) {
// We want to save the username cache json, as we normally bypass it.
((GameProfileCacheBridge) this.profileCache).bridge$setCanSave(true);
this.profileCache.save();
((GameProfileCacheBridge) this.profileCache).bridge$setCanSave(false);
}
return var0;
}
Aggregations