mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 05:06:44 +01:00
Implement backup restoration command. This might work, idk, we'll see.
This commit is contained in:
parent
079289eb74
commit
6fb63c9609
@ -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);
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -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>
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user