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()) {
|
if (!dataStore.getStorage().isError()) {
|
||||||
getLogger().info("Closing persistence...");
|
getLogger().info("Closing persistence...");
|
||||||
dataStore.removeAllNames();
|
dataStore.removeAllNames();
|
||||||
|
dataStore.saveAll();
|
||||||
if (!dataStore.getStorage().getProvider().close()) {
|
if (!dataStore.getStorage().getProvider().close()) {
|
||||||
getLogger().warning("Failed to close persistence!");
|
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.mojang.MojangUtils;
|
||||||
import net.artelnatif.nicko.storage.json.JSONStorage;
|
import net.artelnatif.nicko.storage.json.JSONStorage;
|
||||||
import net.artelnatif.nicko.storage.sql.SQLStorage;
|
import net.artelnatif.nicko.storage.sql.SQLStorage;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -39,6 +40,10 @@ public class PlayerDataStore {
|
||||||
names.clear();
|
names.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void saveAll() {
|
||||||
|
Bukkit.getOnlinePlayers().forEach(this::saveData);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public Optional<NickoProfile> getData(UUID uuid) {
|
public Optional<NickoProfile> getData(UUID uuid) {
|
||||||
if (storage.isError()) {
|
if (storage.isError()) {
|
||||||
|
@ -76,9 +81,8 @@ public class PlayerDataStore {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void saveData(Player player) {
|
public void saveData(Player player) {
|
||||||
if (storage.isError()) {
|
if (storage.isError()) { return; }
|
||||||
return;
|
if (!profiles.containsKey(player.getUniqueId())) { return; }
|
||||||
}
|
|
||||||
|
|
||||||
storage.store(player.getUniqueId(), profiles.get(player.getUniqueId()));
|
storage.store(player.getUniqueId(), profiles.get(player.getUniqueId()));
|
||||||
profiles.remove(player.getUniqueId());
|
profiles.remove(player.getUniqueId());
|
||||||
|
|
Loading…
Reference in a new issue