diff --git a/TShockAPI/TSPlayer.cs b/TShockAPI/TSPlayer.cs index 031a3b95..75141da1 100755 --- a/TShockAPI/TSPlayer.cs +++ b/TShockAPI/TSPlayer.cs @@ -542,34 +542,59 @@ namespace TShockAPI } /// - /// Stores an object on this player, accessible with the given key + /// Determines whether the player's storage contains 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) + /// Key to test. + /// + public bool ContainsData(string key) { - data.TryAdd(key, value); + return data.ContainsKey(key); } /// - /// Returns the stored object associated with the given key + /// 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) + /// Type of the object being retrieved. + /// Key with which to access the object. + /// The stored object, or default(T) if not found. + public T GetData(string key) { object obj; if (!data.TryGetValue(key, out obj)) { - value = default(T); - return false; + return default(T); } - value = (T)obj; - return true; + return (T)obj; + } + + /// + /// 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) + { + if (!data.TryAdd(key, value)) + { + data.TryUpdate(key, value, data[key]); + } + } + + /// + /// Removes the stored object associated with the given key. + /// + /// Key with which to access the object. + /// The removed object. + public object RemoveData(string key) + { + object rem; + if (data.TryRemove(key, out rem)) + { + return rem; + } + return null; } public TSPlayer(int index)