Backup current saved data just incase
This commit is contained in:
parent
b611e4b206
commit
de164e6d69
|
|
@ -6,6 +6,8 @@ import it.unimi.dsi.fastutil.io.BinIO;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.StandardCopyOption;
|
||||||
|
|
||||||
public class SaveTask implements Runnable {
|
public class SaveTask implements Runnable {
|
||||||
|
|
||||||
|
|
@ -20,7 +22,23 @@ public class SaveTask implements Runnable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private synchronized void save() {
|
||||||
File file = new File(fishingEvent.getDataFolder(), "map.bin");
|
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 {
|
try {
|
||||||
BinIO.storeObject(pointsManagement.getPointsMap(), file);
|
BinIO.storeObject(pointsManagement.getPointsMap(), file);
|
||||||
logger.info("Object2IntOpenHashMap saved to map.bin");
|
logger.info("Object2IntOpenHashMap saved to map.bin");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user