Merge pull request #654 from PhoenixICE/general-devel

ItemBan Use Group Parenting
This commit is contained in:
k0rd 2013-10-11 09:56:22 -07:00
commit c112f433c5

View file

@ -196,13 +196,28 @@ namespace TShockAPI.DB
return Name == other.Name; return Name == other.Name;
} }
public bool HasPermissionToUseItem(TSPlayer ply) public bool HasPermissionToUseItem(TSPlayer ply)
{ {
if (ply == null) if (ply == null)
return false; return false;
return AllowedGroups.Contains(ply.Group.Name); var cur = ply.Group;
// could add in the other permissions in this class instead of a giant if switch. var traversed = new List<Group>();
} while (cur != null)
{
if (AllowedGroups.Contains(cur.Name))
{
return true;
}
if (traversed.Contains(cur))
{
throw new InvalidOperationException("Infinite group parenting ({0})".SFormat(cur.Name));
}
traversed.Add(cur);
cur = cur.Parent;
}
return false;
// could add in the other permissions in this class instead of a giant if switch.
}
public void SetAllowedGroups(String groups) public void SetAllowedGroups(String groups)
{ {