Backup current saved data just incase

This commit is contained in:
Teriuihi 2023-09-24 23:59:26 +02:00
parent b611e4b206
commit de164e6d69

View File

@ -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");