diff --git a/src/main/java/tsp/headdb/core/command/CommandMain.java b/src/main/java/tsp/headdb/core/command/CommandMain.java index 7494c72..0779911 100644 --- a/src/main/java/tsp/headdb/core/command/CommandMain.java +++ b/src/main/java/tsp/headdb/core/command/CommandMain.java @@ -104,6 +104,8 @@ public class CommandMain extends HeadDBCommand implements CommandExecutor, TabCo } })); } + + main.open(player); })); pane.setButton(getInstance().getConfig().getInt("gui.main.meta.search.slot"), new Button(Utils.getItemFromConfig("gui.main.meta.search.item", Material.DARK_OAK_SIGN), e -> { diff --git a/src/main/java/tsp/headdb/core/storage/PlayerStorage.java b/src/main/java/tsp/headdb/core/storage/PlayerStorage.java index 14dd0b5..5004efd 100644 --- a/src/main/java/tsp/headdb/core/storage/PlayerStorage.java +++ b/src/main/java/tsp/headdb/core/storage/PlayerStorage.java @@ -4,19 +4,19 @@ import tsp.headdb.HeadDB; import tsp.warehouse.storage.file.SerializableFileDataManager; import java.io.File; -import java.util.Collection; import java.util.Collections; import java.util.HashMap; +import java.util.HashSet; import java.util.Map; import java.util.Optional; import java.util.UUID; -public class PlayerStorage extends SerializableFileDataManager> { +public class PlayerStorage extends SerializableFileDataManager> { private final Map players = new HashMap<>(); - public PlayerStorage(Storage storage) { - super(new File("data/players.data"), storage.getExecutor()); + public PlayerStorage(HeadDB instance, Storage storage) { + super(new File(instance.getDataFolder(), "data/players.data"), storage.getExecutor()); } public void set(PlayerData data) { @@ -42,11 +42,11 @@ public class PlayerStorage extends SerializableFileDataManager HeadDB.getInstance().getLog().debug("Saved " + players.values().size() + " player data!")); + save(new HashSet<>(players.values())).whenComplete((success, ex) -> HeadDB.getInstance().getLog().debug("Saved " + players.values().size() + " player data!")); } public void suspend() { - Boolean saved = save(players.values()) + Boolean saved = save(new HashSet<>(players.values())) .exceptionally(ex -> { HeadDB.getInstance().getLog().error("Failed to save player data! | Stack Trace: "); ex.printStackTrace(); diff --git a/src/main/java/tsp/headdb/core/storage/Storage.java b/src/main/java/tsp/headdb/core/storage/Storage.java index 1cb46d1..ca5d775 100644 --- a/src/main/java/tsp/headdb/core/storage/Storage.java +++ b/src/main/java/tsp/headdb/core/storage/Storage.java @@ -1,5 +1,8 @@ package tsp.headdb.core.storage; +import tsp.headdb.HeadDB; + +import java.io.File; import java.util.concurrent.Executor; import java.util.concurrent.Executors; @@ -10,7 +13,8 @@ public class Storage { public Storage(int threads) { executor = Executors.newFixedThreadPool(threads, HeadDBThreadFactory.FACTORY); - playerStorage = new PlayerStorage(this); + validateDataDirectory(); + playerStorage = new PlayerStorage(HeadDB.getInstance(), this); } public PlayerStorage getPlayerStorage() { @@ -21,4 +25,9 @@ public class Storage { return executor; } + private void validateDataDirectory() { + //noinspection ResultOfMethodCallIgnored + new File(HeadDB.getInstance().getDataFolder(), "data").mkdir(); + } + } diff --git a/src/main/java/tsp/headdb/core/task/UpdateTask.java b/src/main/java/tsp/headdb/core/task/UpdateTask.java index 2d0de6c..faf22d7 100644 --- a/src/main/java/tsp/headdb/core/task/UpdateTask.java +++ b/src/main/java/tsp/headdb/core/task/UpdateTask.java @@ -18,7 +18,7 @@ public class UpdateTask implements Task { @Override public void run() { HeadAPI.getDatabase().update((time, heads) -> HeadDB.getInstance().getLog().debug("Fetched: " + heads.size() + " Heads | Provider: " + HeadAPI.getDatabase().getRequester().getProvider().name() + " | Time: " + time + "ms (" + TimeUnit.MILLISECONDS.toSeconds(time) + "s)")); - //HeadDB.getInstance().getStorage().save(); + HeadDB.getInstance().getStorage().getPlayerStorage().backup(); HeadDB.getInstance().getLog().debug("UpdateTask finished!"); }