From 7500303bed11785e2b7f4eec0d32020837c7d21f Mon Sep 17 00:00:00 2001 From: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com> Date: Sun, 31 Jul 2022 14:53:17 +1200 Subject: [PATCH] Strap bug fixes (#10142) --- Content.Server/Buckle/Systems/StrapSystem.cs | 18 +++++++++++++++--- .../Construction/Completions/DeleteEntity.cs | 18 ++++++++++++++++-- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/Content.Server/Buckle/Systems/StrapSystem.cs b/Content.Server/Buckle/Systems/StrapSystem.cs index b3087e0db9..e9312ee558 100644 --- a/Content.Server/Buckle/Systems/StrapSystem.cs +++ b/Content.Server/Buckle/Systems/StrapSystem.cs @@ -1,4 +1,5 @@ using Content.Server.Buckle.Components; +using Content.Server.Construction.Completions; using Content.Server.Interaction; using Content.Shared.Destructible; using Content.Shared.Interaction; @@ -8,7 +9,6 @@ using JetBrains.Annotations; using Robust.Server.GameObjects; using Robust.Shared.Containers; - namespace Content.Server.Buckle.Systems { [UsedImplicitly] @@ -23,7 +23,19 @@ namespace Content.Server.Buckle.Systems SubscribeLocalEvent>(AddStrapVerbs); SubscribeLocalEvent(OnInsertAttempt); SubscribeLocalEvent(OnInteractHand); - SubscribeLocalEvent(OnDestroy); + SubscribeLocalEvent((_,c,_) => RemoveAll(c)); + SubscribeLocalEvent((_, c, _) => RemoveAll(c)); + SubscribeLocalEvent((_, c, _) => RemoveAll(c)); + SubscribeLocalEvent(OnShutdown); + } + + private void OnShutdown(EntityUid uid, StrapComponent component, ComponentShutdown args) + { + if (LifeStage(uid) > EntityLifeStage.MapInitialized) + return; + + // Component is being removed, but entity is not shutting down. + component.RemoveAll(); } private void OnInsertAttempt(EntityUid uid, StrapComponent component, ContainerGettingInsertedAttemptEvent args) @@ -123,7 +135,7 @@ namespace Content.Server.Buckle.Systems } } - private void OnDestroy(EntityUid uid, StrapComponent component, DestructionEventArgs args) + public void RemoveAll(StrapComponent component) { component.RemoveAll(); } diff --git a/Content.Server/Construction/Completions/DeleteEntity.cs b/Content.Server/Construction/Completions/DeleteEntity.cs index 796cd888ef..8aa1f98893 100644 --- a/Content.Server/Construction/Completions/DeleteEntity.cs +++ b/Content.Server/Construction/Completions/DeleteEntity.cs @@ -1,15 +1,29 @@ -using Content.Shared.Construction; +using Content.Shared.Construction; using JetBrains.Annotations; namespace Content.Server.Construction.Completions { + public sealed class ConstructionBeforeDeleteEvent : CancellableEntityEventArgs + { + public EntityUid? User; + + public ConstructionBeforeDeleteEvent(EntityUid? user) + { + User = user; + } + } + [UsedImplicitly] [DataDefinition] public sealed class DeleteEntity : IGraphAction { public void PerformAction(EntityUid uid, EntityUid? userUid, IEntityManager entityManager) { - entityManager.DeleteEntity(uid); + var ev = new ConstructionBeforeDeleteEvent(userUid); + entityManager.EventBus.RaiseLocalEvent(uid, ev); + + if (!ev.Cancelled) + entityManager.DeleteEntity(uid); } } }