Search in sources :

Example 1 with GameProfileCacheBridge

use of org.spongepowered.common.bridge.server.players.GameProfileCacheBridge 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;
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) GameProfileCacheBridge(org.spongepowered.common.bridge.server.players.GameProfileCacheBridge) WorldConfig(org.spongepowered.common.config.inheritable.WorldConfig) SerializationBehavior(org.spongepowered.api.world.SerializationBehavior) PrimaryLevelDataBridge(org.spongepowered.common.bridge.world.level.storage.PrimaryLevelDataBridge) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Aggregations

ServerLevel (net.minecraft.server.level.ServerLevel)1 SerializationBehavior (org.spongepowered.api.world.SerializationBehavior)1 Overwrite (org.spongepowered.asm.mixin.Overwrite)1 GameProfileCacheBridge (org.spongepowered.common.bridge.server.players.GameProfileCacheBridge)1 PrimaryLevelDataBridge (org.spongepowered.common.bridge.world.level.storage.PrimaryLevelDataBridge)1 WorldConfig (org.spongepowered.common.config.inheritable.WorldConfig)1