3
0
Mirror von https://github.com/TheSilentPro/HeadDB.git synchronisiert 2024-12-27 11:20:05 +01:00

use impl of set

Dieser Commit ist enthalten in:
Silent 2022-11-13 03:41:44 +01:00
Ursprung 796652ed95
Commit 6f415e58ca
4 geänderte Dateien mit 19 neuen und 8 gelöschten Zeilen

Datei anzeigen

@ -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 -> { pane.setButton(getInstance().getConfig().getInt("gui.main.meta.search.slot"), new Button(Utils.getItemFromConfig("gui.main.meta.search.item", Material.DARK_OAK_SIGN), e -> {

Datei anzeigen

@ -4,19 +4,19 @@ import tsp.headdb.HeadDB;
import tsp.warehouse.storage.file.SerializableFileDataManager; import tsp.warehouse.storage.file.SerializableFileDataManager;
import java.io.File; import java.io.File;
import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.UUID; import java.util.UUID;
public class PlayerStorage extends SerializableFileDataManager<Collection<PlayerData>> { public class PlayerStorage extends SerializableFileDataManager<HashSet<PlayerData>> {
private final Map<UUID, PlayerData> players = new HashMap<>(); private final Map<UUID, PlayerData> players = new HashMap<>();
public PlayerStorage(Storage storage) { public PlayerStorage(HeadDB instance, Storage storage) {
super(new File("data/players.data"), storage.getExecutor()); super(new File(instance.getDataFolder(), "data/players.data"), storage.getExecutor());
} }
public void set(PlayerData data) { public void set(PlayerData data) {
@ -42,11 +42,11 @@ public class PlayerStorage extends SerializableFileDataManager<Collection<Player
} }
public void backup() { public void backup() {
save(players.values()).whenComplete((success, ex) -> 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() { public void suspend() {
Boolean saved = save(players.values()) Boolean saved = save(new HashSet<>(players.values()))
.exceptionally(ex -> { .exceptionally(ex -> {
HeadDB.getInstance().getLog().error("Failed to save player data! | Stack Trace: "); HeadDB.getInstance().getLog().error("Failed to save player data! | Stack Trace: ");
ex.printStackTrace(); ex.printStackTrace();

Datei anzeigen

@ -1,5 +1,8 @@
package tsp.headdb.core.storage; package tsp.headdb.core.storage;
import tsp.headdb.HeadDB;
import java.io.File;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
@ -10,7 +13,8 @@ public class Storage {
public Storage(int threads) { public Storage(int threads) {
executor = Executors.newFixedThreadPool(threads, HeadDBThreadFactory.FACTORY); executor = Executors.newFixedThreadPool(threads, HeadDBThreadFactory.FACTORY);
playerStorage = new PlayerStorage(this); validateDataDirectory();
playerStorage = new PlayerStorage(HeadDB.getInstance(), this);
} }
public PlayerStorage getPlayerStorage() { public PlayerStorage getPlayerStorage() {
@ -21,4 +25,9 @@ public class Storage {
return executor; return executor;
} }
private void validateDataDirectory() {
//noinspection ResultOfMethodCallIgnored
new File(HeadDB.getInstance().getDataFolder(), "data").mkdir();
}
} }

Datei anzeigen

@ -18,7 +18,7 @@ public class UpdateTask implements Task {
@Override @Override
public void run() { 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)")); 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!"); HeadDB.getInstance().getLog().debug("UpdateTask finished!");
} }