From 02066c37d516cfb5a82fbb848b16345c388b519f Mon Sep 17 00:00:00 2001 From: ASangarin Date: Sat, 4 Jul 2020 16:42:46 +0200 Subject: [PATCH] MySQL PlayerData now saves/loads properly when switching servers --- .../java/net/Indyuce/mmocore/listener/PlayerListener.java | 2 ++ .../Indyuce/mmocore/manager/data/PlayerDataManager.java | 8 +++++++- .../manager/data/mysql/MySQLPlayerDataManager.java | 6 ++++++ .../mmocore/manager/data/yaml/YAMLPlayerDataManager.java | 3 +++ 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/Indyuce/mmocore/listener/PlayerListener.java b/src/main/java/net/Indyuce/mmocore/listener/PlayerListener.java index 87169277..7c0319dc 100644 --- a/src/main/java/net/Indyuce/mmocore/listener/PlayerListener.java +++ b/src/main/java/net/Indyuce/mmocore/listener/PlayerListener.java @@ -70,6 +70,8 @@ public class PlayerListener implements Listener { PlayerData playerData = PlayerData.get(event.getPlayer()); if (playerData.hasParty()) playerData.getParty().removeMember(playerData); + + MMOCore.plugin.dataProvider.getDataManager().remove(playerData); } /* diff --git a/src/main/java/net/Indyuce/mmocore/manager/data/PlayerDataManager.java b/src/main/java/net/Indyuce/mmocore/manager/data/PlayerDataManager.java index 7b8cdb49..014487c9 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/data/PlayerDataManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/data/PlayerDataManager.java @@ -25,6 +25,10 @@ public abstract class PlayerDataManager { return map.getOrDefault(uuid, PlayerData.NOT_LOADED); } + public void remove(UUID uuid) { + map.remove(uuid); + } + public abstract OfflinePlayerData getOffline(UUID uuid); public void setup(Player player) { @@ -54,7 +58,7 @@ public abstract class PlayerDataManager { public boolean isLoaded(UUID uuid) { return map.containsKey(uuid); } - + public Collection getLoaded() { return map.values(); } @@ -62,4 +66,6 @@ public abstract class PlayerDataManager { public abstract void loadData(PlayerData data); public abstract void saveData(PlayerData data); + + public abstract void remove(PlayerData data); } diff --git a/src/main/java/net/Indyuce/mmocore/manager/data/mysql/MySQLPlayerDataManager.java b/src/main/java/net/Indyuce/mmocore/manager/data/mysql/MySQLPlayerDataManager.java index 3b33783d..f126bdfd 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/data/mysql/MySQLPlayerDataManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/data/mysql/MySQLPlayerDataManager.java @@ -231,4 +231,10 @@ public class MySQLPlayerDataManager extends PlayerDataManager { return lastLogin; } } + + @Override + public void remove(PlayerData data) { + saveData(data); + remove(data.getUniqueId()); + } } diff --git a/src/main/java/net/Indyuce/mmocore/manager/data/yaml/YAMLPlayerDataManager.java b/src/main/java/net/Indyuce/mmocore/manager/data/yaml/YAMLPlayerDataManager.java index d0ae7292..67f9f0e8 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/data/yaml/YAMLPlayerDataManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/data/yaml/YAMLPlayerDataManager.java @@ -127,4 +127,7 @@ public class YAMLPlayerDataManager extends PlayerDataManager { public OfflinePlayerData getOffline(UUID uuid) { return isLoaded(uuid) ? get(uuid) : new YAMLOfflinePlayerData(uuid); } + + @Override + public void remove(PlayerData data) {} }