diff --git a/Core/src/main/java/com/plotsquared/core/command/Backup.java b/Core/src/main/java/com/plotsquared/core/command/Backup.java index 5f9522194..60cba6d6c 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Backup.java +++ b/Core/src/main/java/com/plotsquared/core/command/Backup.java @@ -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); + } + })); + } + } + } }); } } diff --git a/Core/src/main/java/com/plotsquared/core/configuration/Captions.java b/Core/src/main/java/com/plotsquared/core/configuration/Captions.java index 20d6193ea..486a4db90 100644 --- a/Core/src/main/java/com/plotsquared/core/configuration/Captions.java +++ b/Core/src/main/java/com/plotsquared/core/configuration/Captions.java @@ -765,8 +765,10 @@ public enum Captions implements Caption { // 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"), // @@ -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"), // /**