PlayerData.get returns empty PlayerData instance if UUID not loaded

This commit is contained in:
Indyuce 2020-04-28 00:13:58 +02:00
parent 89788cd03b
commit c48b1df43e
2 changed files with 14 additions and 1 deletions

View File

@ -103,6 +103,19 @@ public class PlayerData extends OfflinePlayerData {
questData = new PlayerQuests(this);
}
/*
* easily solves some issues where other plugins use PlayerData.get
*/
public static final PlayerData NOT_LOADED = new PlayerData();
@Deprecated
private PlayerData() {
super(UUID.randomUUID());
playerStats = new PlayerStats(this);
questData = new PlayerQuests(this);
}
/*
* update all references after /mmocore reload so there can be garbage
* collection with old plugin objects like class or skill instances.

View File

@ -22,7 +22,7 @@ public abstract class PlayerDataManager {
}
public PlayerData get(UUID uuid) {
return map.get(uuid);
return map.getOrDefault(uuid, PlayerData.NOT_LOADED);
}
public abstract OfflinePlayerData getOffline(UUID uuid);