Иконка ресурса

FREE PermissionsManager : 2.1.2 2.1.2

Нет прав для скачивания
C#:
using System;
using System.Linq;
using System.Globalization;
using System.Collections.Generic;
using UnityEngine;
using Oxide.Core.Plugins;
using Oxide.Game.Rust.Cui;
using Newtonsoft.Json;
using Oxide.Core;
using Oxide.Core.Database;
using Facepunch;
namespace Oxide.Plugins {
    //  To do
    //  Change button colour of permission to indicate that player/group has at least one perm from that plugin.
    //  Create player UI, behind permission or global true/false, to let players see what permissions they have access to.
    //  Add button to remove records for 'Unnamed' players (from UI or from perms db?)
    //  Changes in 2.1.2
    //  Fix for missing plugins, and for Rust Update July
    [Info("PermissionsManager", "Steenamaroo", "2.1.2", ResourceId = 3)]
    class PermissionsManager : RustPlugin {
        IEnumerable<string> AllPerms;
        List<ulong> MenuOpen = Pool.Get<List<ulong>>();
        Dictionary<string, List<string>> PlugsAndPerms = new Dictionary<string, List<string>>();
        bool HasPermission(string id, string perm) => permission.UserHasPermission(id, perm);
        const string permAllowed = "permissionsmanager.allowed";
        Dictionary<ulong, Info> ActiveAdmins = new Dictionary<ulong, Info>();
        public class Info {
            public string inheritedcheck = "";
            public int pluginPage = 1;
            public int PPage = 1;
            public int GPage = 1;
            public string subjectGroup;
            public BasePlayer subject;
        }
        string ButtonColour1 = "0.7 0.32 0.17 1";
        string ButtonColour2 = "0.2 0.2 0.2 1";
#region Hooks
        void OnPluginLoaded(Plugin plugin) {
            if (!init || plugin is PermissionsManager) return;
            CloseUIs();
            AllPerms = permission.GetPermissions();
            var name = plugin.Name;
            foreach (var perm in AllPerms) if (perm.Contains(name, CompareOptions.IgnoreCase) && !(config.BlockList.Split(',').Contains(name, StringComparer.OrdinalIgnoreCase))) {
                if (!PlugsAndPerms.ContainsKey(name)) PlugsAndPerms[name] = new List<string>() {
                    perm
                }
                ;
                else PlugsAndPerms[name].Add(perm);
            }
            PlugsAndPerms = PlugsAndPerms.OrderBy(x => x.Key).ToDictionary(x => x.Key, x => x.Value);
        }
        void OnPluginUnloaded(Plugin plugin) {
            if (!init || plugin is PermissionsManager) return;
            var name = plugin.Name;
            if (PlugsAndPerms.ContainsKey(name)) PlugsAndPerms.Remove(name);
            CloseUIs();
        }
        void Init() {
            lang.RegisterMessages(messages, this);
            permission.RegisterPermission(permAllowed, this);
        }
        void CloseUIs() {
            foreach (BasePlayer player in BasePlayer.activePlayerList.Where(player => player?.net?.connection != null && MenuOpen.Contains(player.userID))) DestroyMenu(player, true);
        }
        bool init = false;
        void OnServerInitialized() {
            CloseUIs();
            if (!LoadConfigVariables()) {
                Puts("Config file issue detected. Please delete file, or check syntax and fix.");
                Interface.Oxide.UnloadPlugin(Name);
                return;
            }
            config.BlockList = config.BlockList.ToLower();
            GetPlugs();
            init = true;
            if (Sql_conn == null) Sql_conn = Sql.OpenDb(config.MySQL.sql_host, config.MySQL.sql_port, config.MySQL.sql_db, config.MySQL.sql_user, config.MySQL.sql_pass + ";Connection Timeout = 10; CharSet=utf8mb4", this);
        }
        void Unload() {
            CloseUIs();
            SaveData();
            Pool.FreeUnmanaged<ulong>(ref MenuOpen);
        }
        void OnPlayerDisconnected(BasePlayer player) {
            if (MenuOpen.Contains(player.userID)) DestroyMenu(player, true);
        }
        void OnPlayerDeath(BasePlayer player, HitInfo info) {
            if (player?.net?.connection != null && MenuOpen.Contains(player.userID)) DestroyMenu(player, true);
        }
#endregion
#region Methods
        void DestroyMenu(BasePlayer player, bool all) {
            CuiHelper.DestroyUi(player, "PMMainUI");
            CuiHelper.DestroyUi(player, "PMPermsUI");
            CuiHelper.DestroyUi(player, "PMConfirmUI");
            CuiHelper.DestroyUi(player, "PMDataUI");
            CuiHelper.DestroyUi(player, "PMDataConfirm");
            CuiHelper.DestroyUi(player, "PMMsgUI");
            if (all) {
                CuiHelper.DestroyUi(player, "PMBgUI");
                MenuOpen.Remove(player.userID);
            }
        }
        void GetPlugs() {
            AllPerms = permission.GetPermissions();
            foreach (var entry in plugins.GetAll().Where(x => !x.IsCorePlugin).Select(x => x.Name)) {
                foreach (var perm in AllPerms) if (perm.Contains(entry, CompareOptions.IgnoreCase) && !(config.BlockList.Split(',').Contains(entry, StringComparer.OrdinalIgnoreCase))) if (!PlugsAndPerms.ContainsKey(entry)) PlugsAndPerms[entry] = new List<string>() {
                    perm
                }
                ;
                else PlugsAndPerms[entry].Add(perm);
            }
            PlugsAndPerms = PlugsAndPerms.OrderBy(x => x.Key).ToDictionary(x =>x.Key, x => x.Value);
        }
        bool IsAuth(BasePlayer player) => player?.net?.connection != null && player.net.connection.authLevel == 2;
        void SetButtons(bool on) {
            ButtonColour1 = (on) ? config.OffColour : config.OnColour;
            ButtonColour2 = (on) ? config.OnColour : config.OffColour;
        }
        object[] PermsCheck(BasePlayer player, string group, string info) {
            bool has = false;
            List<string> inherited = new List<string>();
            var path = ActiveAdmins[player.userID];
            if (group == "true") {
                if (permission.GroupHasPermission(path.subjectGroup, info)) has = true;
            }
            else {
                var userData = permission.GetUserData(path.subject.UserIDString);
                if (userData.Perms.Contains(info)) has = true;
                foreach (var group1 in permission.GetUserGroups(path.subject.UserIDString)) if (permission.GroupHasPermission(group1, info)) inherited.Add(group1);
            }
            return new object[] {
                has, inherited
            }
            ;
        }
#endregion
#region UI
        void PMBgUI(BasePlayer player) {
            MenuOpen.Add(player.userID);
            string guiString = String.Format("0.1 0.1 0.1 {0}", config.guitransparency);
            var elements = new CuiElementContainer();
            var mainName = elements.Add(new CuiPanel {
                Image = {
                    Color = guiString
                }
                , RectTransform = {
                    AnchorMin = "0.3 0.1", AnchorMax = "0.7 0.9"
                }
                , CursorEnabled = true
            }
            , "Overlay", "PMBgUI");
            elements.Add(new CuiPanel {
                Image = {
                    Color = $"0 0 0 1"
                }
                , RectTransform = {
                    AnchorMin = $"0 0.95", AnchorMax = $"0.999 1"
                }
                , CursorEnabled = true
            }
            , mainName);
            elements.Add(new CuiPanel {
                Image = {
                    Color = $"0 0 0 1"
                }
                , RectTransform = {
                    AnchorMin = $"0 0", AnchorMax = $"0.999 0.05"
                }
                , CursorEnabled = true
            }
            , mainName);
            elements.Add(new CuiButton {
                Button = {
                    Command = "ClosePM", Color = config.ButtonColour
                }
                , RectTransform = {
                    AnchorMin = "0.955 0.96", AnchorMax = "0.99 0.995"
                }
                , Text = {
                    Text = "X", FontSize = 11, Align = TextAnchor.MiddleCenter
                }
            }
            , mainName);
            CuiHelper.AddUi(player, elements);
        }
        void PMMainUI(BasePlayer player, bool group, int page) {
            var elements = new CuiElementContainer();
            var mainName = elements.Add(new CuiPanel {
                Image = {
                    Color = "0 0 0 0"
                }
                , RectTransform = {
                    AnchorMin = "0.32 0.1", AnchorMax = "0.68 0.9"
                }
                , CursorEnabled = true
            }
            , "Overlay", "PMMainUI");
            string subject = group ? lang.GetMessage("GUIPlayers", this) : lang.GetMessage("GUIGroups", this);
            string current = !group ? lang.GetMessage("GUIPlayers", this) : lang.GetMessage("GUIGroups", this);
            elements.Add(new CuiLabel {
                Text = {
                    Text = "Permissions Manager V2", FontSize = 16, Align = TextAnchor.MiddleCenter
                }
                , RectTransform = {
                    AnchorMin = "0 0.95", AnchorMax = "1 1"
                }
            }
            , mainName);
            elements.Add(new CuiButton {
                Button = {
                    Command = $"PMTogglePlayerGroup {group} 1", Color = config.ButtonColour
                }
                , RectTransform = {
                    AnchorMin = "0.4 0.02", AnchorMax = "0.6 0.04"
                }
                , Text = {
                    Text = lang.GetMessage("All", this) + " " + subject, FontSize = 11, Align = TextAnchor.MiddleCenter
                }
            }
            , mainName);
            int pos1 = 20 - (page * 20), quantity = 0;
            float top = 0.87f;
            float bottom = 0.85f;
            elements.Add(new CuiLabel {
                Text = {
                    Text = lang.GetMessage("All", this) + " " + current, FontSize = 14, Align = TextAnchor.MiddleCenter
                }
                , RectTransform = {
                    AnchorMin = "0 0.9", AnchorMax = "1 0.97"
                }
            }
            , mainName);
            if (group) {
                foreach (var grp in permission.GetGroups().OrderBy(x => x)) {
                    pos1++;
                    quantity++;
                    if (pos1 > 0 && pos1 < 21) {
                        elements.Add(new CuiButton {
                            Button = {
                                Command = $"PMSelected group {grp}", Color = config.ButtonColour
                            }
                            , RectTransform = {
                                AnchorMin = $"0.3 {bottom}", AnchorMax = $"0.7 {top}"
                            }
                            , Text = {
                                Text = $"{grp}", FontSize = 11, Align = TextAnchor.MiddleCenter
                            }
                        }
                        , mainName);
                        top = top - 0.025f;
                        bottom = bottom - 0.025f;
                    }
                }
            }
            else {
                foreach (var plyr in BasePlayer.allPlayerList.OrderBy(x => x.displayName).OrderBy(x => x?.net?.connection == null)) {
                    pos1++;
                    quantity++;
                    if (pos1 > 0 && pos1 < 21) {
                        elements.Add(new CuiButton {
                            Button = {
                                Command = $"PMSelected player {plyr.userID}", Color = config.ButtonColour
                            }
                            , RectTransform = {
                                AnchorMin = $"0.3 {bottom}", AnchorMax = $"0.7 {top}"
                            }
                            , Text = {
                                Text = StripSlashes(plyr.displayName), FontSize = 11, Align = TextAnchor.MiddleCenter, Color = plyr?.net?.connection == null ? "1 1 1 1" : "0.2 1 0.2 1"
                            }
                        }
                        , mainName);
                        top = top - 0.025f;
                        bottom = bottom - 0.025f;
                    }
                }
            }
            if (quantity > (page * 20)) elements.Add(new CuiButton {
                Button = {
                    Command = $"PMTogglePlayerGroup {!group} {page + 1}", Color = config.ButtonColour
                }
                , RectTransform = {
                    AnchorMin = "0.8 0.02", AnchorMax = "0.9 0.04"
                }
                , Text = {
                    Text = lang.GetMessage("->", this), FontSize = 11, Align = TextAnchor.MiddleCenter
                }
                ,
            }
            , mainName);
            if (page > 1) elements.Add(new CuiButton {
                Button = {
                    Command = $"PMTogglePlayerGroup {!group} {page - 1}", Color = config.ButtonColour
                }
                , RectTransform = {
                    AnchorMin = "0.1 0.02", AnchorMax = "0.2 0.04"
                }
                , Text = {
                    Text = lang.GetMessage("<-", this), FontSize = 11, Align = TextAnchor.MiddleCenter
                }
                ,
            }
            , mainName);
            CuiHelper.AddUi(player, elements);
        }
        void PMDataUI(BasePlayer player) {
            var elements = new CuiElementContainer();
            var mainName = elements.Add(new CuiPanel {
                Image = {
                    Color = "0 0 0 0"
                }
                , RectTransform = {
                    AnchorMin = "0.32 0.1", AnchorMax = "0.68 0.9"
                }
                , CursorEnabled = true
            }
            , "Overlay", "PMDataUI");
            elements.Add(new CuiLabel {
                Text = {
                    Text = "Permissions Manager - Data Menu", FontSize = 16, Align = TextAnchor.MiddleCenter
                }
                , RectTransform = {
                    AnchorMin = "0 0.95", AnchorMax = "1 1"
                }
            }
            , mainName);
            elements.Add(new CuiButton {
                Button = {
                    Color = "0 0 0 1"
                }
                , RectTransform = {
                    AnchorMin = "0.1 0.85", AnchorMax = $"0.898 0.88"
                }
                , Text = {
                    Text = String.Empty
                }
            }
            , mainName);
            elements.Add(new CuiLabel {
                Text = {
                    Text = "Local data backup.", FontSize = 14, Align = TextAnchor.MiddleCenter
                }
                , RectTransform = {
                    AnchorMin = "0.1 0.85", AnchorMax = $"0.898 0.88"
                }
                ,
            }
            , mainName);
            elements.Add(new CuiLabel {
                Text = {
                    Text = "Save", FontSize = 13, Align = TextAnchor.MiddleCenter
                }
                , RectTransform = {
                    AnchorMin = "0.1 0.81", AnchorMax = "0.3 0.835"
                }
            }
            , mainName);
            elements.Add(new CuiButton {
                Button = {
                    Command = $"PMDataConfirm 0", Color = config.ButtonColour
                }
                , RectTransform = {
                    AnchorMin = $"0.4 0.81", AnchorMax = $"0.6 0.835"
                }
                , Text = {
                    Text = $"Groups", FontSize = 10, Align = TextAnchor.MiddleCenter
                }
            }
            , mainName);
            elements.Add(new CuiButton {
                Button = {
                    Command = $"PMDataConfirm 1", Color = config.ButtonColour
                }
                , RectTransform = {
                    AnchorMin = $"0.7 0.81", AnchorMax = $"0.9 0.835"
                }
                , Text = {
                    Text = $"Players", FontSize = 10, Align = TextAnchor.MiddleCenter
                }
            }
            , mainName);
            elements.Add(new CuiLabel {
                Text = {
                    Text = "Load", FontSize = 13, Align = TextAnchor.MiddleCenter
                }
                , RectTransform = {
                    AnchorMin = "0.1 0.78", AnchorMax = "0.3 0.805"
                }
            }
            , mainName);
            elements.Add(new CuiButton {
                Button = {
                    Command = $"PMDataConfirm 2", Color = config.ButtonColour
                }
                , RectTransform = {
                    AnchorMin = $"0.4 0.78", AnchorMax = $"0.6 0.805"
                }
                , Text = {
                    Text = $"Groups", FontSize = 10, Align = TextAnchor.MiddleCenter
                }
            }
            , mainName);
            elements.Add(new CuiButton {
                Button = {
                    Command = $"PMDataConfirm 3", Color = config.ButtonColour
                }
                , RectTransform = {
                    AnchorMin = $"0.7 0.78", AnchorMax = $"0.9 0.805"
                }
                , Text = {
                    Text = $"Players", FontSize = 10, Align = TextAnchor.MiddleCenter
                }
            }
            , mainName);
            elements.Add(new CuiButton {
                Button = {
                    Command = $"PMDataConfirm 4", Color = config.ButtonColour
                }
                , RectTransform = {
                    AnchorMin = $"0.4 0.74", AnchorMax = $"0.9 0.765"
                }
                , Text = {
                    Text = $"Wipe local data backup", FontSize = 10, Align = TextAnchor.MiddleCenter
                }
            }
            , mainName);
            if (config.MySQL.useMySQL) {
                elements.Add(new CuiButton {
                    Button = {
                        Color = "0 0 0 1"
                    }
                    , RectTransform = {
                        AnchorMin = "0.1 0.65", AnchorMax = $"0.898 0.68"
                    }
                    , Text = {
                        Text = String.Empty
                    }
                }
                , mainName);
                elements.Add(new CuiLabel {
                    Text = {
                        Text = "SQL table backup.", FontSize = 14, Align = TextAnchor.MiddleCenter
                    }
                    , RectTransform = {
                        AnchorMin = "0.1 0.65", AnchorMax = $"0.898 0.68"
                    }
                    ,
                }
                , mainName);
                elements.Add(new CuiLabel {
                    Text = {
                        Text = "Save", FontSize = 13, Align = TextAnchor.MiddleCenter
                    }
                    , RectTransform = {
                        AnchorMin = "0.1 0.61", AnchorMax = "0.3 0.635"
                    }
                }
                , mainName);
                elements.Add(new CuiButton {
                    Button = {
                        Command = $"PMDataConfirm 5", Color = config.ButtonColour
                    }
                    , RectTransform = {
                        AnchorMin = $"0.4 0.61", AnchorMax = $"0.6 0.635"
                    }
                    , Text = {
                        Text = $"Groups", FontSize = 10, Align = TextAnchor.MiddleCenter
                    }
                }
                , mainName);
                elements.Add(new CuiButton {
                    Button = {
                        Command = $"PMDataConfirm 6", Color = config.ButtonColour
                    }
                    , RectTransform = {
                        AnchorMin = $"0.7 0.61", AnchorMax = $"0.9 0.635"
                    }
                    , Text = {
                        Text = $"Players", FontSize = 10, Align = TextAnchor.MiddleCenter
                    }
                }
                , mainName);
                elements.Add(new CuiLabel {
                    Text = {
                        Text = "Load", FontSize = 13, Align = TextAnchor.MiddleCenter
                    }
                    , RectTransform = {
                        AnchorMin = "0.1 0.58", AnchorMax = "0.3 0.605"
                    }
                }
                , mainName);
                elements.Add(new CuiButton {
                    Button = {
                        Command = $"PMDataConfirm 7", Color = config.ButtonColour
                    }
                    , RectTransform = {
                        AnchorMin = $"0.4 0.58", AnchorMax = $"0.6 0.605"
                    }
                    , Text = {
                        Text = $"Groups", FontSize = 10, Align = TextAnchor.MiddleCenter
                    }
                }
                , mainName);
                elements.Add(new CuiButton {
                    Button = {
                        Command = $"PMDataConfirm 8", Color = config.ButtonColour
                    }
                    , RectTransform = {
                        AnchorMin = $"0.7 0.58", AnchorMax = $"0.9 0.605"
                    }
                    , Text = {
                        Text = $"Players", FontSize = 10, Align = TextAnchor.MiddleCenter
                    }
                }
                , mainName);
                elements.Add(new CuiButton {
                    Button = {
                        Command = $"PMDataConfirm 9", Color = config.ButtonColour
                    }
                    , RectTransform = {
                        AnchorMin = $"0.4 0.54", AnchorMax = $"0.9 0.565"
                    }
                    , Text = {
                        Text = $"Wipe SQL backup", FontSize = 10, Align = TextAnchor.MiddleCenter
                    }
                }
                , mainName);
            }
            elements.Add(new CuiButton {
                Button = {
                    Color = "0 0 0 1"
                }
                , RectTransform = {
                    AnchorMin = "0.1 0.4", AnchorMax = $"0.898 0.43"
                }
                , Text = {
                    Text = String.Empty
                }
            }
            , mainName);
            elements.Add(new CuiLabel {
                Text = {
                    Text = "Purge Unloaded Permissions for...", FontSize = 14, Align = TextAnchor.MiddleCenter
                }
                , RectTransform = {
                    AnchorMin = "0.1 0.4", AnchorMax = $"0.898 0.43"
                }
                ,
            }
            , mainName);
            elements.Add(new CuiButton {
                Button = {
                    Command = $"PMDataConfirm 13", Color = config.ButtonColour
                }
                , RectTransform = {
                    AnchorMin = $"0.3 0.36", AnchorMax = $"0.7 0.39"
                }
                , Text = {
                    Text = $"Groups", FontSize = 10, Align = TextAnchor.MiddleCenter
                }
            }
            , mainName);
            elements.Add(new CuiButton {
                Button = {
                    Command = $"PMDataConfirm 14", Color = config.ButtonColour
                }
                , RectTransform = {
                    AnchorMin = $"0.3 0.325", AnchorMax = $"0.7 0.355"
                }
                , Text = {
                    Text = $"Players", FontSize = 10, Align = TextAnchor.MiddleCenter
                }
            }
            , mainName);
            elements.Add(new CuiButton {
                Button = {
                    Color = "0 0 0 1"
                }
                , RectTransform = {
                    AnchorMin = "0.1 0.17", AnchorMax = $"0.898 0.20"
                }
                , Text = {
                    Text = String.Empty
                }
            }
            , mainName);
            elements.Add(new CuiLabel {
                Text = {
                    Text = "Global remove.", FontSize = 13, Align = TextAnchor.MiddleCenter
                }
                , RectTransform = {
                    AnchorMin = "0.1 0.17", AnchorMax = $"0.898 0.20"
                }
                ,
            }
            , mainName);
            elements.Add(new CuiButton {
                Button = {
                    Command = $"PMDataConfirm 10", Color = config.ButtonColour
                }
                , RectTransform = {
                    AnchorMin = $"0.3 0.13", AnchorMax = $"0.7 0.16"
                }
                , Text = {
                    Text = $"Empty All Groups", FontSize = 10, Align = TextAnchor.MiddleCenter
                }
            }
            , mainName);
            elements.Add(new CuiButton {
                Button = {
                    Command = $"PMDataConfirm 11", Color = config.ButtonColour
                }
                , RectTransform = {
                    AnchorMin = $"0.3 0.095", AnchorMax = $"0.7 0.125"
                }
                , Text = {
                    Text = $"Delete All Groups", FontSize = 10, Align = TextAnchor.MiddleCenter
                }
            }
            , mainName);
            elements.Add(new CuiButton {
                Button = {
                    Command = $"PMDataConfirm 12", Color = config.ButtonColour
                }
                , RectTransform = {
                    AnchorMin = $"0.3 0.06", AnchorMax = $"0.7 0.09"
                }
                , Text = {
                    Text = $"Wipe All Player Permissions", FontSize = 10, Align = TextAnchor.MiddleCenter
                }
            }
            , mainName);
            CuiHelper.AddUi(player, elements);
        }
        void MsgUI(BasePlayer player, string message) {
            CuiHelper.DestroyUi(player, "PMMsgUI");
            timer.Once(1.5f, () => {
                if (player != null) CuiHelper.DestroyUi(player, "PMMsgUI");
            }
            );
            var elements = new CuiElementContainer();
            var first = elements.Add(new CuiPanel {
                Image = {
                    FadeIn = 0.3f, Color = $"0.1 0.1 0.1 0.95"
                }
                , RectTransform = {
                    AnchorMin = "0.3 0.4", AnchorMax = "0.7 0.6"
                }
                , CursorEnabled = false
            }
            , "Overlay", "PMMsgUI");
            elements.Add(new CuiLabel {
                Text = {
                    FadeIn = 0.5f, Text = message, Color = "1 1 1 1", FontSize = 28, Align = TextAnchor.MiddleCenter
                }
                , RectTransform = {
                    AnchorMin = "0 0", AnchorMax = "1 1"
                }
            }
            , first);
            CuiHelper.AddUi(player, elements);
        }
        [ConsoleCommand("PMDataConfirm")]
        private void PMDataConfirm(ConsoleSystem.Arg arg) {
            var player = arg?.Connection?.player as BasePlayer;
            var elements = new CuiElementContainer();
            var mainName = elements.Add(new CuiPanel {
                Image = {
                    Color = "0.2 0.2 0.2 0.1", Material = "assets/content/ui/uibackgroundblur.mat"
                }
                , RectTransform = {
                    AnchorMin = "0.3 0.09", AnchorMax = "0.7 0.91"
                }
                , CursorEnabled = true
            }
            , "Overlay", "PMDataConfirm");
            elements.Add(new CuiButton {
                Button = {
                    Color = "0 0 0 1"
                }
                , RectTransform = {
                    AnchorMin = "0.28 0.46", AnchorMax = $"0.72 0.54"
                }
                , Text = {
                    Text = String.Empty
                }
            }
            , mainName);
            elements.Add(new CuiLabel {
                Text = {
                    Text = "", FontSize = 16, Align = TextAnchor.MiddleCenter
                }
                , RectTransform = {
                    AnchorMin = "0.28 0.46", AnchorMax = $"0.72 0.54"
                }
                ,
            }
            , mainName);
            elements.Add(new CuiButton {
                Button = {
                    Command = $"ManageData true {arg.GetString(0)}", Color = config.ButtonColour
                }
                , RectTransform = {
                    AnchorMin = "0.3 0.48", AnchorMax = "0.45 0.52"
                }
                , Text = {
                    Text = lang.GetMessage("confirm", this), FontSize = 14, Align = TextAnchor.MiddleCenter
                }
                ,
            }
            , mainName);
            elements.Add(new CuiButton {
                Button = {
                    Command = $"ManageData false {arg.GetString(0)}", Color = config.ButtonColour
                }
                , RectTransform = {
                    AnchorMin = "0.55 0.48", AnchorMax = "0.7 0.52"
                }
                , Text = {
                    Text = lang.GetMessage("cancel", this), FontSize = 14, Align = TextAnchor.MiddleCenter
                }
                ,
            }
            , mainName);
            CuiHelper.AddUi(player, elements);
        }
        [ConsoleCommand("ManageData")]
        private void ManageData(ConsoleSystem.Arg arg) {
            string confirmation = arg.GetString(0);
            if (confirmation == "false") CuiHelper.DestroyUi(arg.Player(), "PMDataConfirm");
            else {
                int cmd = arg.GetInt(1);
                if (cmd == 1) MsgUI(arg.Player(), "Local Players Saved");
                // Do this message for every option.
                switch (cmd) {
                    case 0 : DoLocal(true, true);
                    break;
                    case 1 : DoLocal(true, false);
                    break;
                    case 2 : DoLocal(false, true);
                    break;
                    case 3 : DoLocal(false, false);
                    break;
                    case 4 : WipeLocal();
                    break;
                    case 5 : DoSQL(true, true);
                    break;
                    case 6 : DoSQL(true, false);
                    break;
                    case 7 : DoSQL(false, true);
                    break;
                    case 8 : DoSQL(false, false);
                    break;
                    case 9 : WipeSQL();
                    break;
                    case 10 : EmptyAllGroups();
                    break;
                    case 11 : DeleteAllGroups();
                    break;
                    case 12 : WipePlayerPerms();
                    break;
                    case 13 : PurgeUnloadedForGroups();
                    break;
                    case 14 : PurgeUnloadedForPlayers();
                    break;
                }
                CuiHelper.DestroyUi(arg.Player(), "PMDataConfirm");
            }
        }
        void PlugsUI(BasePlayer player, string msg, string group, int page) {
            var path = ActiveAdmins[player.userID];
            var backpage = group == "false" ? path.PPage : path.GPage;
            string toggle = (group == "true") ? "false" : "true";
            var elements = new CuiElementContainer();
            var mainName = elements.Add(new CuiPanel {
                Image = {
                    Color = "0 0 0 0"
                }
                , RectTransform = {
                    AnchorMin = "0.32 0.1", AnchorMax = "0.68 0.9"
                }
                , CursorEnabled = true
            }
            , "Overlay", "PMPermsUI");
            int plugsTotal = 0, pos1 = 60 - (page * 60), next = page + 1, previous = page - 1;
            foreach (var entry in PlugsAndPerms) {
                pos1++;
                plugsTotal++;
                if (pos1 > 0 && pos1 < 21) elements.Add(new CuiButton {
                    Button = {
                        Command = $"PermsList {entry.Key} null null {group} null 1", Color = config.ButtonColour
                    }
                    , RectTransform = {
                        AnchorMin = $"0.1 {(0.89 - (pos1 * 3f) / 100f)}", AnchorMax = $"0.3 {0.91 - (pos1 * 3f) / 100f}"
                    }
                    , Text = {
                        Text = $"{entry.Key}", FontSize = 10, Align = TextAnchor.MiddleCenter
                    }
                }
                , mainName);
                if (pos1 > 20 && pos1 < 41) elements.Add(new CuiButton {
                    Button = {
                        Command = $"PermsList {entry.Key} null null {group} null 1", Color = config.ButtonColour
                    }
                    , RectTransform = {
                        AnchorMin = $"0.4 {(0.89 - ((pos1 - 20) * 3f) / 100f)}", AnchorMax = $"0.6 {0.91 - ((pos1 - 20) * 3f) / 100f}"
                    }
                    , Text = {
                        Text = $"{entry.Key}", FontSize = 10, Align = TextAnchor.MiddleCenter
                    }
                }
                , mainName);
                if (pos1 > 40 && pos1 < 61) elements.Add(new CuiButton {
                    Button = {
                        Command = $"PermsList {entry.Key} null null {group} null 1", Color = config.ButtonColour
                    }
                    , RectTransform = {
                        AnchorMin = $"0.7 {(0.89 - ((pos1 - 40) * 3f) / 100f)}", AnchorMax = $"0.9 {0.91 - ((pos1 - 40) * 3f) / 100f}"
                    }
                    , Text = {
                        Text = $"{entry.Key}", FontSize = 10, Align = TextAnchor.MiddleCenter
                    }
                }
                , mainName);
            }
            elements.Add(new CuiButton {
                Button = {
                    Command = $"PMTogglePlayerGroup {toggle} {backpage}", Color = config.ButtonColour
                }
                , RectTransform = {
                    AnchorMin = "0.55 0.02", AnchorMax = "0.75 0.04"
                }
                , Text = {
                    Text = lang.GetMessage("GUIBack", this), FontSize = 11, Align = TextAnchor.MiddleCenter
                }
            }
            , mainName);
            elements.Add(new CuiLabel {
                Text = {
                    Text = msg, FontSize = 16, Align = TextAnchor.MiddleCenter
                }
                , RectTransform = {
                    AnchorMin = "0 0.95", AnchorMax = "1 1"
                }
            }
            , mainName);
            if (group == "false") elements.Add(new CuiButton {
                Button = {
                    Command = $"PMRevokeAllPlayer", Color = config.ButtonColour
                }
                , RectTransform = {
                    AnchorMin = "0.4 0.1", AnchorMax = "0.6 0.14"
                }
                , Text = {
                    Text = lang.GetMessage("RevokeAll", this), FontSize = 11, Align = TextAnchor.MiddleCenter
                }
            }
            , mainName);
            if (group == "false") elements.Add(new CuiButton {
                Button = {
                    Command = "Groups 1", Color = config.ButtonColour
                }
                , RectTransform = {
                    AnchorMin = "0.25 0.02", AnchorMax = "0.45 0.04"
                }
                , Text = {
                    Text = lang.GetMessage("GUIGroups", this), FontSize = 11, Align = TextAnchor.MiddleCenter
                }
            }
            , mainName);
            else elements.Add(new CuiButton {
                Button = {
                    Command = "PlayersIn 1", Color = config.ButtonColour
                }
                , RectTransform = {
                    AnchorMin = "0.25 0.02", AnchorMax = "0.45 0.04"
                }
                , Text = {
                    Text = lang.GetMessage("GUIPlayers", this), FontSize = 11, Align = TextAnchor.MiddleCenter
                }
            }
            , mainName);
            if (plugsTotal > (page * 60)) elements.Add(new CuiButton {
                Button = {
                    Command = $"Navigate {group} {next}", Color = config.ButtonColour
                }
                , RectTransform = {
                    AnchorMin = "0.8 0.02", AnchorMax = "0.9 0.04"
                }
                , Text = {
                    Text = lang.GetMessage("->", this), FontSize = 11, Align = TextAnchor.MiddleCenter
                }
                ,
            }
            , mainName);
            if (page > 1) elements.Add(new CuiButton {
                Button = {
                    Command = $"Navigate {group} {previous}", Color = config.ButtonColour
                }
                , RectTransform = {
                    AnchorMin = "0.1 0.02", AnchorMax = "0.2 0.04"
                }
                , Text = {
                    Text = lang.GetMessage("<-", this), FontSize = 11, Align = TextAnchor.MiddleCenter
                }
                ,
            }
            , mainName);
            CuiHelper.AddUi(player, elements);
        }
        void PMPermsUI(BasePlayer player, string msg, string plugName, string group, int page) {
            var path = ActiveAdmins[player.userID];
            var elements = new CuiElementContainer();
            var mainName = elements.Add(new CuiPanel {
                Image = {
                    Color = "0 0 0 0"
                }
                , RectTransform = {
                    AnchorMin = "0.32 0.1", AnchorMax = "0.68 0.9"
                }
                , CursorEnabled = true
            }
            , "Overlay", "PMPermsUI");
            int permsTotal = 0, pos1 = 20 - (page * 20), next = (page + 1), previous = (page - 1);
            elements.Add(new CuiButton {
                Button = {
                    Command = $"PermsList {plugName} grant null {group} all {page}", Color = config.ButtonColour
                }
                , RectTransform = {
                    AnchorMin = $"0.5 {(0.89 - (pos1 * 3f) / 100f)}", AnchorMax = $"0.6 {(0.91 - (pos1 * 3f) / 100f)}"
                }
                , Text = {
                    Text = lang.GetMessage("GUIAll", this), FontSize = 10, Align = TextAnchor.MiddleCenter
                }
            }
            , mainName);
            elements.Add(new CuiButton {
                Button = {
                    Command = $"PermsList {plugName} revoke null {group} all {page}", Color = config.ButtonColour
                }
                , RectTransform = {
                    AnchorMin = $"0.65 {(0.89 - (pos1 * 3f) / 100f)}", AnchorMax = $"0.75 {(0.91 - (pos1 * 3f) / 100f)}"
                }
                , Text = {
                    Text = lang.GetMessage("GUINone", this), FontSize = 10, Align = TextAnchor.MiddleCenter
                }
            }
            , mainName);
            var elements1 = new CuiElementContainer();
            bool list = false;
            for (int i = 0; i < PlugsAndPerms[plugName].Count; i++) {
                SetButtons(true);
                pos1++;
                permsTotal++;
                string showName = PlugsAndPerms[plugName][i];
                string output = showName.Substring(showName.IndexOf('.') + 1);
                string granted = lang.GetMessage("GUIGranted", this);
                if (pos1 > 0 && pos1 < 21) {
                    granted = lang.GetMessage("GUIGranted", this);
                    if ((bool)PermsCheck(player, group, showName)[0]) SetButtons(false);
                    List<string> inheritcheck = (List<string>)(PermsCheck(player, group, showName)[1]);
                    if (inheritcheck.Count > 0) {
                        if (path.inheritedcheck == showName) {
                            var mainName1 = elements1.Add(new CuiPanel {
                                Image = {
                                    Color = "0.1 0.1 0.1 0.99"
                                }
                                , RectTransform = {
                                    AnchorMin = "0.3 0.1", AnchorMax = "0.7 0.86"
                                }
                                , CursorEnabled = true
                            }
                            , "Overlay", "PMConfirmUI");
                            elements1.Add(new CuiButton {
                                Button = {
                                    Command = $"ShowInherited {plugName} null {showName} {group} null {page} -", Color = config.ButtonColour
                                }
                                , RectTransform = {
                                    AnchorMin = "0.4 0.01", AnchorMax = "0.6 0.05"
                                }
                                , Text = {
                                    Text = lang.GetMessage("GUIBack", this), FontSize = 14, Align = TextAnchor.MiddleCenter
                                }
                                ,
                            }
                            , mainName1);
                            float h1 = 0, h2 = 0;
                            elements1.Add(new CuiButton {
                                Button = {
                                    Command = "", Color = config.ButtonColour
                                }
                                , RectTransform = {
                                    AnchorMin = "0.3 0.8", AnchorMax = "0.7 0.825"
                                }
                                , Text = {
                                    Text = $"{showName}", FontSize = 12, Align = TextAnchor.MiddleCenter
                                }
                                ,
                            }
                            , mainName1);
                            elements1.Add(new CuiLabel {
                                Text = {
                                    Text = $"{lang.GetMessage("GUIInheritedFrom", this)}", FontSize = 11, Align = TextAnchor.MiddleCenter
                                }
                                , RectTransform = {
                                    AnchorMin = "0 0.77", AnchorMax = "1 0.8"
                                }
                            }
                            , mainName1);
                            for (int j = 0; j < inheritcheck.Count; j++) {
                                h1 = j * 0.022f;
                                h2 = j * 0.022f;
                                elements1.Add(new CuiLabel {
                                    Text = {
                                        Text = $"{inheritcheck[j]}", FontSize = 11, Align = TextAnchor.MiddleCenter
                                    }
                                    , RectTransform = {
                                        AnchorMin = $"0 {0.7 - h1}", AnchorMax = $"1 {0.75 - h2}"
                                    }
                                }
                                , mainName1);
                            }
                            list = true;
                        }
                        elements.Add(new CuiButton {
                            Button = {
                                Command = $"ShowInherited {plugName} null {showName} {group} null {page} {showName}", Color = config.InheritedColour
                            }
                            , RectTransform = {
                                AnchorMin = $"0.8 {(0.89 - (pos1 * 3f) / 100f)}", AnchorMax = $"0.9 {(0.91 - (pos1 * 3f) / 100f)}"
                            }
                            , Text = {
                                Text = lang.GetMessage("GUIInherited", this), FontSize = 10, Align = TextAnchor.MiddleCenter
                            }
                        }
                        , mainName);
                    }
                    elements.Add(new CuiButton {
                        Button = {
                            Color = config.ButtonColour
                        }
                        , RectTransform = {
                            AnchorMin = $"0.1 {(0.89 - (pos1 * 3f) / 100f)}", AnchorMax = $"0.45 {(0.91 - (pos1 * 3f) / 100f)}"
                        }
                        , Text = {
                            Text = $"{output}", FontSize = 10, Align = TextAnchor.MiddleCenter
                        }
                    }
                    , mainName);
                    elements.Add(new CuiButton {
                        Button = {
                            Command = $"PermsList {plugName} grant {showName} {group} null {page}", Color = ButtonColour1
                        }
                        , RectTransform = {
                            AnchorMin = $"0.5 {(0.89 - (pos1 * 3f) / 100f)}", AnchorMax = $"0.6 {(0.91 - (pos1 * 3f) / 100f)}"
                        }
                        , Text = {
                            Text = lang.GetMessage("GUIGranted", this), FontSize = 10, Align = TextAnchor.MiddleCenter
                        }
                    }
                    , mainName);
                    elements.Add(new CuiButton {
                        Button = {
                            Command = $"PermsList {plugName} revoke {showName} {group} null {page}", Color = ButtonColour2
                        }
                        , RectTransform = {
                            AnchorMin = $"0.65 {(0.89 - (pos1 * 3f) / 100f)}", AnchorMax = $"0.75 {(0.91 - (pos1 * 3f) / 100f)}"
                        }
                        , Text = {
                            Text = lang.GetMessage("GUIRevoked", this), FontSize = 10, Align = TextAnchor.MiddleCenter
                        }
                    }
                    , mainName);
                }
            }
            elements.Add(new CuiButton {
                Button = {
                    Command = $"Navigate {group} {path.pluginPage}", Color = config.ButtonColour
                }
                , RectTransform = {
                    AnchorMin = "0.4 0.02", AnchorMax = "0.6 0.04"
                }
                , Text = {
                    Text = lang.GetMessage("GUIBack", this), FontSize = 11, Align = TextAnchor.MiddleCenter
                }
            }
            , mainName);
            elements.Add(new CuiLabel {
                Text = {
                    Text = msg, FontSize = 16, Align = TextAnchor.MiddleCenter
                }
                , RectTransform = {
                    AnchorMin = "0 0.95", AnchorMax = "1 1"
                }
            }
            , mainName);
            if (permsTotal > (page * 20)) elements.Add(new CuiButton {
                Button = {
                    Command = $"PermsList {plugName} null null {group} null
// ... [Code preview truncated due to length. Full source in attached file] ...

Автор
15FPS
Скачиваний
0
Просмотры
1
Первый выпуск
Обновление
Оценка
0.00 звёзд 0 оценок
Сверху