Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> chat) {
startBackup(chat, null);
}

public static void startBackup(Consumer<String> 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<String> chat) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> output, boolean shutdown) {
makeSingleBackup(delay, output, shutdown, null);
}

public static void makeSingleBackup(long delay, Consumer<String> output, boolean shutdown, String type) {
try {
if (!shutdown) {
ABCore.disableSaving();
Expand All @@ -296,6 +300,7 @@ public static void makeSingleBackup(long delay, Consumer<String> 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public class ThreadedBackup extends Thread {
private Consumer<String> output;
private boolean snapshot = false;
private boolean shutdown = false;
private String forcedType = null;
private ArrayList<String> erroringFiles = new ArrayList<>();
private String snapshotName = "";

Expand All @@ -64,6 +65,10 @@ public ThreadedBackup(long delay, Consumer<String> output) {
completeSize = 0F;
}

public void setForcedType(String type) {
this.forcedType = type;
}

@Override
public void run() {
try {
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,15 @@ public static void register(CommandDispatcher<ServerCommandSource> 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) -> {
Expand Down