Added a ConcurrentDictionary for plugin data to TSPlayer
This commit is contained in:
parent
d64abdb9a6
commit
275ca6f9d1
1 changed files with 37 additions and 0 deletions
|
|
@ -17,6 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Concurrent;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
|
@ -353,6 +354,11 @@ namespace TShockAPI
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Region CurrentRegion = null;
|
public Region CurrentRegion = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Contains data stored by plugins
|
||||||
|
/// </summary>
|
||||||
|
protected ConcurrentDictionary<string, object> data => new ConcurrentDictionary<string, object>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Whether the player is a real, human, player on the server.
|
/// Whether the player is a real, human, player on the server.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -535,6 +541,37 @@ namespace TShockAPI
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Stores an object on this player, accessible with the given key
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">Type of the object being stored</typeparam>
|
||||||
|
/// <param name="key">Key with which to access the object</param>
|
||||||
|
/// <param name="value">Object to store</param>
|
||||||
|
public void SetData<T>(string key, T value)
|
||||||
|
{
|
||||||
|
data.TryAdd(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the stored object associated with the given key
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">Type of the object being retrieved</typeparam>
|
||||||
|
/// <param name="key">Key with which to access the object</param>
|
||||||
|
/// <param name="value">Stored object, or default(T) if not found</param>
|
||||||
|
/// <returns>True if the value was retrieved, else False</returns>
|
||||||
|
public bool GetData<T>(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)
|
public TSPlayer(int index)
|
||||||
{
|
{
|
||||||
TilesDestroyed = new Dictionary<Vector2, Tile>();
|
TilesDestroyed = new Dictionary<Vector2, Tile>();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue