Skip to content

Commit

Permalink
Update Persist.java
Browse files Browse the repository at this point in the history
fixed the code so it actually compiles and added a check for if we can successfully backup the config (disables plugin if we can't)
  • Loading branch information
sh0inx committed Oct 12, 2023
1 parent e78fddc commit a782c79
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions plugin/src/main/java/com/iridium/iridiumcore/Persist.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Type;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.Locale;

/**
Expand Down Expand Up @@ -183,10 +185,18 @@ public <T> T load(Class<T> clazz, File file) {
} catch (IOException e) {
javaPlugin.getLogger().severe("Failed to parse " + file + ": " + e.getMessage());
javaPlugin.getLogger().severe("Getting a backup for " + file + " into backups folder");
configFile.renameTo(new File(javaPlugin.getDataFolder(), "broken_" + name + persistType.getExtension()));
File backupFolder = new File(pluginFolder.getPath(), "backups");
backupFolder.mkdirs();
Files.move(configFile.toPath(), backupFolder.toPath(), StandardCopyOption.REPLACE_EXISTING);
try {
file.renameTo(new File(javaPlugin.getDataFolder(), "broken_" + file.getName() + persistType.getExtension()));
File backupFolder = new File(javaPlugin.getDataFolder().getPath(), "backups");
backupFolder.mkdirs();
Files.move(file.toPath(), backupFolder.toPath(), StandardCopyOption.REPLACE_EXISTING);
} catch (IOException exception) {
javaPlugin.getLogger().severe(
"Failed to move " + file + " to "
+ javaPlugin.getDataFolder().getName() + File.separator + "backups: "
+ exception.getMessage());
Bukkit.getPluginManager().disablePlugin(javaPlugin);
}
}
}
try {
Expand Down

0 comments on commit a782c79

Please sign in to comment.