mirror of
https://github.com/songoda/UltimateStacker.git
synced 2024-11-23 10:35:22 +01:00
Storage Fix
This commit is contained in:
parent
1dc3ffa34c
commit
eaa426cbf3
@ -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<String, StorageItem[]> toSave = new HashMap<>();
|
||||
private static Map<String, StorageItem[]> lastSave = new HashMap<>();
|
||||
private static Map<String, StorageItem[]> 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<String, StorageItem[]> 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
|
||||
|
@ -15,7 +15,7 @@ import java.util.*;
|
||||
public class StorageYaml extends Storage {
|
||||
|
||||
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) {
|
||||
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<String, Object> 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<String, Object> 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<String, Object> entry : toSave.entrySet()) {
|
||||
System.out.println(entry.getValue() + " INSERT");
|
||||
dataFile.getConfig().set(entry.getKey(), entry.getValue());
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user