Storage Fix

This commit is contained in:
Brianna O'Keefe 2019-03-12 13:51:28 -04:00
parent 1dc3ffa34c
commit eaa426cbf3
2 changed files with 22 additions and 12 deletions

View File

@ -14,10 +14,12 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors;
public class StorageMysql extends Storage { public class StorageMysql extends Storage {
private static Map<String, StorageItem[]> toSave = new HashMap<>(); private static Map<String, StorageItem[]> toSave = new HashMap<>();
private static Map<String, StorageItem[]> lastSave = new HashMap<>(); private static Map<String, StorageItem[]> lastSave = null;
private MySQLDatabase database; private MySQLDatabase database;
public StorageMysql(UltimateStacker instance) { public StorageMysql(UltimateStacker instance) {
@ -71,12 +73,13 @@ public class StorageMysql extends Storage {
@Override @Override
public void doSave() { public void doSave() {
this.updateData(instance); this.updateData(instance);
if (lastSave == null)
lastSave = new HashMap<>(toSave);
if (toSave.isEmpty()) return; if (toSave.isEmpty()) return;
Map<String, StorageItem[]> nextSave = new HashMap<>(toSave); Map<String, StorageItem[]> nextSave = new HashMap<>(toSave);
if (lastSave.isEmpty())
lastSave.putAll(toSave);
this.makeBackup(); this.makeBackup();
this.save(); this.save();
@ -101,8 +104,8 @@ public class StorageMysql extends Storage {
|| !to.getValue()[0].asObject().equals(lastValue) || !to.getValue()[0].asObject().equals(lastValue)
|| to.getValue().length != last.getValue().length) || to.getValue().length != last.getValue().length)
continue; continue;
toSave.remove(toKey); toSave.remove(to.getKey());
for (int i = 0; i < to.getValue().length - 1; i ++) { for (int i = 0; i < to.getValue().length; i ++) {
if (!to.getValue()[i].asObject().toString() if (!to.getValue()[i].asObject().toString()
.equals(last.getValue()[i].asObject().toString())) { .equals(last.getValue()[i].asObject().toString())) {
//Update //Update

View File

@ -15,7 +15,7 @@ import java.util.*;
public class StorageYaml extends Storage { public class StorageYaml extends Storage {
private static final Map<String, Object> toSave = new HashMap<>(); private static final Map<String, Object> toSave = new HashMap<>();
private static final Map<String, Object> lastSave = new HashMap<>(); private static Map<String, Object> lastSave = null;
public StorageYaml(UltimateStacker instance) { public StorageYaml(UltimateStacker instance) {
super(instance); super(instance);
@ -65,12 +65,13 @@ public class StorageYaml extends Storage {
@Override @Override
public void doSave() { public void doSave() {
this.updateData(instance); this.updateData(instance);
if (lastSave == null)
lastSave = new HashMap<>(toSave);
if (toSave.isEmpty()) return; if (toSave.isEmpty()) return;
Map<String, Object> nextSave = new HashMap<>(toSave); Map<String, Object> nextSave = new HashMap<>(toSave);
if (lastSave.isEmpty())
lastSave.putAll(toSave);
this.makeBackup(); this.makeBackup();
this.save(); this.save();
@ -83,18 +84,24 @@ public class StorageYaml extends Storage {
public void save() { public void save() {
try { try {
for (Map.Entry<String, Object> entry : lastSave.entrySet()) { for (Map.Entry<String, Object> entry : lastSave.entrySet()) {
System.out.println("key: " + entry.getKey());
if (toSave.containsKey(entry.getKey())) { if (toSave.containsKey(entry.getKey())) {
System.out.println("found");
Object newValue = toSave.get(entry.getKey()); Object newValue = toSave.get(entry.getKey());
System.out.println(entry.getValue() + ":" + newValue);
if (!entry.getValue().equals(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 { } else {
System.out.println("Deleting " + entry.getValue());
dataFile.getConfig().set(entry.getKey(), null); dataFile.getConfig().set(entry.getKey(), null);
} }
} }
for (Map.Entry<String, Object> entry : toSave.entrySet()) { for (Map.Entry<String, Object> entry : toSave.entrySet()) {
System.out.println(entry.getValue() + " INSERT");
dataFile.getConfig().set(entry.getKey(), entry.getValue()); dataFile.getConfig().set(entry.getKey(), entry.getValue());
} }