From f89809e51dbeda0a4b305081b3c62ae6f4046954 Mon Sep 17 00:00:00 2001 From: creatorfromhell Date: Wed, 22 Nov 2023 20:59:59 -0500 Subject: [PATCH] Add archives folder for deletion, separate from backup folder. --- .../lokka30/phantomworlds/PhantomWorlds.java | 1 + .../phantomworlds/managers/WorldManager.java | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/main/java/me/lokka30/phantomworlds/PhantomWorlds.java b/src/main/java/me/lokka30/phantomworlds/PhantomWorlds.java index 8e29cea..b4b718d 100644 --- a/src/main/java/me/lokka30/phantomworlds/PhantomWorlds.java +++ b/src/main/java/me/lokka30/phantomworlds/PhantomWorlds.java @@ -55,6 +55,7 @@ public class PhantomWorlds extends JavaPlugin { public static final String[] CONTRIBUTORS = new String[]{"madison-allen"}; public static final String BACKUP_FOLDER = "backups"; + public static final String ARCHIVE_FOLDER = "archives"; /** * This is reported in the 'pw info' command to inform the command sender of what MC versions that diff --git a/src/main/java/me/lokka30/phantomworlds/managers/WorldManager.java b/src/main/java/me/lokka30/phantomworlds/managers/WorldManager.java index 0ddb1ff..201a514 100644 --- a/src/main/java/me/lokka30/phantomworlds/managers/WorldManager.java +++ b/src/main/java/me/lokka30/phantomworlds/managers/WorldManager.java @@ -115,20 +115,23 @@ public PhantomWorld getPhantomWorldFromData(final String name) { } return world; } - + public boolean backupWorld(final String world) { + return backupWorld(world, new File(PhantomWorlds.instance().getDataFolder(), PhantomWorlds.BACKUP_FOLDER)); + } + + public boolean backupWorld(final String world, final File backupFolder) { final File worldFolder = new File(Bukkit.getWorldContainer(), world); - final File backupFolder = new File(PhantomWorlds.instance().getDataFolder(), PhantomWorlds.BACKUP_FOLDER); try { - final String timestamp = String.valueOf(System.currentTimeMillis()); - final File timestampedBackupFolder = new File(backupFolder + File.separator + world, world + "_" + timestamp); - timestampedBackupFolder.mkdir(); + final File worldBackupFolder = new File(backupFolder, world); + worldBackupFolder.mkdir(); - final String zipFilePath = new File(timestampedBackupFolder, world + ".zip").getPath(); + final String timestamp = String.valueOf(System.currentTimeMillis()); + final String zipFilePath = new File(worldBackupFolder, world + "-" + timestamp + ".zip").getPath(); zipFolder(worldFolder, zipFilePath); - PhantomWorlds.logger().info("World '" + world + "' backed up to: " + timestampedBackupFolder.getPath()); + PhantomWorlds.logger().info("World '" + world + "' backed up to: " + worldBackupFolder.getPath()); return true; } catch (IOException e) { e.printStackTrace(); @@ -145,7 +148,7 @@ public boolean backupAndDeleteWorld(final String worldName) { } if(PhantomWorlds.instance().settings.getConfig().getBoolean("delete-archive", true)) { - if(!backupWorld(world.getName())) { + if(!backupWorld(world.getName(), new File(PhantomWorlds.instance().getDataFolder(), PhantomWorlds.ARCHIVE_FOLDER))) { PhantomWorlds.logger().warning("Unable to backup world '" + worldName + "'! Halting deletion."); return false; }