Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions LabApi/Features/Stores/CustomDataStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,23 @@ public static TStore GetOrAdd<TStore>(Player player)
return (TStore)store;
}

/// <summary>
/// Checks if the <see cref="CustomDataStore"/> for the specified <see cref="Player"/> exists.
/// </summary>
/// <param name="player"> The <see cref="Player"/> to check the <see cref="CustomDataStore"/> for.</param>
/// <typeparam name="TStore">The type of the <see cref="CustomDataStore"/></typeparam>
/// <returns>True if the <see cref="CustomDataStore"/> exists for the specified <see cref="Player"/>, false if not.</returns>
public static bool Exists<TStore>(Player player)
where TStore : CustomDataStore
{
Type type = typeof(TStore);

if (!StoreInstances.TryGetValue(type, out Dictionary<Player, CustomDataStore>? playerStores))
return false;

return playerStores.ContainsKey(player);
}

/// <summary>
/// Called when a new instance of the <see cref="CustomDataStore"/> is created.
/// </summary>
Expand Down Expand Up @@ -133,4 +150,12 @@ protected CustomDataStore(Player owner)
/// <param name="player">The <see cref="Player"/> to get the <see cref="CustomDataStore"/> for.</param>
/// <returns>The <see cref="CustomDataStore"/> for the specified <see cref="Player"/>.</returns>
public static TStore Get(Player player) => GetOrAdd<TStore>(player);

/// <summary>
/// Checks if the <see cref="CustomDataStore"/> for the specified <see cref="Player"/> exists.
/// </summary>
/// <param name="player"> The <see cref="Player"/> to check the <see cref="CustomDataStore"/> for.</param>
/// <typeparam name="TStore">The type of the <see cref="CustomDataStore"/></typeparam>
/// <returns>True if the <see cref="CustomDataStore"/> exists for the specified <see cref="Player"/>, false if not.</returns>
public static bool Exists(Player player) => Exists<TStore>(player);
}
11 changes: 11 additions & 0 deletions LabApi/Features/Wrappers/Players/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1504,6 +1504,17 @@ public TStore GetDataStore<TStore>()
return CustomDataStore.GetOrAdd<TStore>(this);
}

/// <summary>
/// Checks if the <see cref="CustomDataStore"/> exists on the player.
/// </summary>
/// <typeparam name="TStore">The type of the <see cref="CustomDataStore"/></typeparam>
/// <returns>True if the <see cref="CustomDataStore"/> exists on the player, false if not.</returns>
public bool HasDataStore<TStore>()
where TStore : CustomDataStore
{
return CustomDataStore.Exists<TStore>(this);
}

/// <summary>
/// Handles the creation of a player in the server.
/// </summary>
Expand Down