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 e3ffbc3b..780680b5 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/data/PlayerDataManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/data/PlayerDataManager.java @@ -32,7 +32,9 @@ public abstract class PlayerDataManager { * @return Player data, if it's loaded */ public PlayerData get(UUID uuid) { - return Objects.requireNonNull(data.get(uuid), "Player data is not loaded"); + if(isLoaded(uuid)) + return Objects.requireNonNull(data.get(uuid), "Player data is not loaded"); + else return setup(uuid); } /** @@ -51,13 +53,13 @@ public abstract class PlayerDataManager { // Unregister once the data was saved playerData.close(); - this.data.remove(playerData.getUniqueId()); + data.remove(playerData.getUniqueId()); }); // Just unregister data without saving else { playerData.close(); - this.data.remove(playerData.getUniqueId()); + data.remove(playerData.getUniqueId()); } } @@ -85,7 +87,6 @@ public abstract class PlayerDataManager { * @return The loaded player data. */ public PlayerData setup(UUID uniqueId) { - // Load player data if it does not exist if (!data.containsKey(uniqueId)) { PlayerData newData = TemporaryPlayerData.has(uniqueId) ? new PlayerData(MMOPlayerData.get(uniqueId), TemporaryPlayerData.get(uniqueId)) : new PlayerData(MMOPlayerData.get(uniqueId)); 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 e7702a02..d001d09d 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 @@ -12,6 +12,7 @@ import net.Indyuce.mmocore.manager.data.PlayerDataManager; import net.Indyuce.mmocore.manager.data.mysql.MySQLTableEditor.Table; import io.lumine.mythic.lib.MythicLib; import org.apache.commons.lang.Validate; +import org.jetbrains.annotations.NotNull; import java.sql.ResultSet; import java.sql.SQLException; @@ -174,6 +175,7 @@ public class MySQLPlayerDataManager extends PlayerDataManager { return json; } + @NotNull @Override public OfflinePlayerData getOffline(UUID uuid) { return isLoaded(uuid) ? get(uuid) : new MySQLOfflinePlayerData(uuid); 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 92b927c8..72d7e5ec 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 @@ -17,6 +17,7 @@ import net.Indyuce.mmocore.api.player.profess.PlayerClass; import net.Indyuce.mmocore.api.player.profess.SavedClassInformation; import net.Indyuce.mmocore.api.player.stats.StatType; import net.Indyuce.mmocore.manager.data.PlayerDataManager; +import org.jetbrains.annotations.NotNull; public class YAMLPlayerDataManager extends PlayerDataManager { @@ -126,6 +127,7 @@ public class YAMLPlayerDataManager extends PlayerDataManager { file.save(); } + @NotNull @Override public OfflinePlayerData getOffline(UUID uuid) { return isLoaded(uuid) ? get(uuid) : new YAMLOfflinePlayerData(uuid);