diff --git a/Content.Shared/Storage/EntitySystems/SharedStorageSystem.cs b/Content.Shared/Storage/EntitySystems/SharedStorageSystem.cs index 771513a0a8..ba840cd67a 100644 --- a/Content.Shared/Storage/EntitySystems/SharedStorageSystem.cs +++ b/Content.Shared/Storage/EntitySystems/SharedStorageSystem.cs @@ -109,6 +109,7 @@ public abstract class SharedStorageSystem : EntitySystem SubscribeLocalEvent(AfterInteract); SubscribeLocalEvent(OnDestroy); SubscribeLocalEvent(OnBoundUIOpen); + SubscribeLocalEvent(OnLockToggled); SubscribeLocalEvent(OnStackCountChanged); SubscribeLocalEvent(OnEntInserted); @@ -1401,6 +1402,25 @@ public abstract class SharedStorageSystem : EntitySystem return _nextSmallest[item.Size]; } + /// + /// Checks if a storage's UI is open by anyone when locked, and closes it unless they're an admin. + /// + private void OnLockToggled(EntityUid uid, StorageComponent component, ref LockToggledEvent args) + { + if (!args.Locked) + return; + + // Gets everyone looking at the UI + foreach (var actor in _ui.GetActors(uid, StorageComponent.StorageUiKey.Key)) + { + if (_admin.HasAdminFlag(actor, AdminFlags.Admin)) + continue; + + // And closes it unless they're an admin + _ui.CloseUi(uid, StorageComponent.StorageUiKey.Key, actor); + } + } + private void OnStackCountChanged(EntityUid uid, MetaDataComponent component, StackCountChangedEvent args) { if (_containerSystem.TryGetContainingContainer(uid, out var container, component) &&