From 9921801f15273a0e1d68071788501096184d6db6 Mon Sep 17 00:00:00 2001 From: Vera Aguilera Puerto Date: Tue, 9 Nov 2021 13:43:39 +0100 Subject: [PATCH] ActionBlocker CanPickup uses EntityUid exclusively --- Content.Server/Access/IdCardConsoleSystem.cs | 2 +- .../Chemistry/EntitySystems/ChemMasterSystem.cs | 2 +- .../EntitySystems/ReagentDispenserSystem.cs | 2 +- .../Power/EntitySystems/BaseChargerSystem.cs | 2 +- Content.Server/PowerCell/PowerCellSystem.cs | 2 +- .../Weapon/Ranged/Barrels/BarrelSystem.cs | 4 ++-- .../ActionBlocker/ActionBlockerSystem.cs | 14 ++++---------- .../Containers/ItemSlot/SharedItemSlotsSystem.cs | 2 +- .../Hands/Components/SharedHandsComponent.cs | 2 +- Content.Shared/Item/PickupAttemptEvent.cs | 6 +++--- Content.Shared/Item/SharedItemComponent.cs | 2 +- 11 files changed, 17 insertions(+), 23 deletions(-) diff --git a/Content.Server/Access/IdCardConsoleSystem.cs b/Content.Server/Access/IdCardConsoleSystem.cs index 597a6381f9..aa81d33f42 100644 --- a/Content.Server/Access/IdCardConsoleSystem.cs +++ b/Content.Server/Access/IdCardConsoleSystem.cs @@ -53,7 +53,7 @@ namespace Content.Server.Access if (args.Hands == null || !args.CanAccess || !args.CanInteract || - !_actionBlockerSystem.CanPickup(args.User)) + !_actionBlockerSystem.CanPickup(args.User.Uid)) return; // Can we eject a privileged ID? diff --git a/Content.Server/Chemistry/EntitySystems/ChemMasterSystem.cs b/Content.Server/Chemistry/EntitySystems/ChemMasterSystem.cs index 55b0a7337b..993ff518bf 100644 --- a/Content.Server/Chemistry/EntitySystems/ChemMasterSystem.cs +++ b/Content.Server/Chemistry/EntitySystems/ChemMasterSystem.cs @@ -32,7 +32,7 @@ namespace Content.Server.Chemistry.EntitySystems !args.CanAccess || !args.CanInteract || !component.HasBeaker || - !_actionBlockerSystem.CanPickup(args.User)) + !_actionBlockerSystem.CanPickup(args.User.Uid)) return; Verb verb = new(); diff --git a/Content.Server/Chemistry/EntitySystems/ReagentDispenserSystem.cs b/Content.Server/Chemistry/EntitySystems/ReagentDispenserSystem.cs index 525efe5a37..c305721ed8 100644 --- a/Content.Server/Chemistry/EntitySystems/ReagentDispenserSystem.cs +++ b/Content.Server/Chemistry/EntitySystems/ReagentDispenserSystem.cs @@ -34,7 +34,7 @@ namespace Content.Server.Chemistry.EntitySystems !args.CanAccess || !args.CanInteract || !component.HasBeaker || - !_actionBlockerSystem.CanPickup(args.User)) + !_actionBlockerSystem.CanPickup(args.User.Uid)) return; Verb verb = new(); diff --git a/Content.Server/Power/EntitySystems/BaseChargerSystem.cs b/Content.Server/Power/EntitySystems/BaseChargerSystem.cs index 82f5866580..649c5ca71c 100644 --- a/Content.Server/Power/EntitySystems/BaseChargerSystem.cs +++ b/Content.Server/Power/EntitySystems/BaseChargerSystem.cs @@ -39,7 +39,7 @@ namespace Content.Server.Power.EntitySystems !args.CanAccess || !args.CanInteract || !component.HasCell || - !_actionBlockerSystem.CanPickup(args.User)) + !_actionBlockerSystem.CanPickup(args.User.Uid)) return; Verb verb = new(); diff --git a/Content.Server/PowerCell/PowerCellSystem.cs b/Content.Server/PowerCell/PowerCellSystem.cs index ea41f72894..02595812ce 100644 --- a/Content.Server/PowerCell/PowerCellSystem.cs +++ b/Content.Server/PowerCell/PowerCellSystem.cs @@ -31,7 +31,7 @@ namespace Content.Server.PowerCell !args.CanInteract || !component.ShowVerb || !component.HasCell || - !_actionBlockerSystem.CanPickup(args.User)) + !_actionBlockerSystem.CanPickup(args.User.Uid)) return; Verb verb = new(); diff --git a/Content.Server/Weapon/Ranged/Barrels/BarrelSystem.cs b/Content.Server/Weapon/Ranged/Barrels/BarrelSystem.cs index 726c2840a6..7c07749499 100644 --- a/Content.Server/Weapon/Ranged/Barrels/BarrelSystem.cs +++ b/Content.Server/Weapon/Ranged/Barrels/BarrelSystem.cs @@ -71,7 +71,7 @@ namespace Content.Server.Weapon.Ranged.Barrels !args.CanInteract || !component.PowerCellRemovable || component.PowerCell == null || - !_actionBlockerSystem.CanPickup(args.User)) + !_actionBlockerSystem.CanPickup(args.User.Uid)) return; Verb verb = new(); @@ -104,7 +104,7 @@ namespace Content.Server.Weapon.Ranged.Barrels !args.CanAccess || !args.CanInteract || !component.HasMagazine || - !_actionBlockerSystem.CanPickup(args.User)) + !_actionBlockerSystem.CanPickup(args.User.Uid)) return; if (component.MagNeedsOpenBolt && !component.BoltOpen) diff --git a/Content.Shared/ActionBlocker/ActionBlockerSystem.cs b/Content.Shared/ActionBlocker/ActionBlockerSystem.cs index d2fd79f03e..c32172dadf 100644 --- a/Content.Shared/ActionBlocker/ActionBlockerSystem.cs +++ b/Content.Shared/ActionBlocker/ActionBlockerSystem.cs @@ -75,18 +75,12 @@ namespace Content.Shared.ActionBlocker return !ev.Cancelled; } - public bool CanPickup(IEntity entity) - { - var ev = new PickupAttemptEvent(entity); - - RaiseLocalEvent(entity.Uid, ev); - - return !ev.Cancelled; - } - public bool CanPickup(EntityUid uid) { - return CanPickup(EntityManager.GetEntity(uid)); + var ev = new PickupAttemptEvent(uid); + RaiseLocalEvent(uid, ev); + + return !ev.Cancelled; } public bool CanEmote(EntityUid uid) diff --git a/Content.Shared/Containers/ItemSlot/SharedItemSlotsSystem.cs b/Content.Shared/Containers/ItemSlot/SharedItemSlotsSystem.cs index 0c2c195a27..bd38d1a60b 100644 --- a/Content.Shared/Containers/ItemSlot/SharedItemSlotsSystem.cs +++ b/Content.Shared/Containers/ItemSlot/SharedItemSlotsSystem.cs @@ -67,7 +67,7 @@ namespace Content.Shared.Containers.ItemSlots if (args.Hands == null || !args.CanAccess || !args.CanInteract || - !_actionBlockerSystem.CanPickup(args.User)) + !_actionBlockerSystem.CanPickup(args.User.Uid)) return; foreach (var (slotName, slot) in component.Slots) diff --git a/Content.Shared/Hands/Components/SharedHandsComponent.cs b/Content.Shared/Hands/Components/SharedHandsComponent.cs index 96bece3897..a47c7f4581 100644 --- a/Content.Shared/Hands/Components/SharedHandsComponent.cs +++ b/Content.Shared/Hands/Components/SharedHandsComponent.cs @@ -625,7 +625,7 @@ namespace Content.Shared.Hands.Components /// protected bool PlayerCanPickup() { - if (!IoCManager.Resolve().GetEntitySystem().CanPickup(Owner)) + if (!EntitySystem.Get().CanPickup(Owner.Uid)) return false; return true; diff --git a/Content.Shared/Item/PickupAttemptEvent.cs b/Content.Shared/Item/PickupAttemptEvent.cs index d8e3164a3c..1d922a6d04 100644 --- a/Content.Shared/Item/PickupAttemptEvent.cs +++ b/Content.Shared/Item/PickupAttemptEvent.cs @@ -4,11 +4,11 @@ namespace Content.Shared.Item { public class PickupAttemptEvent : CancellableEntityEventArgs { - public PickupAttemptEvent(IEntity entity) + public PickupAttemptEvent(EntityUid uid) { - Entity = entity; + Uid = uid; } - public IEntity Entity { get; } + public EntityUid Uid { get; } } } diff --git a/Content.Shared/Item/SharedItemComponent.cs b/Content.Shared/Item/SharedItemComponent.cs index 675fc84e07..12ff413d18 100644 --- a/Content.Shared/Item/SharedItemComponent.cs +++ b/Content.Shared/Item/SharedItemComponent.cs @@ -111,7 +111,7 @@ namespace Content.Shared.Item /// public bool CanPickup(IEntity user, bool popup = true) { - if (!EntitySystem.Get().CanPickup(user)) + if (!EntitySystem.Get().CanPickup(user.Uid)) return false; if (user.Transform.MapID != Owner.Transform.MapID)