コード例 #1
0
        public static Permission RegisterPermission(string name, string desc, PermissionDefault def, Dictionary <string, bool> children, Permission parent)
        {
            Permission perm = RegisterPermission(name, desc, def, children);

            if (!parent.Children.ContainsKey(perm.Name))
            {
                parent.Children.Add(perm.Name, true);
            }
            return(perm);
        }
コード例 #2
0
        public static Permission LoadPermission <TKey, TValue>(String name, Dictionary <TKey, TValue> data, PermissionDefault def, List <Permission> output)
        {
            Debug.Assert(name != null, "Name cannot be null");
            Debug.Assert(data != null, "Data cannot be null");

            String desc = null;
            Dictionary <String, Boolean> children = null;

            if (((Dictionary <TKey, string>)((object)data))[(TKey)((object)"default")] != null)
            {
                PermissionDefault value = PermissionDefaultHelper.GetByName(data[(TKey)((object)"default")].ToString());
                if (value != default(PermissionDefault))
                {
                    def = value;
                }
                else
                {
                    throw new ArgumentException("'default' key contained unknown value");
                }
            }

            if (data[(TKey)((object)"children")] != null)
            {
                object childrenNode = data[(TKey)((object)"children")];
                if (childrenNode is IList)
                {
                    children = new Dictionary <string, bool>();
                    foreach (var child in (List <TKey>)childrenNode)
                    {
                        if (child != null)
                        {
                            children.Add(child.ToString(), true);
                        }
                    }
                }
                else if (childrenNode is Dictionary <TKey, TValue> )
                {
                    children = ExtractChildren((Dictionary <TKey, TValue>)childrenNode, name, def, output);
                }
                else
                {
                    throw new ArgumentException("'children' key is of wrong type");
                }
            }

            if (data[(TKey)((object)"description")] != null)
            {
                desc = data[(TKey)((object)"description")].ToString();
            }

            return(new Permission(name, desc, def, children));
        }
コード例 #3
0
        public Permission(String name, String description, PermissionDefault defaultValue, Dictionary <string, bool> children)
        {
            this.name        = name;
            this.description = description ?? "";

            if (defaultValue != null)
            {
                this.defaultValue = defaultValue;
            }

            if (children != null)
            {
                this.children = children;
            }

            RecalculatePermissibles();
        }
コード例 #4
0
        public static bool GetValue(this PermissionDefault def, bool op)
        {
            switch (def)
            {
            case PermissionDefault.True:
                return(true);

            case PermissionDefault.False:
                return(false);

            case PermissionDefault.OP:
                return(op);

            case PermissionDefault.NotOP:
                return(!op);

            default:
                return(false);
            }
        }
コード例 #5
0
 public Permission(string name, string description, PermissionDefault defaultValue)
     : this(name, description, defaultValue, null)
 {
 }
コード例 #6
0
 public Permission(string name, PermissionDefault defaultValue)
     : this(name, null, defaultValue, null)
 {
 }
コード例 #7
0
        private static Dictionary <string, bool> ExtractChildren <TKey, TValue>(Dictionary <TKey, TValue> input, String name, PermissionDefault def, List <Permission> output)
        {
            Dictionary <string, bool> children = new Dictionary <string, bool>();

            foreach (var entry in input)
            {
                if (((object)entry.Value is bool))
                {
                    children.Add(entry.Key.ToString(), (bool)((object)entry.Value));
                }
                else if (((object)entry.Value is Dictionary <TKey, TValue>))
                {
                    try
                    {
                        Permission perm = LoadPermission(entry.Key.ToString(), (Dictionary <TKey, TValue>)((object)entry.Value), def, output);
                        children.Add(perm.Name, true);

                        if (output != null)
                        {
                            output.Add(perm);
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new ArgumentException("Permission node '" + entry.Key.ToString() + "' in child of " + name + " is invalid", ex);
                    }
                }
                else
                {
                    throw new ArgumentException("Child '" + entry.Key.ToString() + "' contains invalid value");
                }
            }

            return(children);
        }
コード例 #8
0
        public static List <Permission> LoadPermissions <TKey, TValue>(Dictionary <TKey, TValue> data, string error, PermissionDefault def)
        {
            List <Permission> result = new List <Permission>();

            foreach (var entry in data)
            {
                try
                {
                    result.Add(Permission.LoadPermission(entry.Key.ToString(), (Dictionary <TKey, TValue>)((object)entry.Value), def, result));
                }
                catch (Exception ex)
                {
                    Bukkit.Server.GetLogger().Log(Level.SEVERE, String.Format(error, entry.Key), ex);
                }
            }

            return(result);
        }
コード例 #9
0
 public Permission(String name, PermissionDefault defaultValue, Dictionary <string, bool> children)
     : this(name, null, defaultValue, children)
 {
 }
コード例 #10
0
        public static Permission RegisterPermission(string name, string desc, PermissionDefault def, Dictionary <string, bool> children)
        {
            Permission perm = RegisterPermission(new Permission(name, desc, def, children));

            return(perm);
        }
コード例 #11
0
        public static Permission RegisterPermission(string name, string desc, PermissionDefault def)
        {
            Permission perm = RegisterPermission(new Permission(name, desc, def));

            return(perm);
        }