Skip to content

Commit

Permalink
Critical fix
Browse files Browse the repository at this point in the history
  • Loading branch information
NaoUnderscore committed Jul 1, 2024
1 parent a567baf commit 4845e73
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions Exiled.CustomModules/API/Features/Pawn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ namespace Exiled.CustomModules.API.Features
using Exiled.API.Extensions;
using Exiled.API.Features;
using Exiled.API.Features.Attributes;
using Exiled.API.Features.Core;
using Exiled.API.Features.Core.Behaviours;
using Exiled.API.Features.Items;
using Exiled.API.Features.Roles;
Expand Down Expand Up @@ -195,26 +194,29 @@ public object GlobalCurrentItem
return;
}

bool isCustomItem = typeof(CustomItem).IsAssignableFrom(value.GetType());
bool isCustomItem = value is CustomItem;
if (isCustomItem)
{
if (!CustomItems.Any(customItem => customItem.GetType() == value.GetType()))
if (CustomItems.All(customItem => customItem.GetType() != value.GetType()))
{
if (IsInventoryFull)
return;

AddItem(value);
}

Item customItem = Items.LastOrDefault(i => i.TryGetComponent(out ItemBehaviour behaviour) && behaviour.GetType() == (value as CustomItem).BehaviourComponent);
Inventory.ServerSelectItem(customItem.Serial);
Item customItem = Items.LastOrDefault(i => i.TryGetComponent(out ItemBehaviour behaviour) && behaviour.GetType() == (value as CustomItem)?.BehaviourComponent);

if (customItem)
Inventory.ServerSelectItem(customItem.Serial);

return;
}

if (value is not Item item)
return;

CurrentItem = value as Item;
CurrentItem = item;
}
}

Expand Down Expand Up @@ -261,7 +263,7 @@ public bool HasCustomItem<T>()
/// <typeparam name="T">The type of the <see cref="PlayerAbility"/>.</typeparam>
/// <returns><see langword="true"/> if a <see cref="PlayerAbility"/> of the specified type was found; otherwise, <see langword="false"/>.</returns>
public bool HasCustomAbility<T>()
where T : PlayerAbility => CustomItems.Any(item => item.GetType() == typeof(T));
where T : PlayerAbility => CustomAbilities.Any(ability => ability.GetType() == typeof(T));

/// <summary>
/// Tries to get the first <see cref="CustomItem"/> of the specified type from the collection of custom items.
Expand All @@ -270,7 +272,7 @@ public bool HasCustomAbility<T>()
/// <param name="customItem">The output parameter that will contain the retrieved <see cref="CustomItem"/>, if found.</param>
/// <returns><see langword="true"/> if a <see cref="CustomItem"/> of the specified type was found; otherwise, <see langword="false"/>.</returns>
public bool TryGetCustomItem<T>(out T customItem)
where T : CustomItem => customItem = CustomItems.FirstOrDefault(item => item.GetType() == typeof(T)).Cast<T>();
where T : CustomItem => customItem = CustomItems.FirstOrDefault(item => item.GetType() == typeof(T))?.Cast<T>();

/// <summary>
/// Tries to get the <see cref="CustomRoles.CustomRole"/> of the specified type from the <see cref="Pawn"/>.
Expand Down

0 comments on commit 4845e73

Please sign in to comment.