/** Load file */ private static void load(Manager managerInterface, File file) { try { managerInterface.load(file); } catch (FileNotFoundException exception) { Bukkit.getServer().getLogger().info(file.getName() + " does not exist! Creating file!"); } catch (IOException exception) { throw new RuntimeException("Failed to load " + file.getPath(), exception); } try { managerInterface.save(file); } catch (IOException exception) { throw new RuntimeException("Failed to create " + file.getPath(), exception); } }
/** Save file */ private static void save(Manager manager, File file) { try { File newFile = new File(file.getAbsolutePath() + ".new"); File bakFile = new File(file.getAbsolutePath() + ".bak"); manager.save(newFile); if (bakFile.exists()) { bakFile.delete(); } if (file.exists() && !file.renameTo(bakFile)) { throw new IOException( "Failed to rename " + file.getAbsolutePath() + " to " + bakFile.getAbsolutePath()); } if (!newFile.renameTo(file)) { throw new IOException( "Failed to rename " + newFile.getAbsolutePath() + " to " + file.getAbsolutePath()); } } catch (IOException exception) { throw new RuntimeException("Failed to save to " + file.getAbsolutePath(), exception); } }