Raise an attempt-event when receiving client BUI messages. (#6113)
This commit is contained in:
@@ -50,6 +50,7 @@ namespace Content.Shared.Interaction
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
SubscribeLocalEvent<BoundUserInterfaceMessageAttempt>(OnBoundInterfaceInteractAttempt);
|
||||
SubscribeAllEvent<InteractInventorySlotEvent>(HandleInteractInventorySlotEvent);
|
||||
|
||||
CommandBinds.Builder
|
||||
@@ -64,6 +65,30 @@ namespace Content.Shared.Interaction
|
||||
base.Shutdown();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check that the user that is interacting with the BUI is capable of interacting and can access the entity.
|
||||
/// </summary>
|
||||
private void OnBoundInterfaceInteractAttempt(BoundUserInterfaceMessageAttempt ev)
|
||||
{
|
||||
if (ev.Sender.AttachedEntity is not EntityUid user || !_actionBlockerSystem.CanInteract(user))
|
||||
{
|
||||
ev.Cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!user.IsInSameOrParentContainer(ev.Target) && !CanAccessViaStorage(user, ev.Target))
|
||||
{
|
||||
ev.Cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!user.InRangeUnobstructed(ev.Target))
|
||||
{
|
||||
ev.Cancel();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the event were a client uses an item in their inventory or in their hands, either by
|
||||
/// alt-clicking it or pressing 'E' while hovering over it.
|
||||
|
||||
Reference in New Issue
Block a user