fix get set data nullreference
This commit is contained in:
@@ -93,6 +93,11 @@ namespace ReallifeGamemode.Server.Extensions
|
||||
|
||||
internal static T GetData<T>(this User user, string key, T nullValue)
|
||||
{
|
||||
if(user == null)
|
||||
{
|
||||
return default;
|
||||
}
|
||||
|
||||
key += "data_";
|
||||
if (!user.Player.HasData(key)) return nullValue;
|
||||
return JsonConvert.DeserializeObject<T>(user.Player.GetData<dynamic>(key));
|
||||
@@ -102,6 +107,11 @@ namespace ReallifeGamemode.Server.Extensions
|
||||
|
||||
internal static void SetData(this User user, string key, object value)
|
||||
{
|
||||
if(user == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
key += "data_";
|
||||
user.Player.SetData(key, JsonConvert.SerializeObject(value));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user