diff --git a/TShockAPI/TSPlayer.cs b/TShockAPI/TSPlayer.cs index ce4d3e10..031a3b95 100755 --- a/TShockAPI/TSPlayer.cs +++ b/TShockAPI/TSPlayer.cs @@ -17,6 +17,7 @@ along with this program. If not, see . */ using System; +using System.Collections.Concurrent; using System.Collections.Generic; using System.Diagnostics; using System.IO; @@ -352,6 +353,11 @@ namespace TShockAPI /// The current region this player is in, or null if none. /// public Region CurrentRegion = null; + + /// + /// Contains data stored by plugins + /// + protected ConcurrentDictionary data => new ConcurrentDictionary(); /// /// Whether the player is a real, human, player on the server. @@ -535,6 +541,37 @@ namespace TShockAPI } } + /// + /// Stores an object on this player, accessible with the given key + /// + /// Type of the object being stored + /// Key with which to access the object + /// Object to store + public void SetData(string key, T value) + { + data.TryAdd(key, value); + } + + /// + /// Returns the stored object associated with the given key + /// + /// Type of the object being retrieved + /// Key with which to access the object + /// Stored object, or default(T) if not found + /// True if the value was retrieved, else False + public bool GetData(string key, out T value) + { + object obj; + if (!data.TryGetValue(key, out obj)) + { + value = default(T); + return false; + } + + value = (T)obj; + return true; + } + public TSPlayer(int index) { TilesDestroyed = new Dictionary();