MySQL PlayerData now saves/loads properly when switching servers

This commit is contained in:
ASangarin 2020-07-04 16:42:46 +02:00
parent 349735395e
commit 02066c37d5
4 changed files with 18 additions and 1 deletions

View File

@ -70,6 +70,8 @@ public class PlayerListener implements Listener {
PlayerData playerData = PlayerData.get(event.getPlayer()); PlayerData playerData = PlayerData.get(event.getPlayer());
if (playerData.hasParty()) if (playerData.hasParty())
playerData.getParty().removeMember(playerData); playerData.getParty().removeMember(playerData);
MMOCore.plugin.dataProvider.getDataManager().remove(playerData);
} }
/* /*

View File

@ -25,6 +25,10 @@ public abstract class PlayerDataManager {
return map.getOrDefault(uuid, PlayerData.NOT_LOADED); return map.getOrDefault(uuid, PlayerData.NOT_LOADED);
} }
public void remove(UUID uuid) {
map.remove(uuid);
}
public abstract OfflinePlayerData getOffline(UUID uuid); public abstract OfflinePlayerData getOffline(UUID uuid);
public void setup(Player player) { public void setup(Player player) {
@ -54,7 +58,7 @@ public abstract class PlayerDataManager {
public boolean isLoaded(UUID uuid) { public boolean isLoaded(UUID uuid) {
return map.containsKey(uuid); return map.containsKey(uuid);
} }
public Collection<PlayerData> getLoaded() { public Collection<PlayerData> getLoaded() {
return map.values(); return map.values();
} }
@ -62,4 +66,6 @@ public abstract class PlayerDataManager {
public abstract void loadData(PlayerData data); public abstract void loadData(PlayerData data);
public abstract void saveData(PlayerData data); public abstract void saveData(PlayerData data);
public abstract void remove(PlayerData data);
} }

View File

@ -231,4 +231,10 @@ public class MySQLPlayerDataManager extends PlayerDataManager {
return lastLogin; return lastLogin;
} }
} }
@Override
public void remove(PlayerData data) {
saveData(data);
remove(data.getUniqueId());
}
} }

View File

@ -127,4 +127,7 @@ public class YAMLPlayerDataManager extends PlayerDataManager {
public OfflinePlayerData getOffline(UUID uuid) { public OfflinePlayerData getOffline(UUID uuid) {
return isLoaded(uuid) ? get(uuid) : new YAMLOfflinePlayerData(uuid); return isLoaded(uuid) ? get(uuid) : new YAMLOfflinePlayerData(uuid);
} }
@Override
public void remove(PlayerData data) {}
} }