diff --git a/Content.Server/Atmos/EntitySystems/GasAnalyzerSystem.cs b/Content.Server/Atmos/EntitySystems/GasAnalyzerSystem.cs index 81f0b96d02..cc541e35e9 100644 --- a/Content.Server/Atmos/EntitySystems/GasAnalyzerSystem.cs +++ b/Content.Server/Atmos/EntitySystems/GasAnalyzerSystem.cs @@ -76,14 +76,13 @@ public sealed class GasAnalyzerSystem : EntitySystem /// private void OnUseInHand(Entity entity, ref UseInHandEvent args) { + // Not checking for Handled because ActivatableUISystem already marks it as such. + if (!entity.Comp.Enabled) - { ActivateAnalyzer(entity, args.User); - } else - { DisableAnalyzer(entity, args.User); - } + args.Handled = true; } diff --git a/Content.Server/Holiday/Christmas/RandomGiftSystem.cs b/Content.Server/Holiday/Christmas/RandomGiftSystem.cs index 0816c2c36c..559dc9856e 100644 --- a/Content.Server/Holiday/Christmas/RandomGiftSystem.cs +++ b/Content.Server/Holiday/Christmas/RandomGiftSystem.cs @@ -6,7 +6,6 @@ using Content.Shared.Interaction.Events; using Content.Shared.Item; using Content.Shared.Whitelist; using Robust.Server.Audio; -using Robust.Server.GameObjects; using Robust.Shared.Map.Components; using Robust.Shared.Physics.Components; using Robust.Shared.Prototypes; @@ -26,6 +25,7 @@ public sealed class RandomGiftSystem : EntitySystem [Dependency] private readonly IRobustRandom _random = default!; [Dependency] private readonly IAdminLogManager _adminLogger = default!; [Dependency] private readonly EntityWhitelistSystem _whitelistSystem = default!; + [Dependency] private readonly SharedTransformSystem _transform = default!; private readonly List _possibleGiftsSafe = new(); private readonly List _possibleGiftsUnsafe = new(); @@ -63,11 +63,16 @@ public sealed class RandomGiftSystem : EntitySystem if (component.Wrapper is not null) Spawn(component.Wrapper, coords); - args.Handled = true; _audio.PlayPvs(component.Sound, args.User); - Del(uid); + + // Don't delete the entity in the event bus, so we queue it for deletion. + // We need the free hand for the new item, so we send it to nullspace. + _transform.DetachEntity(uid, Transform(uid)); + QueueDel(uid); + _hands.PickupOrDrop(args.User, handsEnt); + args.Handled = true; } private void OnGiftMapInit(EntityUid uid, RandomGiftComponent component, MapInitEvent args) diff --git a/Content.Server/Mousetrap/MousetrapSystem.cs b/Content.Server/Mousetrap/MousetrapSystem.cs index e3aaab364d..3afe858ce0 100644 --- a/Content.Server/Mousetrap/MousetrapSystem.cs +++ b/Content.Server/Mousetrap/MousetrapSystem.cs @@ -27,6 +27,9 @@ public sealed class MousetrapSystem : EntitySystem private void OnUseInHand(EntityUid uid, MousetrapComponent component, UseInHandEvent args) { + if (args.Handled) + return; + component.IsActive = !component.IsActive; _popupSystem.PopupEntity(component.IsActive ? Loc.GetString("mousetrap-on-activate") @@ -35,6 +38,8 @@ public sealed class MousetrapSystem : EntitySystem args.User); UpdateVisuals(uid); + + args.Handled = true; } private void OnStepTriggerAttempt(EntityUid uid, MousetrapComponent component, ref StepTriggerAttemptEvent args) diff --git a/Content.Server/PAI/PAISystem.cs b/Content.Server/PAI/PAISystem.cs index 0cdb0bc29a..b0f4f2476d 100644 --- a/Content.Server/PAI/PAISystem.cs +++ b/Content.Server/PAI/PAISystem.cs @@ -37,6 +37,8 @@ public sealed class PAISystem : SharedPAISystem private void OnUseInHand(EntityUid uid, PAIComponent component, UseInHandEvent args) { + // Not checking for Handled because ToggleableGhostRoleSystem already marks it as such. + if (!TryComp(uid, out var mind) || !mind.HasMind) component.LastUser = args.User; } diff --git a/Content.Server/Storage/EntitySystems/SpawnItemsOnUseSystem.cs b/Content.Server/Storage/EntitySystems/SpawnItemsOnUseSystem.cs index 4c533ede3a..1fd617c539 100644 --- a/Content.Server/Storage/EntitySystems/SpawnItemsOnUseSystem.cs +++ b/Content.Server/Storage/EntitySystems/SpawnItemsOnUseSystem.cs @@ -4,10 +4,8 @@ using Content.Server.Storage.Components; using Content.Shared.Database; using Content.Shared.Hands.EntitySystems; using Content.Shared.Interaction.Events; -using Robust.Shared.Audio; using Robust.Shared.Audio.Systems; using Robust.Shared.Map; -using Robust.Shared.Player; using Robust.Shared.Random; using static Content.Shared.Storage.EntitySpawnCollection; @@ -20,6 +18,7 @@ namespace Content.Server.Storage.EntitySystems [Dependency] private readonly SharedHandsSystem _hands = default!; [Dependency] private readonly PricingSystem _pricing = default!; [Dependency] private readonly SharedAudioSystem _audio = default!; + [Dependency] private readonly SharedTransformSystem _transform = default!; public override void Initialize() { @@ -80,26 +79,25 @@ namespace Content.Server.Storage.EntitySystems _adminLogger.Add(LogType.EntitySpawn, LogImpact.Low, $"{ToPrettyString(args.User)} used {ToPrettyString(uid)} which spawned {ToPrettyString(entityToPlaceInHands.Value)}"); } + // The entity is often deleted, so play the sound at its position rather than parenting if (component.Sound != null) - { - // The entity is often deleted, so play the sound at its position rather than parenting - var coordinates = Transform(uid).Coordinates; - _audio.PlayPvs(component.Sound, coordinates); - } + _audio.PlayPvs(component.Sound, coords); component.Uses--; // Delete entity only if component was successfully used if (component.Uses <= 0) { - args.Handled = true; - EntityManager.DeleteEntity(uid); + // Don't delete the entity in the event bus, so we queue it for deletion. + // We need the free hand for the new item, so we send it to nullspace. + _transform.DetachEntity(uid, Transform(uid)); + QueueDel(uid); } if (entityToPlaceInHands != null) - { _hands.PickupOrDrop(args.User, entityToPlaceInHands.Value); - } + + args.Handled = true; } } } diff --git a/Content.Server/Storage/EntitySystems/SpawnTableOnUseSystem.cs b/Content.Server/Storage/EntitySystems/SpawnTableOnUseSystem.cs index 96556ed7b2..1f96b39a4e 100644 --- a/Content.Server/Storage/EntitySystems/SpawnTableOnUseSystem.cs +++ b/Content.Server/Storage/EntitySystems/SpawnTableOnUseSystem.cs @@ -12,6 +12,7 @@ public sealed class SpawnTableOnUseSystem : EntitySystem [Dependency] private readonly EntityTableSystem _entityTable = default!; [Dependency] private readonly IAdminLogManager _adminLogger = default!; [Dependency] private readonly SharedHandsSystem _hands = default!; + [Dependency] private readonly SharedTransformSystem _transform = default!; public override void Initialize() { @@ -25,17 +26,21 @@ public sealed class SpawnTableOnUseSystem : EntitySystem if (args.Handled) return; - args.Handled = true; - var coords = Transform(ent).Coordinates; var spawns = _entityTable.GetSpawns(ent.Comp.Table); + + // Don't delete the entity in the event bus, so we queue it for deletion. + // We need the free hand for the new item, so we send it to nullspace. + _transform.DetachEntity(ent, Transform(ent)); + QueueDel(ent); + foreach (var id in spawns) { var spawned = Spawn(id, coords); _adminLogger.Add(LogType.EntitySpawn, LogImpact.Low, $"{ToPrettyString(args.User):user} used {ToPrettyString(ent):spawner} which spawned {ToPrettyString(spawned)}"); - _hands.TryPickupAnyHand(args.User, spawned); + _hands.PickupOrDrop(args.User, spawned); } - Del(ent); + args.Handled = true; } } diff --git a/Content.Server/Teleportation/HandTeleporterSystem.cs b/Content.Server/Teleportation/HandTeleporterSystem.cs index 1cd2e1d8c2..78e881d76a 100644 --- a/Content.Server/Teleportation/HandTeleporterSystem.cs +++ b/Content.Server/Teleportation/HandTeleporterSystem.cs @@ -41,6 +41,9 @@ public sealed class HandTeleporterSystem : EntitySystem private void OnUseInHand(EntityUid uid, HandTeleporterComponent component, UseInHandEvent args) { + if (args.Handled) + return; + if (Deleted(component.FirstPortal)) component.FirstPortal = null; @@ -67,6 +70,8 @@ public sealed class HandTeleporterSystem : EntitySystem _doafter.TryStartDoAfter(doafterArgs); } + + args.Handled = true; } diff --git a/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.Magazine.cs b/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.Magazine.cs index 61a4820e5b..2876851d2d 100644 --- a/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.Magazine.cs +++ b/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.Magazine.cs @@ -38,6 +38,8 @@ public abstract partial class SharedGunSystem private void OnMagazineUse(EntityUid uid, MagazineAmmoProviderComponent component, UseInHandEvent args) { + // not checking for args.Handled or marking as such because we only relay the event to the magazine entity + var magEnt = GetMagazineEntity(uid); if (magEnt == null) diff --git a/Content.Shared/Whistle/WhistleSystem.cs b/Content.Shared/Whistle/WhistleSystem.cs index 9db7ffa0bf..bbedffd8ec 100644 --- a/Content.Shared/Whistle/WhistleSystem.cs +++ b/Content.Shared/Whistle/WhistleSystem.cs @@ -27,11 +27,10 @@ public sealed class WhistleSystem : EntitySystem public void OnUseInHand(EntityUid uid, WhistleComponent component, UseInHandEvent args) { - if (!_timing.IsFirstTimePredicted) + if (args.Handled || !_timing.IsFirstTimePredicted) return; - TryMakeLoudWhistle(uid, args.User, component); - args.Handled = true; + args.Handled = TryMakeLoudWhistle(uid, args.User, component); } public bool TryMakeLoudWhistle(EntityUid uid, EntityUid owner, WhistleComponent? component = null)