From 05f3ca087a337c1eaf0b93416f5ba890f2f50a4d Mon Sep 17 00:00:00 2001 From: Shyanne Date: Fri, 29 Sep 2023 19:20:02 -0400 Subject: [PATCH 1/2] Added backupConfigs added `backupConfigs` to copy all current config files (and database) to a backup folder on plugin load / reload (thank you faun for helping me fix this mess) --- .../iridiumskyblock/IridiumSkyblock.java | 32 +++++++++++++++++-- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/iridium/iridiumskyblock/IridiumSkyblock.java b/src/main/java/com/iridium/iridiumskyblock/IridiumSkyblock.java index 4de2f3959..846ea2ed5 100644 --- a/src/main/java/com/iridium/iridiumskyblock/IridiumSkyblock.java +++ b/src/main/java/com/iridium/iridiumskyblock/IridiumSkyblock.java @@ -21,9 +21,7 @@ import org.bukkit.plugin.RegisteredServiceProvider; import org.bukkit.plugin.java.JavaPluginLoader; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; +import java.io.*; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.StandardCopyOption; @@ -146,6 +144,7 @@ public void registerListeners() { @Override public void loadConfigs() { + backupConfigs("backup"); this.configuration = getPersist().load(Configuration.class); this.messages = getPersist().load(Messages.class); this.commands = getPersist().load(Commands.class); @@ -275,6 +274,33 @@ private void saveFile(File parent, String name) { } } + private void backupConfigs(String backupFolderName) { + + getLogger().info("Attempting to create backup of configuration files..."); + + File pluginFolder = new File(getDataFolder().getPath()); + File backupFolder = new File(pluginFolder.getPath() + File.separator + backupFolderName); + if (!backupFolder.exists()) backupFolder.mkdir(); + + File[] configFiles = pluginFolder.listFiles((dir, name) -> name.endsWith(".yml") || name.endsWith(".db")); + + if(configFiles == null) { + getLogger().info("No files found."); + return; + } + + for (File configFile : configFiles) { + File backupFile = new File(backupFolder, configFile.getName()); + + try { + Files.copy(configFile.toPath(), backupFile.toPath(), StandardCopyOption.REPLACE_EXISTING); + } catch (IOException exception) { + getLogger().warning("Could not copy " + configFile.getName() + " to " + backupFile.getAbsolutePath()); + } + } + getLogger().info("Backup successful, check " + backupFolder.getPath() + "."); + } + @Override public ChunkGenerator getDefaultWorldGenerator(String worldName, String id) { return this.chunkGenerator; From 4e8a81e9ebac7fd75c9e38c8a700f7098ac51558 Mon Sep 17 00:00:00 2001 From: Shyanne Date: Wed, 11 Oct 2023 17:15:03 -0400 Subject: [PATCH 2/2] Update IridiumSkyblock.java moved backupConfigs to IridiumTeams (super) for cross-plugin usage --- .../iridiumskyblock/IridiumSkyblock.java | 29 +------------------ 1 file changed, 1 insertion(+), 28 deletions(-) diff --git a/src/main/java/com/iridium/iridiumskyblock/IridiumSkyblock.java b/src/main/java/com/iridium/iridiumskyblock/IridiumSkyblock.java index 846ea2ed5..1bee1c873 100644 --- a/src/main/java/com/iridium/iridiumskyblock/IridiumSkyblock.java +++ b/src/main/java/com/iridium/iridiumskyblock/IridiumSkyblock.java @@ -144,7 +144,7 @@ public void registerListeners() { @Override public void loadConfigs() { - backupConfigs("backup"); + super.backupConfigs("backup"); this.configuration = getPersist().load(Configuration.class); this.messages = getPersist().load(Messages.class); this.commands = getPersist().load(Commands.class); @@ -274,33 +274,6 @@ private void saveFile(File parent, String name) { } } - private void backupConfigs(String backupFolderName) { - - getLogger().info("Attempting to create backup of configuration files..."); - - File pluginFolder = new File(getDataFolder().getPath()); - File backupFolder = new File(pluginFolder.getPath() + File.separator + backupFolderName); - if (!backupFolder.exists()) backupFolder.mkdir(); - - File[] configFiles = pluginFolder.listFiles((dir, name) -> name.endsWith(".yml") || name.endsWith(".db")); - - if(configFiles == null) { - getLogger().info("No files found."); - return; - } - - for (File configFile : configFiles) { - File backupFile = new File(backupFolder, configFile.getName()); - - try { - Files.copy(configFile.toPath(), backupFile.toPath(), StandardCopyOption.REPLACE_EXISTING); - } catch (IOException exception) { - getLogger().warning("Could not copy " + configFile.getName() + " to " + backupFile.getAbsolutePath()); - } - } - getLogger().info("Backup successful, check " + backupFolder.getPath() + "."); - } - @Override public ChunkGenerator getDefaultWorldGenerator(String worldName, String id) { return this.chunkGenerator;