Skip to content

Commit

Permalink
Add archives folder for deletion, separate from backup folder.
Browse files Browse the repository at this point in the history
  • Loading branch information
creatorfromhell committed Nov 23, 2023
1 parent ccca780 commit f89809e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/main/java/me/lokka30/phantomworlds/PhantomWorlds.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 11 additions & 8 deletions src/main/java/me/lokka30/phantomworlds/managers/WorldManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
}
Expand Down

0 comments on commit f89809e

Please sign in to comment.