From fd03365d9741335459a3caa081d54fc887588a32 Mon Sep 17 00:00:00 2001 From: jascotty2 Date: Tue, 10 Sep 2019 20:07:26 -0500 Subject: [PATCH] fix overwriting data with previous state --- .../java/com/songoda/epicfurnaces/EpicFurnaces.java | 12 +----------- .../com/songoda/epicfurnaces/storage/Storage.java | 3 --- .../epicfurnaces/storage/types/StorageYaml.java | 5 +++++ 3 files changed, 6 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/songoda/epicfurnaces/EpicFurnaces.java b/src/main/java/com/songoda/epicfurnaces/EpicFurnaces.java index f7fb3b4..c700b3f 100644 --- a/src/main/java/com/songoda/epicfurnaces/EpicFurnaces.java +++ b/src/main/java/com/songoda/epicfurnaces/EpicFurnaces.java @@ -47,7 +47,6 @@ public class EpicFurnaces extends SongodaPlugin { 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 levelsFile = new Config(this, "levels.yml"); @@ -105,8 +104,6 @@ public class EpicFurnaces extends SongodaPlugin { new CommandSettings(this, guiManager) ); - dataConfig.load(); - loadLevelManager(); this.furnaceManager = new FurnaceManager(); @@ -114,9 +111,8 @@ public class EpicFurnaces extends SongodaPlugin { this.boostManager = new BoostManager(); this.blacklistHandler = new BlacklistHandler(); - this.checkStorage(); - // Load from file + this.storage = new StorageYaml(this); loadFromFile(); setupRecipies(); @@ -300,16 +296,10 @@ public class EpicFurnaces extends SongodaPlugin { } } - private void checkStorage() { - this.storage = new StorageYaml(this); - } - /* * Saves registered furnaces to file. */ private void saveToFile() { - checkStorage(); - storage.doSave(); } diff --git a/src/main/java/com/songoda/epicfurnaces/storage/Storage.java b/src/main/java/com/songoda/epicfurnaces/storage/Storage.java index a71fe5e..81f84fb 100644 --- a/src/main/java/com/songoda/epicfurnaces/storage/Storage.java +++ b/src/main/java/com/songoda/epicfurnaces/storage/Storage.java @@ -11,12 +11,9 @@ import java.util.List; public abstract class Storage { protected final EpicFurnaces plugin; - protected final Config dataFile; public Storage(EpicFurnaces plugin) { this.plugin = plugin; - this.dataFile = new Config(plugin, "data.yml"); - this.dataFile.load(); } public abstract boolean containsGroup(String group); diff --git a/src/main/java/com/songoda/epicfurnaces/storage/types/StorageYaml.java b/src/main/java/com/songoda/epicfurnaces/storage/types/StorageYaml.java index 9519bed..c57233f 100644 --- a/src/main/java/com/songoda/epicfurnaces/storage/types/StorageYaml.java +++ b/src/main/java/com/songoda/epicfurnaces/storage/types/StorageYaml.java @@ -1,5 +1,6 @@ package com.songoda.epicfurnaces.storage.types; +import com.songoda.core.configuration.Config; import com.songoda.epicfurnaces.EpicFurnaces; import com.songoda.epicfurnaces.storage.Storage; import com.songoda.epicfurnaces.storage.StorageItem; @@ -12,11 +13,14 @@ import java.util.*; public class StorageYaml extends Storage { + protected final Config dataFile; private final Map toSave = new HashMap<>(); private Map lastSave = null; public StorageYaml(EpicFurnaces plugin) { super(plugin); + this.dataFile = new Config(plugin, "data.yml"); + this.dataFile.load(); } @Override @@ -62,6 +66,7 @@ public class StorageYaml extends Storage { @Override public void doSave() { + toSave.clear(); this.updateData(plugin); if (lastSave == null)