EntityWhitelist uses EntityUid

This commit is contained in:
Vera Aguilera Puerto
2021-11-09 13:08:09 +01:00
parent 5d66a08ac9
commit 1f9e1c033f
8 changed files with 20 additions and 18 deletions

View File

@@ -30,7 +30,7 @@ namespace Content.Shared.Containers.ItemSlots
private void OnComponentInit(EntityUid uid, SharedItemSlotsComponent itemSlots, ComponentInit args)
{
// create container for each slot
// create container for each slot
foreach (var pair in itemSlots.Slots)
{
var slotName = pair.Key;
@@ -131,7 +131,7 @@ namespace Content.Shared.Containers.ItemSlots
foreach (var (slotName, slot) in itemSlots.Slots)
{
// check if item allowed in whitelist
if (slot.Whitelist != null && !slot.Whitelist.IsValid(item))
if (slot.Whitelist != null && !slot.Whitelist.IsValid(item.Uid))
continue;
// check if slot does not contain the item currently being inserted???
@@ -179,7 +179,7 @@ namespace Content.Shared.Containers.ItemSlots
return false;
// check if item allowed in whitelist
if (slot.Whitelist != null && !slot.Whitelist.IsValid(item))
if (slot.Whitelist != null && !slot.Whitelist.IsValid(item.Uid))
return false;
return true;

View File

@@ -67,11 +67,13 @@ namespace Content.Shared.Whitelist
/// <summary>
/// Returns whether a given entity fits the whitelist.
/// </summary>
public bool IsValid(IEntity entity)
public bool IsValid(EntityUid uid, IEntityManager? entityManager = null)
{
if (Tags != null)
entityManager ??= IoCManager.Resolve<IEntityManager>();
if (Tags != null && entityManager.TryGetComponent(uid, out TagComponent? tags))
{
if (entity.HasAnyTag(Tags))
if (tags.HasAnyTag(Tags))
return true;
}
@@ -79,7 +81,7 @@ namespace Content.Shared.Whitelist
{
foreach (var reg in _registrations)
{
if (entity.HasComponent(reg.Type))
if (entityManager.HasComponent(uid, reg.Type))
return true;
}
}