fix overwriting data with previous state

This commit is contained in:
jascotty2 2019-09-10 20:07:26 -05:00
parent 09216ac604
commit fd03365d97
3 changed files with 6 additions and 14 deletions

View File

@ -47,7 +47,6 @@ public class EpicFurnaces extends SongodaPlugin {
private static EpicFurnaces INSTANCE; private static EpicFurnaces INSTANCE;
private final Config dataConfig = new Config(this, "data.yml");
private final Config furnaceRecipeFile = new Config(this, "Furnace Recipes.yml"); private final Config furnaceRecipeFile = new Config(this, "Furnace Recipes.yml");
private final Config levelsFile = new Config(this, "levels.yml"); private final Config levelsFile = new Config(this, "levels.yml");
@ -105,8 +104,6 @@ public class EpicFurnaces extends SongodaPlugin {
new CommandSettings(this, guiManager) new CommandSettings(this, guiManager)
); );
dataConfig.load();
loadLevelManager(); loadLevelManager();
this.furnaceManager = new FurnaceManager(); this.furnaceManager = new FurnaceManager();
@ -114,9 +111,8 @@ public class EpicFurnaces extends SongodaPlugin {
this.boostManager = new BoostManager(); this.boostManager = new BoostManager();
this.blacklistHandler = new BlacklistHandler(); this.blacklistHandler = new BlacklistHandler();
this.checkStorage();
// Load from file // Load from file
this.storage = new StorageYaml(this);
loadFromFile(); loadFromFile();
setupRecipies(); setupRecipies();
@ -300,16 +296,10 @@ public class EpicFurnaces extends SongodaPlugin {
} }
} }
private void checkStorage() {
this.storage = new StorageYaml(this);
}
/* /*
* Saves registered furnaces to file. * Saves registered furnaces to file.
*/ */
private void saveToFile() { private void saveToFile() {
checkStorage();
storage.doSave(); storage.doSave();
} }

View File

@ -11,12 +11,9 @@ import java.util.List;
public abstract class Storage { public abstract class Storage {
protected final EpicFurnaces plugin; protected final EpicFurnaces plugin;
protected final Config dataFile;
public Storage(EpicFurnaces plugin) { public Storage(EpicFurnaces plugin) {
this.plugin = plugin; this.plugin = plugin;
this.dataFile = new Config(plugin, "data.yml");
this.dataFile.load();
} }
public abstract boolean containsGroup(String group); public abstract boolean containsGroup(String group);

View File

@ -1,5 +1,6 @@
package com.songoda.epicfurnaces.storage.types; package com.songoda.epicfurnaces.storage.types;
import com.songoda.core.configuration.Config;
import com.songoda.epicfurnaces.EpicFurnaces; import com.songoda.epicfurnaces.EpicFurnaces;
import com.songoda.epicfurnaces.storage.Storage; import com.songoda.epicfurnaces.storage.Storage;
import com.songoda.epicfurnaces.storage.StorageItem; import com.songoda.epicfurnaces.storage.StorageItem;
@ -12,11 +13,14 @@ import java.util.*;
public class StorageYaml extends Storage { public class StorageYaml extends Storage {
protected final Config dataFile;
private final Map<String, Object> toSave = new HashMap<>(); private final Map<String, Object> toSave = new HashMap<>();
private Map<String, Object> lastSave = null; private Map<String, Object> lastSave = null;
public StorageYaml(EpicFurnaces plugin) { public StorageYaml(EpicFurnaces plugin) {
super(plugin); super(plugin);
this.dataFile = new Config(plugin, "data.yml");
this.dataFile.load();
} }
@Override @Override
@ -62,6 +66,7 @@ public class StorageYaml extends Storage {
@Override @Override
public void doSave() { public void doSave() {
toSave.clear();
this.updateData(plugin); this.updateData(plugin);
if (lastSave == null) if (lastSave == null)