diff --git a/src/main/java/com/songoda/ultimatestacker/storage/types/StorageMysql.java b/src/main/java/com/songoda/ultimatestacker/storage/types/StorageMysql.java index 511453c..bb7906d 100644 --- a/src/main/java/com/songoda/ultimatestacker/storage/types/StorageMysql.java +++ b/src/main/java/com/songoda/ultimatestacker/storage/types/StorageMysql.java @@ -14,10 +14,12 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; + public class StorageMysql extends Storage { private static Map toSave = new HashMap<>(); - private static Map lastSave = new HashMap<>(); + private static Map lastSave = null; private MySQLDatabase database; public StorageMysql(UltimateStacker instance) { @@ -71,12 +73,13 @@ public class StorageMysql extends Storage { @Override public void doSave() { this.updateData(instance); + + if (lastSave == null) + lastSave = new HashMap<>(toSave); + if (toSave.isEmpty()) return; Map nextSave = new HashMap<>(toSave); - if (lastSave.isEmpty()) - lastSave.putAll(toSave); - this.makeBackup(); this.save(); @@ -101,8 +104,8 @@ public class StorageMysql extends Storage { || !to.getValue()[0].asObject().equals(lastValue) || to.getValue().length != last.getValue().length) continue; - toSave.remove(toKey); - for (int i = 0; i < to.getValue().length - 1; i ++) { + toSave.remove(to.getKey()); + for (int i = 0; i < to.getValue().length; i ++) { if (!to.getValue()[i].asObject().toString() .equals(last.getValue()[i].asObject().toString())) { //Update diff --git a/src/main/java/com/songoda/ultimatestacker/storage/types/StorageYaml.java b/src/main/java/com/songoda/ultimatestacker/storage/types/StorageYaml.java index f1a860e..4b73b1f 100644 --- a/src/main/java/com/songoda/ultimatestacker/storage/types/StorageYaml.java +++ b/src/main/java/com/songoda/ultimatestacker/storage/types/StorageYaml.java @@ -15,7 +15,7 @@ import java.util.*; public class StorageYaml extends Storage { private static final Map toSave = new HashMap<>(); - private static final Map lastSave = new HashMap<>(); + private static Map lastSave = null; public StorageYaml(UltimateStacker instance) { super(instance); @@ -65,12 +65,13 @@ public class StorageYaml extends Storage { @Override public void doSave() { this.updateData(instance); + + if (lastSave == null) + lastSave = new HashMap<>(toSave); + if (toSave.isEmpty()) return; Map nextSave = new HashMap<>(toSave); - if (lastSave.isEmpty()) - lastSave.putAll(toSave); - this.makeBackup(); this.save(); @@ -83,18 +84,24 @@ public class StorageYaml extends Storage { public void save() { try { for (Map.Entry entry : lastSave.entrySet()) { + System.out.println("key: " + entry.getKey()); if (toSave.containsKey(entry.getKey())) { + System.out.println("found"); Object newValue = toSave.get(entry.getKey()); + System.out.println(entry.getValue() + ":" + newValue); if (!entry.getValue().equals(newValue)) { - dataFile.getConfig().set(entry.getKey(), entry.getValue()); + System.out.println("new value"); + dataFile.getConfig().set(entry.getKey(), newValue); } - toSave.remove(newValue); + toSave.remove(entry.getKey()); } else { + System.out.println("Deleting " + entry.getValue()); dataFile.getConfig().set(entry.getKey(), null); } } for (Map.Entry entry : toSave.entrySet()) { + System.out.println(entry.getValue() + " INSERT"); dataFile.getConfig().set(entry.getKey(), entry.getValue()); }