Implement backup restoration command. This might work, idk, we'll see.

This commit is contained in:
Alexander Söderberg 2020-05-10 16:53:19 +02:00
parent 079289eb74
commit 6fb63c9609
No known key found for this signature in database
GPG key ID: C0207FF7EA146678
2 changed files with 29 additions and 5 deletions

View file

@ -36,6 +36,7 @@ import com.plotsquared.core.util.Permissions;
import com.plotsquared.core.util.task.RunnableVal2;
import com.plotsquared.core.util.task.RunnableVal3;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@ -127,9 +128,9 @@ public final class Backup extends Command {
} else {
backupProfile.createBackup().whenComplete((backup, throwable) -> {
if (throwable != null) {
sendMessage(player, Captions.BACKUP_FAILED, throwable.getMessage());
sendMessage(player, Captions.BACKUP_SAVE_FAILED, throwable.getMessage());
} else {
sendMessage(player, Captions.BACKUP_SAVED);
sendMessage(player, Captions.BACKUP_SAVE_SUCCESS);
}
});
}
@ -200,7 +201,27 @@ public final class Backup extends Command {
sendMessage(player, Captions.BACKUP_IMPOSSIBLE, Captions.GENERIC_OTHER.getTranslated());
} else {
backupProfile.listBackups().whenComplete((backups, throwable) -> {
// TODO: Load backups
if (throwable != null) {
sendMessage(player, Captions.BACKUP_LOAD_FAILURE, throwable.getMessage());
} else {
if (number < 1 || number > backups.size()) {
sendMessage(player, Captions.BACKUP_LOAD_FAILURE, Captions.GENERIC_INVALID_CHOICE.getTranslated());
} else {
final com.plotsquared.core.backup.Backup backup = backups.get(number - 1);
if (backup == null || backup.getFile() == null || !Files.exists(backup.getFile())) {
sendMessage(player, Captions.BACKUP_LOAD_FAILURE, Captions.GENERIC_INVALID_CHOICE.getTranslated());
} else {
CmdConfirm.addPending(player, "/plot backup load " + number, () ->
backupProfile.restoreBackup(backup).whenComplete((n, error) -> {
if (error != null) {
sendMessage(player, Captions.BACKUP_LOAD_FAILURE, error.getMessage());
} else {
sendMessage(player, Captions.BACKUP_LOAD_SUCCESS);
}
}));
}
}
}
});
}
}

View file

@ -765,8 +765,10 @@ public enum Captions implements Caption {
//<editor-fold desc="Backups">
BACKUP_USAGE("$1Usage: $2/plot backup save/list/load", "Backups"),
BACKUP_IMPOSSIBLE("$2Backups are not enabled for this plot: %s", "Backups"),
BACKUP_SAVED("$1The backup was created successfully", "Backups"),
BACKUP_FAILED("$2The backup could not be created: %s", "Backups"),
BACKUP_SAVE_SUCCESS("$1The backup was created successfully", "Backups"),
BACKUP_SAVE_FAILED("$2The backup could not be created: %s", "Backups"),
BACKUP_LOAD_SUCCESS("$1The backup was restored successfully", "Backups"),
BACKUP_LOAD_FAILURE("$2The backup could not be restored: %s", "Backups"),
BACKUP_LOAD_USAGE("$1Usage: $2/plot backup load [#]", "Backups"),
//</editor-fold>
@ -774,6 +776,7 @@ public enum Captions implements Caption {
GENERIC_OTHER("other", "Generic"),
GENERIC_MERGED("merged", "Generic"),
GENERIC_UNOWNED("unowned", "Generic"),
GENERIC_INVALID_CHOICE("invalid choice", "Generic"),
//</editor-fold>
/**