add generic get/set data method to user class
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
using GTANetworkAPI;
|
using GTANetworkAPI;
|
||||||
|
using Newtonsoft.Json;
|
||||||
using ReallifeGamemode.Server.Models;
|
using ReallifeGamemode.Server.Models;
|
||||||
using ReallifeGamemode.Server.Services;
|
using ReallifeGamemode.Server.Services;
|
||||||
using ReallifeGamemode.Server.Util;
|
using ReallifeGamemode.Server.Util;
|
||||||
@@ -161,5 +162,20 @@ namespace ReallifeGamemode.Server.Entities
|
|||||||
{
|
{
|
||||||
get => NAPI.Player.GetPlayerFromName(this.Name);
|
get => NAPI.Player.GetPlayerFromName(this.Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal T GetData<T>(string key, T nullValue)
|
||||||
|
{
|
||||||
|
key += "data_";
|
||||||
|
if (!Client.HasData(key)) return nullValue;
|
||||||
|
return JsonConvert.DeserializeObject<T>(Client.GetData(key));
|
||||||
|
}
|
||||||
|
|
||||||
|
internal T GetData<T>(string key) => GetData<T>(key, default);
|
||||||
|
|
||||||
|
internal void SetData(string key, object value)
|
||||||
|
{
|
||||||
|
key += "data_";
|
||||||
|
Client.SetData(key, JsonConvert.SerializeObject(value));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user