Automatic world saving is disabled when backup is being made

2.x-1.16
szymon 2020-10-29 12:32:18 +01:00
parent fd69b2ae6b
commit a002d49ecf
3 changed files with 87 additions and 63 deletions

View File

@ -19,6 +19,7 @@
package net.szum123321.textile_backup.core; package net.szum123321.textile_backup.core;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.registry.Registry; import net.minecraft.util.registry.Registry;
import net.minecraft.util.registry.RegistryKey; import net.minecraft.util.registry.RegistryKey;
import net.minecraft.world.dimension.DimensionType; import net.minecraft.world.dimension.DimensionType;
@ -49,6 +50,22 @@ public class Utilities {
.getWorldDirectory(RegistryKey.of(Registry.DIMENSION, DimensionType.OVERWORLD_REGISTRY_KEY.getValue())); .getWorldDirectory(RegistryKey.of(Registry.DIMENSION, DimensionType.OVERWORLD_REGISTRY_KEY.getValue()));
} }
public static void disableWorldSaving(MinecraftServer server) {
for (ServerWorld serverWorld : server.getWorlds()) {
if (serverWorld != null && !serverWorld.savingDisabled) {
serverWorld.savingDisabled = true;
}
}
}
public static void enableWorldSaving(MinecraftServer server) {
for (ServerWorld serverWorld : server.getWorlds()) {
if (serverWorld != null && serverWorld.savingDisabled) {
serverWorld.savingDisabled = false;
}
}
}
public static boolean isWindows() { public static boolean isWindows() {
return System.getProperty("os.name").toLowerCase().contains("win"); return System.getProperty("os.name").toLowerCase().contains("win");
} }

View File

@ -53,7 +53,10 @@ public class BackupHelper {
if (ctx.shouldSave()) { if (ctx.shouldSave()) {
Statics.LOGGER.sendInfo(ctx.getCommandSource(), "Saving server..."); Statics.LOGGER.sendInfo(ctx.getCommandSource(), "Saving server...");
Statics.LOGGER.info( "Saving server..."); Statics.LOGGER.info( "Saving server...");
ctx.getServer().save(true, true, false);
ctx.getServer().save(true, true, true);
Utilities.disableWorldSaving(ctx.getServer());
} }
return new MakeBackupRunnable(ctx); return new MakeBackupRunnable(ctx);

View File

@ -35,6 +35,7 @@ public class MakeBackupRunnable implements Runnable {
@Override @Override
public void run() { public void run() {
try {
Statics.LOGGER.sendInfo(context.getCommandSource(), "Starting backup"); Statics.LOGGER.sendInfo(context.getCommandSource(), "Starting backup");
Statics.LOGGER.info("Starting backup"); Statics.LOGGER.info("Starting backup");
@ -100,6 +101,9 @@ public class MakeBackupRunnable implements Runnable {
Statics.LOGGER.sendInfo(context, "Done!"); Statics.LOGGER.sendInfo(context, "Done!");
Statics.LOGGER.info("Done!"); Statics.LOGGER.info("Done!");
} finally {
Utilities.enableWorldSaving(context.getServer());
}
} }
private String getFileName(){ private String getFileName(){