feat: save all on shutdown
This commit is contained in:
parent
44b4fdd618
commit
b176296b24
2 changed files with 9 additions and 4 deletions
|
@ -65,6 +65,7 @@ public class NickoBukkit extends JavaPlugin {
|
|||
if (!dataStore.getStorage().isError()) {
|
||||
getLogger().info("Closing persistence...");
|
||||
dataStore.removeAllNames();
|
||||
dataStore.saveAll();
|
||||
if (!dataStore.getStorage().getProvider().close()) {
|
||||
getLogger().warning("Failed to close persistence!");
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import net.artelnatif.nicko.disguise.NickoProfile;
|
|||
import net.artelnatif.nicko.mojang.MojangUtils;
|
||||
import net.artelnatif.nicko.storage.json.JSONStorage;
|
||||
import net.artelnatif.nicko.storage.sql.SQLStorage;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -22,7 +23,7 @@ public class PlayerDataStore {
|
|||
}
|
||||
|
||||
public void storeName(Player player) {
|
||||
if(!isNameStored(player)) {
|
||||
if (!isNameStored(player)) {
|
||||
names.put(player.getUniqueId(), player.getName());
|
||||
}
|
||||
}
|
||||
|
@ -39,6 +40,10 @@ public class PlayerDataStore {
|
|||
names.clear();
|
||||
}
|
||||
|
||||
public void saveAll() {
|
||||
Bukkit.getOnlinePlayers().forEach(this::saveData);
|
||||
}
|
||||
|
||||
|
||||
public Optional<NickoProfile> getData(UUID uuid) {
|
||||
if (storage.isError()) {
|
||||
|
@ -76,9 +81,8 @@ public class PlayerDataStore {
|
|||
}
|
||||
|
||||
public void saveData(Player player) {
|
||||
if (storage.isError()) {
|
||||
return;
|
||||
}
|
||||
if (storage.isError()) { return; }
|
||||
if (!profiles.containsKey(player.getUniqueId())) { return; }
|
||||
|
||||
storage.store(player.getUniqueId(), profiles.get(player.getUniqueId()));
|
||||
profiles.remove(player.getUniqueId());
|
||||
|
|
Loading…
Reference in a new issue