Merge pull request #654 from PhoenixICE/general-devel
ItemBan Use Group Parenting
This commit is contained in:
commit
c112f433c5
1 changed files with 22 additions and 7 deletions
|
|
@ -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)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue