Exemple #1
0
        public bool HasPermissionToUseItem(TSPlayer ply)
        {
            if (ply == null)
            {
                return(false);
            }

            if (ply.HasPermission(Permissions.usebanneditem))
            {
                return(true);
            }

            PermissionHookResult hookResult = PlayerHooks.OnPlayerItembanPermission(ply, this);

            if (hookResult != PermissionHookResult.Unhandled)
            {
                return(hookResult == PermissionHookResult.Granted);
            }

            var cur       = ply.Group;
            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.
        }