diff --git a/gradle.properties b/gradle.properties index bfee7ff..7eaf195 100644 --- a/gradle.properties +++ b/gradle.properties @@ -14,12 +14,11 @@ cloth_version=11.1.106 #ModMenu modmenu_version=7.2.2 -databreaker_version=0.2.10 - +lazydfu_version=0.1.3 #Hash of commit form which parallel gzip will be build pgzip_commit_hash=af5f5c297e735f3f2df7aa4eb0e19a5810b8aff6 # Mod Properties -mod_version = 3.1.1 +mod_version = 3.1.1-b maven_group = net.szum123321 archives_base_name = textile_backup \ No newline at end of file diff --git a/src/main/java/net/szum123321/textile_backup/core/WorldSavingState.java b/src/main/java/net/szum123321/textile_backup/core/WorldSavingState.java new file mode 100644 index 0000000..87c2c0c --- /dev/null +++ b/src/main/java/net/szum123321/textile_backup/core/WorldSavingState.java @@ -0,0 +1,35 @@ +package net.szum123321.textile_backup.core; + +import net.minecraft.registry.RegistryKey; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.world.World; + +import java.util.HashSet; +import java.util.Set; + +public class WorldSavingState { + private final Set> data; + + private WorldSavingState(Set> data) { + this.data = data; + } + + public static WorldSavingState disable(MinecraftServer server) { + Set> data = new HashSet<>(); + + for (ServerWorld serverWorld : server.getWorlds()) { + if (serverWorld == null || serverWorld.savingDisabled) continue; + serverWorld.savingDisabled = true; + data.add(serverWorld.getRegistryKey()); + } + return new WorldSavingState(data); + } + + public void enable(MinecraftServer server) { + for (ServerWorld serverWorld : server.getWorlds()) { + if (serverWorld != null && data.contains(serverWorld.getRegistryKey())) + serverWorld.savingDisabled = false; + } + } +} diff --git a/src/main/java/net/szum123321/textile_backup/core/create/ExecutableBackup.java b/src/main/java/net/szum123321/textile_backup/core/create/ExecutableBackup.java index e5456eb..c767029 100644 --- a/src/main/java/net/szum123321/textile_backup/core/create/ExecutableBackup.java +++ b/src/main/java/net/szum123321/textile_backup/core/create/ExecutableBackup.java @@ -9,6 +9,7 @@ import net.szum123321.textile_backup.config.ConfigHelper; import net.szum123321.textile_backup.core.ActionInitiator; import net.szum123321.textile_backup.core.Cleanup; import net.szum123321.textile_backup.core.Utilities; +import net.szum123321.textile_backup.core.WorldSavingState; import net.szum123321.textile_backup.core.create.compressors.ParallelZipCompressor; import net.szum123321.textile_backup.core.create.compressors.ZipCompressor; import net.szum123321.textile_backup.core.create.compressors.tar.AbstractTarArchiver; @@ -20,7 +21,9 @@ import java.nio.file.Files; import java.nio.file.Path; import java.time.LocalDateTime; import java.util.NoSuchElementException; +import java.util.Optional; import java.util.concurrent.Callable; +import java.util.concurrent.atomic.AtomicReference; public record ExecutableBackup(@NotNull MinecraftServer server, ServerCommandSource commandSource, @@ -68,11 +71,24 @@ public record ExecutableBackup(@NotNull MinecraftServer server, log.trace("Outfile is: {}", outFile); - try { - //I think I should synchronise these two next calls... - Utilities.disableWorldSaving(server); + AtomicReference> state = new AtomicReference<>(Optional.empty()); + + try { + //Globals.INSTANCE.disableWatchdog = true; + //I think I should synchronise these two next calls... + + //Execute following call on the server executor + server.submitAndJoin(() -> { + if (save) { //save the world + // We need to flush everything as next thing we'll be copying all the files. + // this is mostly the reason for #81 - minecraft doesn't flush during scheduled saves. + log.sendInfoAL(this.commandSource, "Saving server..."); + + server.saveAll(true, true, false); + } + state.set(Optional.of(WorldSavingState.disable(server))); + }); - Globals.INSTANCE.disableWatchdog = true; Globals.INSTANCE.updateTMPFSFlag(server); log.sendInfoAL(this, "Starting backup"); @@ -128,8 +144,11 @@ public record ExecutableBackup(@NotNull MinecraftServer server, throw e; } finally { - Utilities.enableWorldSaving(server); - Globals.INSTANCE.disableWatchdog = false; + if (state.get().isPresent()) { + state.get().get().enable(server); + } + //Utilities.enableWorldSaving(server); + //Globals.INSTANCE.disableWatchdog = false; } return null; @@ -221,13 +240,6 @@ public record ExecutableBackup(@NotNull MinecraftServer server, if(announce) v.announce(); - if (save) { //save the world - // We need to flush everything as next thing we'll be copying all the files. - // this is mostly the reason for #81 - minecraft doesn't flush during scheduled saves. - log.sendInfoAL(this.commandSource, "Saving server..."); - server.saveAll(true, true, false); - } - return v; } } diff --git a/src/main/java/net/szum123321/textile_backup/core/create/compressors/ZipCompressor.java b/src/main/java/net/szum123321/textile_backup/core/create/compressors/ZipCompressor.java index ec4d062..47f7e34 100644 --- a/src/main/java/net/szum123321/textile_backup/core/create/compressors/ZipCompressor.java +++ b/src/main/java/net/szum123321/textile_backup/core/create/compressors/ZipCompressor.java @@ -61,7 +61,7 @@ public class ZipCompressor extends AbstractCompressor { if(input.getPath().isEmpty()) { entry = new ZipArchiveEntry(input.getName()); - + //It's basically just byte[] buff = new byte[(int)input.size()]; int len = input.getInputStream().read(buff);