From 4845e73f77c5bf25cb3cf63b074abf3ec5f8d48e Mon Sep 17 00:00:00 2001 From: NaoUnderscore Date: Mon, 1 Jul 2024 18:03:34 +0200 Subject: [PATCH] Critical fix --- Exiled.CustomModules/API/Features/Pawn.cs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/Exiled.CustomModules/API/Features/Pawn.cs b/Exiled.CustomModules/API/Features/Pawn.cs index 67a104338e..9bba495ab4 100644 --- a/Exiled.CustomModules/API/Features/Pawn.cs +++ b/Exiled.CustomModules/API/Features/Pawn.cs @@ -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; @@ -195,10 +194,10 @@ 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; @@ -206,15 +205,18 @@ public object GlobalCurrentItem 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; } } @@ -261,7 +263,7 @@ public bool HasCustomItem() /// The type of the . /// if a of the specified type was found; otherwise, . public bool HasCustomAbility() - where T : PlayerAbility => CustomItems.Any(item => item.GetType() == typeof(T)); + where T : PlayerAbility => CustomAbilities.Any(ability => ability.GetType() == typeof(T)); /// /// Tries to get the first of the specified type from the collection of custom items. @@ -270,7 +272,7 @@ public bool HasCustomAbility() /// The output parameter that will contain the retrieved , if found. /// if a of the specified type was found; otherwise, . public bool TryGetCustomItem(out T customItem) - where T : CustomItem => customItem = CustomItems.FirstOrDefault(item => item.GetType() == typeof(T)).Cast(); + where T : CustomItem => customItem = CustomItems.FirstOrDefault(item => item.GetType() == typeof(T))?.Cast(); /// /// Tries to get the of the specified type from the .