From de164e6d695c7ba476e55dd84e535773958a5d2f Mon Sep 17 00:00:00 2001 From: Teriuihi Date: Sun, 24 Sep 2023 23:59:26 +0200 Subject: [PATCH] Backup current saved data just incase --- .../alttd/fishingevent/points/SaveTask.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/main/java/com/alttd/fishingevent/points/SaveTask.java b/src/main/java/com/alttd/fishingevent/points/SaveTask.java index 25dbf6e..3799542 100644 --- a/src/main/java/com/alttd/fishingevent/points/SaveTask.java +++ b/src/main/java/com/alttd/fishingevent/points/SaveTask.java @@ -6,6 +6,8 @@ import it.unimi.dsi.fastutil.io.BinIO; import java.io.File; import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.StandardCopyOption; public class SaveTask implements Runnable { @@ -20,7 +22,23 @@ public class SaveTask implements Runnable { @Override public void run() { + + } + + private synchronized void save() { File file = new File(fishingEvent.getDataFolder(), "map.bin"); + if (file.exists()) { + File oldFile = new File(fishingEvent.getDataFolder(), "map.bin.old"); + if (oldFile.exists() && oldFile.canWrite()) + oldFile.delete(); + if (!file.renameTo(oldFile)) { + try { + Files.copy(file.toPath(), oldFile.toPath(), StandardCopyOption.REPLACE_EXISTING); + } catch (IOException e) { + e.printStackTrace(); + } + } + } try { BinIO.storeObject(pointsManagement.getPointsMap(), file); logger.info("Object2IntOpenHashMap saved to map.bin");