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

FREE PermissionsManager : 1.0.0 1.0.0

Нет прав для скачивания
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;
namespace Oxide.Plugins {
    // To do
    // Change button colour of permission to indicate that player/group has at least one perm from that plugin.// Fix for oxide case sensitivity changes.[Info("PermissionsManager", "https://discord.gg/9vyTXsJyKR", "1.0.0", ResourceId = 3)]
    class PermissionsManager : RustPlugin {
#region Declarations
        List<string> PlugList = new List<string>();
        Dictionary<int, string> numberedPerms = new Dictionary<int, string>();
        List<ulong> MenuOpen = new List<ulong>();
        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 noOfPlugs;
            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";
#endregion
#region Hooks
        void OnPluginLoaded(Plugin plugin) {
            if (plugin is PermissionsManager) return;
            Wipe();
            OnServerInitialized();
        }
        void OnPluginUnloaded(Plugin plugin) {
            if (plugin is PermissionsManager) return;
            Wipe();
            OnServerInitialized();
        }
        void Init() {
            lang.RegisterMessages(messages, this);
            permission.RegisterPermission(permAllowed, this);
        }
        void OnServerInitialized() {
            foreach (BasePlayer player in BasePlayer.activePlayerList.Where(player => MenuOpen.Contains(player.userID))) DestroyMenu(player, true);
            if (!LoadConfigVariables()) {
                Puts("Config file issue detected.Please delete file, or check syntax and fix.");
                Interface.Oxide.UnloadPlugin(Name);
                return;
            }
            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);
            if (!config.Keep_Perms_After_Wipe) {
                Unsubscribe(nameof(OnServerSave));
                Unsubscribe(nameof(OnNewSave));
            }
        }
        void Unload() {
            foreach (BasePlayer player in BasePlayer.activePlayerList.Where(player => MenuOpen.Contains(player.userID))) DestroyMenu(player, true);
            SaveData();
        }
        void OnPlayerDisconnected(BasePlayer player) {
            if (MenuOpen.Contains(player.userID)) DestroyMenu(player, true);
        }
        void OnPlayerDeath(BasePlayer player, HitInfo info) {
            if (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 Wipe() {
            PlugList.Clear();
            numberedPerms.Clear();
        }
        void GetPlugs(BasePlayer player) {
            var path = ActiveAdmins[player.userID];
            PlugList.Clear();
            path.noOfPlugs = 0;
            foreach (var entry in plugins.GetAll()) {
                if (entry.IsCorePlugin) continue;
                var str = entry.ToString().Replace("Oxide.Plugins.", "").ToLower();
                foreach (var perm in permission.GetPermissions().ToList().Where(perm => perm.ToLower().Contains($"{str}") && !(config.BlockList.ToLower().Split(',').ToList().Contains($"{str}")))) if (!PlugList.Contains(str)) PlugList.Add(str);
            }
            PlugList.Sort();
        }
        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, FadeOut = 0.1f
            }
            , "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) {
                    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
                            }
                        }
                        , 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 = "Server Permissions.", 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, FadeOut = 0.3f
            }
            , "Overlay", "PMMsgUI");
            elements.Add(new CuiLabel {
                FadeOut = 0.5f, 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, FadeOut = 0.1f
            }
            , "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.Args[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.Args[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.Args[0];
            if (confirmation == "false") CuiHelper.DestroyUi(arg.Player(), "PMDataConfirm");
            else {
                int cmd = Convert.ToInt16(arg.Args[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;
            for (int i = 0; i < PlugList.Count; i++) {
                pos1++;
                plugsTotal++;
                if (pos1 > 0 && pos1 < 21) elements.Add(new CuiButton {
                    Button = {
                        Command = $"PermsList {i} 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 = $"{PlugList[i]}", FontSize = 10, Align = TextAnchor.MiddleCenter
                    }
                }
                , mainName);
                if (pos1 > 20 && pos1 < 41) elements.Add(new CuiButton {
                    Button = {
                        Command = $"PermsList {i} 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 = $"{PlugList[i]}", FontSize = 10, Align = TextAnchor.MiddleCenter
                    }
                }
                , mainName);
                if (pos1 > 40 && pos1 < 61) elements.Add(new CuiButton {
                    Button = {
                        Command = $"PermsList {i} 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 = $"{PlugList[i]}", 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 = "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, int PlugNumber, 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 {PlugNumber} 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 {PlugNumber} 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;
            foreach (var perm in numberedPerms) {
                SetButtons(true);
                pos1++;
                permsTotal++;
                var permNo = perm.Key;
                string showName = numberedPerms[permNo];
                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, numberedPerms[permNo])[0]) SetButtons(false);
                    List<string> inheritcheck = (List<string>)(PermsCheck(player, group, numberedPerms[permNo])[1]);
                    if (inheritcheck.Count > 0) {
                        if (path.inheritedcheck == numberedPerms[permNo]) {
                            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, FadeOut = 0.1f
                            }
                            , "Overlay", "PMConfirmUI");
                            elements1.Add(new CuiButton {
                                Button = {
                                    Command = $"ShowInherited {PlugNumber} null {numberedPerms[permNo]} {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 = $"{numberedPerms[permNo]}", 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 i = 0; i < inheritcheck.Count; i++) {
                                h1 = i * 0.022f;
                                h2 = i * 0.022f;
                                elements1.Add(new CuiLabel {
                                    Text = {
                                        Text = $"{inheritcheck[i]}", 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 {PlugNumber} null {numberedPerms[permNo]} {group} null {page} {numberedPerms[permNo]}", 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 {PlugNumber} grant {numberedPerms[permNo]} {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 {PlugNumber} revoke {numberedPerms[permNo]} {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 {PlugNumber} null null {group} null {next}", Color = config.ButtonColour
                }
                , RectTransform = {
                    AnchorMin = "0.8 0.02", AnchorMax = "0.9 0.04"
                }
                , Text = {
                    Text = "->", FontSize = 11, Align = TextAnchor.MiddleCenter
                }
            }
            , mainName);
            if (page > 1) elements.Add(new CuiButton {
                Button = {
                    Command = $"PermsList {PlugNumber} null null {group} null {previous}", Color = config.ButtonColour
                }
                , RectTransform = {
                    AnchorMin = "0.1 0.02", AnchorMax = "0.2 0.04"
                }
                , Text = {
                    Text = "<-", FontSize = 11, Align = TextAnchor.MiddleCenter
                }
            }
            , mainName);
            CuiHelper.AddUi(player, elements);
            if (list) CuiHelper.AddUi(player, elements1);
        }
        void ViewPlayersUI(BasePlayer player, string msg, int page) {
            var path = ActiveAdmins[player.userID];
            var outmsg = string.Format(lang.GetMessage("GUIPlayersIn", this), msg);
            string guiString = String.Format("0.1 0.1 0.1 {0}", config.guitransparency);
        
// ... [Code preview truncated due to length. Full source in attached file] ...

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

Другие ресурсы пользователя 15FPS

Сверху