From 2f4786c74d24212d5a80d9c853f9438beb4e2622 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sat, 10 Jan 2026 08:48:55 +0000 Subject: [PATCH] feat: Allow specifying backup type in start command This change implements the ability to specify a backup type (zip, differential, incremental) when manually starting a backup via the command line. This overrides the globally configured backup type for that specific run. Changes include: - `ThreadedBackup`: Added `forcedType` field and logic to use it if present. - `BackupWrapper`: Overloaded `makeSingleBackup` to accept an optional type. - `CoreCommandSystem`: Added `startBackup` overload to pass the type down. - `AdvancedBackupsCommand` (Fabric 1.21): Updated command registration to accept an optional `type` argument with suggestions. This fulfills the "One-off backup types" item from the future plans. --- .../advancedbackups/core/CoreCommandSystem.java | 6 +++++- .../advancedbackups/core/backups/BackupWrapper.java | 7 ++++++- .../advancedbackups/core/backups/ThreadedBackup.java | 10 +++++++++- .../advancedbackups/AdvancedBackupsCommand.java | 10 +++++++++- 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/computer/heather/advancedbackups/core/CoreCommandSystem.java b/core/src/main/java/computer/heather/advancedbackups/core/CoreCommandSystem.java index 670d25d0..5d3a658c 100644 --- a/core/src/main/java/computer/heather/advancedbackups/core/CoreCommandSystem.java +++ b/core/src/main/java/computer/heather/advancedbackups/core/CoreCommandSystem.java @@ -26,13 +26,17 @@ public class CoreCommandSystem { //These methods are all called by relevant command classes in version specific code public static void startBackup(Consumer chat) { + startBackup(chat, null); + } + + public static void startBackup(Consumer chat, String type) { chat.accept("Starting backup..."); BackupWrapper.checkBackups(); //makes sure the backups folder is present etc if (ThreadedBackup.running) { chat.accept("Cannot start a backup whilst a backup is already running!"); return; } - BackupWrapper.makeSingleBackup(0, chat, false); + BackupWrapper.makeSingleBackup(0, chat, false, type); } public static void reloadConfig(Consumer chat) { diff --git a/core/src/main/java/computer/heather/advancedbackups/core/backups/BackupWrapper.java b/core/src/main/java/computer/heather/advancedbackups/core/backups/BackupWrapper.java index b0bf66a0..0ad1668c 100644 --- a/core/src/main/java/computer/heather/advancedbackups/core/backups/BackupWrapper.java +++ b/core/src/main/java/computer/heather/advancedbackups/core/backups/BackupWrapper.java @@ -271,10 +271,14 @@ public static long mostRecentBackupTime() { public static void makeSingleBackup(long delay, boolean shutdown) { - makeSingleBackup(delay, s -> {}, shutdown); + makeSingleBackup(delay, s -> {}, shutdown, null); } public static void makeSingleBackup(long delay, Consumer output, boolean shutdown) { + makeSingleBackup(delay, output, shutdown, null); + } + + public static void makeSingleBackup(long delay, Consumer output, boolean shutdown, String type) { try { if (!shutdown) { ABCore.disableSaving(); @@ -296,6 +300,7 @@ public static void makeSingleBackup(long delay, Consumer output, boolean ThreadedBackup.running = true; ThreadedBackup threadedBackup = new ThreadedBackup(delay, output); if (shutdown) threadedBackup.shutdown(); + if (type != null) threadedBackup.setForcedType(type); threadedBackup.start(); // Don't re-enable saving - leave that down to the backup thread. diff --git a/core/src/main/java/computer/heather/advancedbackups/core/backups/ThreadedBackup.java b/core/src/main/java/computer/heather/advancedbackups/core/backups/ThreadedBackup.java index 50783665..1092b2de 100644 --- a/core/src/main/java/computer/heather/advancedbackups/core/backups/ThreadedBackup.java +++ b/core/src/main/java/computer/heather/advancedbackups/core/backups/ThreadedBackup.java @@ -45,6 +45,7 @@ public class ThreadedBackup extends Thread { private Consumer output; private boolean snapshot = false; private boolean shutdown = false; + private String forcedType = null; private ArrayList erroringFiles = new ArrayList<>(); private String snapshotName = ""; @@ -64,6 +65,10 @@ public ThreadedBackup(long delay, Consumer output) { completeSize = 0F; } + public void setForcedType(String type) { + this.forcedType = type; + } + @Override public void run() { try { @@ -141,7 +146,10 @@ public void makeBackup() throws Exception { return; } - switch (ConfigManager.type.get()) { + String type = ConfigManager.type.get(); + if (forcedType != null) type = forcedType; + + switch (type) { case "zip": { this.makeZipBackup(file, false); break; diff --git a/fabric/1.21/src/main/java/computer/heather/advancedbackups/AdvancedBackupsCommand.java b/fabric/1.21/src/main/java/computer/heather/advancedbackups/AdvancedBackupsCommand.java index 31f75a23..b1ca00dd 100644 --- a/fabric/1.21/src/main/java/computer/heather/advancedbackups/AdvancedBackupsCommand.java +++ b/fabric/1.21/src/main/java/computer/heather/advancedbackups/AdvancedBackupsCommand.java @@ -18,7 +18,15 @@ public static void register(CommandDispatcher stack) { runner.getSource().sendFeedback(() -> Text.of(response), true); }); return 1; - })) + }).then(CommandManager.argument("type", StringArgumentType.word()).suggests((context, builder) -> { + return net.minecraft.command.CommandSource.suggestMatching(new String[]{"zip", "differential", "incremental"}, builder); + }).executes((runner) -> { + String type = StringArgumentType.getString(runner, "type"); + CoreCommandSystem.startBackup((response) -> { + runner.getSource().sendFeedback(() -> Text.of(response), true); + }, type); + return 1; + }))) .then(CommandManager.literal("reload-config").executes((runner) -> { CoreCommandSystem.reloadConfig((response) -> {