Skip to content
Merged
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
43 changes: 9 additions & 34 deletions EXILED/Exiled.CustomItems/API/Features/CustomItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ namespace Exiled.CustomItems.API.Features
/// </summary>
public abstract class CustomItem
{
private static Dictionary<Type, CustomItem?> typeLookupTable = new();
private static Dictionary<string, CustomItem?> stringLookupTable = new();
private static Dictionary<uint, CustomItem?> idLookupTable = new();

Expand Down Expand Up @@ -159,16 +158,11 @@ public virtual ItemType Type
}

/// <summary>
/// Gets a <see cref="CustomItem"/> with a specific type.
/// Retrieves a collection of <see cref="CustomItem"/> instances that match a specified type.
/// </summary>
/// <param name="t">The <see cref="System.Type"/> type.</param>
/// <returns>The <see cref="CustomItem"/> matching the search, <see langwod="null"/> if not registered.</returns>
public static CustomItem? Get(Type t)
{
if (!typeLookupTable.ContainsKey(t))
typeLookupTable.Add(t, Registered.FirstOrDefault(i => i.GetType() == t));
return typeLookupTable[t];
}
/// <returns>An <see cref="IEnumerable{CustomItem}"/> containing all registered <see cref="CustomItem"/> of the specified type.</returns>
public static IEnumerable<CustomItem> Get(Type t) => Registered.Where(i => i.GetType() == t);

/// <summary>
/// Tries to get a <see cref="CustomItem"/> with a specific ID.
Expand Down Expand Up @@ -201,16 +195,16 @@ public static bool TryGet(string name, out CustomItem? customItem)
}

/// <summary>
/// Tries to get a <see cref="CustomItem"/> with a specific type.
/// Attempts to retrieve a collection of <see cref="CustomItem"/> instances of a specified type.
/// </summary>
/// <param name="t">The <see cref="System.Type"/> of the item to look for.</param>
/// <param name="customItem">The found <see cref="CustomItem"/>, <see langword="null"/> if not registered.</param>
/// <returns>Returns a value indicating whether the <see cref="CustomItem"/> was found.</returns>
public static bool TryGet(Type t, out CustomItem? customItem)
/// <param name="customItems">An output parameter that will contain the found <see cref="CustomItem"/> instances, or an empty collection if none are registered.</param>
/// <returns>A boolean value indicating whether any <see cref="CustomItem"/> instances of the specified type were found.</returns>
public static bool TryGet(Type t, out IEnumerable<CustomItem> customItems)
{
customItem = Get(t);
customItems = Get(t);

return customItem is not null;
return customItems.Any();
}

/// <summary>
Expand Down Expand Up @@ -345,23 +339,6 @@ public static bool TryGive(Player player, uint id, bool displayMessage = true)
return true;
}

/// <summary>
/// Gives to a specific <see cref="Player"/> a specic <see cref="CustomItem"/>.
/// </summary>
/// <param name="player">The <see cref="Player"/> to give the item to.</param>
/// <param name="t">The <see cref="System.Type"/> of the item to give.</param>
/// <param name="displayMessage">Indicates a value whether <see cref="ShowPickedUpMessage"/> will be called when the player receives the <see cref="CustomItem"/> or not.</param>
/// <returns>Returns a value indicating if the player was given the <see cref="CustomItem"/> or not.</returns>
public static bool TryGive(Player player, Type t, bool displayMessage = true)
{
if (!TryGet(t, out CustomItem? item))
return false;

item?.Give(player, displayMessage);

return true;
}

/// <summary>
/// Registers all the <see cref="CustomItem"/>'s present in the current assembly.
/// </summary>
Expand Down Expand Up @@ -770,7 +747,6 @@ public virtual void Give(Player player, Item item, bool displayMessage = true)
/// </summary>
public virtual void Init()
{
typeLookupTable.Add(GetType(), this);
stringLookupTable.Add(Name, this);
idLookupTable.Add(Id, this);

Expand All @@ -784,7 +760,6 @@ public virtual void Destroy()
{
UnsubscribeEvents();

typeLookupTable.Remove(GetType());
stringLookupTable.Remove(Name);
idLookupTable.Remove(Id);
}
Expand Down