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

FREE NWGPerms : 1.0.0 1.0.0

Нет прав для скачивания
C#:
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using Oxide.Core;
using Oxide.Core.Plugins;
using Oxide.Game.Rust.Cui;
using Newtonsoft.Json;
using UnityEngine;
namespace Oxide.Plugins {
    [Info("NWGPerms", "NWG Team", "1.0.0")]
    [Description("GUI-based permissions manager. Browse players, groups, and plugins to grant/revoke permissions visually.")]
    public class NWGPerms : RustPlugin {
#region Configuration
        private class PluginConfig {
            [JsonProperty("GUI Transparency (0-1)")]
            public double GuiTransparency = 0.95;
            [JsonProperty("Background Colour")]
            public string BgColour = "0.15 0.15 0.15 0.98";
            [JsonProperty("Header Colour")]
            public string HeaderColour = "0.1 0.1 0.1 1";
            [JsonProperty("Button Colour")]
            public string ButtonColour = "0.25 0.25 0.25 0.9";
            [JsonProperty("Button Hover Colour")]
            public string ButtonHoverColour = "0.35 0.55 0.25 1";
            [JsonProperty("Granted Colour (On)")]
            public string OnColour = "0.718 0.816 0.573 1";
            [JsonProperty("Revoked Colour (Off)")]
            public string OffColour = "0.851 0.325 0.31 1";
            [JsonProperty("Inherited Colour")]
            public string InheritedColour = "1 0.647 0 1";
            [JsonProperty("Accent Colour")]
            public string AccentColour = "1 0.647 0 1";
            [JsonProperty("Plugin BlockList (comma separated)")]
            public string BlockList = "";
            [JsonProperty("Grant All = Per Page Only")]
            public bool AllPerPage = false;
        }
        private PluginConfig _config;
#endregion
#region State
        private List<string> _plugList = new List<string>();
        private Dictionary<int, string> _numberedPerms = new Dictionary<int, string>();
        private HashSet<ulong> _menuOpen = new HashSet<ulong>();
        private Dictionary<ulong, AdminSession> _sessions = new Dictionary<ulong, AdminSession>();
        private string _btnOn, _btnOff;
        private class AdminSession {
            public string InheritedCheck = "";
            public int PluginPage = 1, PermPage = 1, PlayerPage = 1, GroupPage = 1;
            public string SubjectGroup;
            public BasePlayer Subject;
        }
        const string PERM_USE = "nwgperms.use";
#endregion
#region Data
        private StoredData _data;
        private class StoredData {
            public Dictionary<string, BackupEntry> Entries = new Dictionary<string, BackupEntry>();
        }
        private class BackupEntry {
            public List<string> Perms = new List<string>();
            public List<string> Players = new List<string>();
            public int IsPlayer;
            // 0=group, 1=player
        }
        void SaveStoredData() => Interface.Oxide.DataFileSystem.WriteObject("NWGPerms", _data);
#endregion
#region Lifecycle
        void Init() {
            permission.RegisterPermission(PERM_USE, this);
            LoadConfigVars();
            _data = Interface.Oxide.DataFileSystem.ReadObject<StoredData>("NWGPerms") ?? new StoredData();
        }
        void OnServerInitialized() {
            foreach (var p in BasePlayer.activePlayerList.Where(p => _menuOpen.Contains(p.userID))) CloseUI(p, true);
        }
        void Unload() {
            foreach (var p in BasePlayer.activePlayerList.Where(p => _menuOpen.Contains(p.userID))) CloseUI(p, true);
            SaveStoredData();
        }
        void OnPluginLoaded(Plugin p) {
            if (!(p is NWGPerms)) RefreshPlugList();
        }
        void OnPluginUnloaded(Plugin p) {
            if (!(p is NWGPerms)) RefreshPlugList();
        }
        void OnPlayerDisconnected(BasePlayer p, string r) {
            if (_menuOpen.Contains(p.userID)) CloseUI(p, true);
        }
        void LoadConfigVars() {
            try {
                _config = Config.ReadObject<PluginConfig>();
                if (_config == null) LoadDefaultConfig();
            }
            catch {
                LoadDefaultConfig();
            }
        }
        protected override void LoadDefaultConfig() {
            Puts("Creating new config for NWG Perms");
            _config = new PluginConfig();
            SaveConfig();
        }
        protected override void SaveConfig() => Config.WriteObject(_config);
#endregion
#region Helpers
        bool IsAllowed(BasePlayer p) => p?.net?.connection != null && (p.net.connection.authLevel == 2 || permission.UserHasPermission(p.UserIDString, PERM_USE));
        string Strip(string s) => s.Replace(@"\", "").Replace(@"/", "");
        string NoSpaces(string s) => s.Replace(" ", "-");
        string AddSpaces(string s) => s.Replace("-", " ");
        void SetButtons(bool granted) {
            _btnOn = granted ? _config.OffColour : _config.OnColour;
            _btnOff = granted ? _config.OnColour : _config.OffColour;
        }
        void RefreshPlugList() {
            _plugList.Clear();
            _numberedPerms.Clear();
            foreach (var plug in plugins.GetAll()) {
                if (plug.IsCorePlugin) continue;
                var name = plug.ToString().Replace("Oxide.Plugins.", "").ToLower();
                if (_config.BlockList.ToLower().Split(',').Contains(name)) continue;
                if (permission.GetPermissions().Any(perm => perm.ToLower().Contains($"{name}."))) if (!_plugList.Contains(name)) _plugList.Add(name);
            }
            _plugList.Sort();
        }
        AdminSession GetSession(BasePlayer p) {
            if (!_sessions.ContainsKey(p.userID)) _sessions[p.userID] = new AdminSession();
            return _sessions[p.userID];
        }
        object[] CheckPerm(BasePlayer admin, string group, string perm) {
            bool has = false;
            var inherited = new List<string>();
            var s = GetSession(admin);
            if (group == "true") has = permission.GroupHasPermission(s.SubjectGroup, perm);
            else {
                var ud = permission.GetUserData(s.Subject.UserIDString);
                has = ud.Perms.Contains(perm);
                foreach (var g in permission.GetUserGroups(s.Subject.UserIDString)) if (permission.GroupHasPermission(g, perm)) inherited.Add(g);
            }
            return new object[] {
                has, inherited
            }
            ;
        }
        BasePlayer FindPlayerById(ulong id) => BasePlayer.allPlayerList.FirstOrDefault(p => p.userID == id);
        BasePlayer FindPlayerByName(string name) => BasePlayer.allPlayerList.FirstOrDefault(p => p.displayName.Equals(name, StringComparison.OrdinalIgnoreCase) || p.displayName.Contains(name, CompareOptions.OrdinalIgnoreCase));
        void CloseUI(BasePlayer p, bool all) {
            CuiHelper.DestroyUi(p, "NWGPBg");
            CuiHelper.DestroyUi(p, "NWGPMain");
            CuiHelper.DestroyUi(p, "NWGPPerms");
            CuiHelper.DestroyUi(p, "NWGPConfirm");
            CuiHelper.DestroyUi(p, "NWGPData");
            CuiHelper.DestroyUi(p, "NWGPMsg");
            CuiHelper.DestroyUi(p, "NWGPDataConf");
            if (all) {
                CuiHelper.DestroyUi(p, "NWGPBg");
                _menuOpen.Remove(p.userID);
                _sessions.Remove(p.userID);
            }
        }
        void ShowMsg(BasePlayer p, string msg) {
            CuiHelper.DestroyUi(p, "NWGPMsg");
            timer.Once(1.5f, () => {
                if (p != null) CuiHelper.DestroyUi(p, "NWGPMsg");
            }
            );
            var e = new CuiElementContainer();
            var m = e.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", "NWGPMsg");
            e.Add(new CuiLabel {
                FadeOut = 0.5f, Text = {
                    FadeIn = 0.5f, Text = msg, FontSize = 28, Align = TextAnchor.MiddleCenter
                }
            }
            , m);
            CuiHelper.AddUi(p, e);
        }
#endregion
#region Chat Command
        [ChatCommand("perms")]
        void CmdPerms(BasePlayer player, string cmd, string[] args) {
            if (!IsAllowed(player)) {
                player.ChatMessage(GetMessage(Lang.NoPermission, player.UserIDString));
                return;
            }
            if (!_sessions.ContainsKey(player.userID)) _sessions[player.userID] = new AdminSession();
            var s = GetSession(player);
            RefreshPlugList();
            // /perms help
            if (args?.Length == 1 && args[0] == "help") {
                player.ChatMessage("<color=#55aaff>â•â•â• NWG Perms Help â•â•â•</color>\n" + "<color=#ffcc00>/perms</color> — Open player selector\n" + "<color=#ffcc00>/perms group</color> — Open group selector\n" + "<color=#ffcc00>/perms player <name|id></color> — Edit player permissions\n" + "<color=#ffcc00>/perms group <name></color> — Edit group permissions\n" + "<color=#ffcc00>/perms data</color> — Backup/restore/purge data\n" + "<color=#ffcc00>/perms help</color> — Show this help" );
                return;
            }
            // /perms data
            if (args?.Length == 1 && args[0] == "data") {
                DrawBg(player);
                DrawDataUI(player);
                return;
            }
            int page = args?.Length >= 3 ? Convert.ToInt32(args[2]) : 1;
            if (args == null || args.Length < 2) {
                bool group = args?.Length == 1 && args[0] == "group";
                if (_menuOpen.Contains(player.userID)) CloseUI(player, true);
                _sessions[player.userID] = new AdminSession();
                DrawBg(player);
                DrawMainUI(player, group, 1);
                return;
            }
            if (args[0] == "player") {
                ulong n;
                bool num = ulong.TryParse(args[1], out n);
                s.Subject = num ? FindPlayerById(n) : FindPlayerByName(args[1]);
                if (s.Subject == null) {
                    ShowMsg(player, GetMessage(Lang.MsgNoPlayer, player.UserIDString));
                    return;
                }
                if (_menuOpen.Contains(player.userID)) CloseUI(player, true);
                DrawBg(player);
                DrawPluginsUI(player, $"Permissions for {Strip(s.Subject.displayName)}", "false", page);
            }
            else if (args[0] == "group") {
                if (!permission.GetGroups().Contains(args[1])) {
                    ShowMsg(player, GetMessage(Lang.MsgNoGroup, player.UserIDString));
                    return;
                }
                s.SubjectGroup = args[1];
                if (_menuOpen.Contains(player.userID)) CloseUI(player, true);
                DrawBg(player);
                DrawPluginsUI(player, $"Permissions for {args[1]}", "true", page);
            }
            else player.ChatMessage("<color=#ffcc00>[NWG Perms]</color> /perms, /perms player <name>, /perms group <name>, /perms data, /perms help");
        }
#endregion
#region UI Drawing
        void DrawBg(BasePlayer p) {
            _menuOpen.Add(p.userID);
            var e = new CuiElementContainer();
            var bg = e.Add(new CuiPanel {
                Image = {
                    Color = $"{_config.BgColour.Substring(0, _config.BgColour.LastIndexOf(' '))} {_config.GuiTransparency}"
                }
                , RectTransform = {
                    AnchorMin = "0.3 0.1", AnchorMax = "0.7 0.9"
                }
                , CursorEnabled = true, FadeOut = 0.1f
            }
            , "Overlay", "NWGPBg");
            // Header bar
            e.Add(new CuiPanel {
                Image = {
                    Color = _config.HeaderColour
                }
                , RectTransform = {
                    AnchorMin = "0 0.95", AnchorMax = "1 1"
                }
            }
            , bg);
            // Footer bar
            e.Add(new CuiPanel {
                Image = {
                    Color = _config.HeaderColour
                }
                , RectTransform = {
                    AnchorMin = "0 0", AnchorMax = "1 0.05"
                }
            }
            , bg);
            // Close button with accent color
            e.Add(new CuiButton {
                Button = {
                    Command = "nwgp.close", Color = _config.OffColour
                }
                , RectTransform = {
                    AnchorMin = "0.955 0.96", AnchorMax = "0.99 0.995"
                }
                , Text = {
                    Text = "✖", FontSize = 12, Align = TextAnchor.MiddleCenter
                }
            }
            , bg);
            CuiHelper.AddUi(p, e);
        }
        void DrawMainUI(BasePlayer p, bool group, int page) {
            var e = new CuiElementContainer();
            var m = e.Add(new CuiPanel {
                Image = {
                    Color = "0 0 0 0"
                }
                , RectTransform = {
                    AnchorMin = "0.32 0.1", AnchorMax = "0.68 0.9"
                }
                , CursorEnabled = true
            }
            , "Overlay", "NWGPMain");
            string switchLabel = group ? "Players" : "Groups";
            string currentLabel = !group ? "Players" : "Groups";
            // Title with accent color
            e.Add(new CuiLabel {
                Text = {
                    Text = GetMessage(Lang.Title, p.UserIDString), FontSize = 14, Align = TextAnchor.MiddleCenter, Color = "1 1 1 1"
                }
                , RectTransform = {
                    AnchorMin = "0 0.96", AnchorMax = "1 0.995"
                }
            }
            , m);
            // Switch button with accent color
            e.Add(new CuiButton {
                Button = {
                    Command = $"nwgp.toggle {group} 1", Color = _config.AccentColour
                }
                , RectTransform = {
                    AnchorMin = "0.35 0.015", AnchorMax = "0.65 0.045"
                }
                , Text = {
                    Text = group ? GetMessage(Lang.ViewPlayers, p.UserIDString) : GetMessage(Lang.ViewGroups, p.UserIDString), FontSize = 12, Align = TextAnchor.MiddleCenter
                }
            }
            , m);
            // Section header
            e.Add(new CuiPanel {
                Image = {
                    Color = _config.HeaderColour
                }
                , RectTransform = {
                    AnchorMin = "0 0.89", AnchorMax = "1 0.94"
                }
            }
            , m);
            e.Add(new CuiLabel {
                Text = {
                    Text = !group ? GetMessage(Lang.AllPlayers, p.UserIDString) : GetMessage(Lang.AllGroups, p.UserIDString), FontSize = 13, Align = TextAnchor.MiddleCenter, Color = "0.8 0.8 0.8 1"
                }
                , RectTransform = {
                    AnchorMin = "0 0.89", AnchorMax = "1 0.94"
                }
            }
            , m);
            int pos = 20 - (page * 20), count = 0;
            float top = 0.865f, bot = 0.84f;
            if (group) {
                foreach (var g in permission.GetGroups().OrderBy(x => x)) {
                    pos++;
                    count++;
                    if (pos > 0 && pos < 21) {
                        e.Add(new CuiButton {
                            Button = {
                                Command = $"nwgp.select group {g}", Color = _config.ButtonColour
                            }
                            , RectTransform = {
                                AnchorMin = $"0.25 {bot}", AnchorMax = $"0.75 {top}"
                            }
                            , Text = {
                                Text = g, FontSize = 11, Align = TextAnchor.MiddleCenter
                            }
                        }
                        , m);
                        top -= 0.027f;
                        bot -= 0.027f;
                    }
                }
            }
            else {
                foreach (var pl in BasePlayer.allPlayerList.OrderBy(x => x.displayName).ThenBy(x => x?.net?.connection == null)) {
                    pos++;
                    count++;
                    if (pos > 0 && pos < 21) {
                        string color = pl?.net?.connection == null ? "0.7 0.7 0.7 1" : "0.4 1 0.4 1";
                        e.Add(new CuiButton {
                            Button = {
                                Command = $"nwgp.select player {pl.userID}", Color = _config.ButtonColour
                            }
                            , RectTransform = {
                                AnchorMin = $"0.25 {bot}", AnchorMax = $"0.75 {top}"
                            }
                            , Text = {
                                Text = Strip(pl.displayName), FontSize = 11, Align = TextAnchor.MiddleCenter, Color = color
                            }
                        }
                        , m);
                        top -= 0.027f;
                        bot -= 0.027f;
                    }
                }
            }
            if (count > page * 20) e.Add(new CuiButton {
                Button = {
                    Command = $"nwgp.toggle {group} {page + 1}", Color = _config.ButtonColour
                }
                , RectTransform = {
                    AnchorMin = "0.8 0.015", AnchorMax = "0.9 0.045"
                }
                , Text = {
                    Text = "→", FontSize = 14, Align = TextAnchor.MiddleCenter
                }
            }
            , m);
            if (page > 1) e.Add(new CuiButton {
                Button = {
                    Command = $"nwgp.toggle {group} {page - 1}", Color = _config.ButtonColour
                }
                , RectTransform = {
                    AnchorMin = "0.1 0.015", AnchorMax = "0.2 0.045"
                }
                , Text = {
                    Text = "â†", FontSize = 14, Align = TextAnchor.MiddleCenter
                }
            }
            , m);
            CuiHelper.AddUi(p, e);
        }
        void DrawPluginsUI(BasePlayer p, string title, string group, int page) {
            var s = GetSession(p);
            var backPage = group == "false" ? s.PlayerPage : s.GroupPage;
            string toggle = group == "true" ? "false" : "true";
            var e = new CuiElementContainer();
            var m = e.Add(new CuiPanel {
                Image = {
                    Color = "0 0 0 0"
                }
                , RectTransform = {
                    AnchorMin = "0.32 0.1", AnchorMax = "0.68 0.9"
                }
                , CursorEnabled = true
            }
            , "Overlay", "NWGPPerms");
            int total = 0, pos = 60 - (page * 60);
            for (int i = 0; i < _plugList.Count; i++) {
                pos++;
                total++;
                float yOff(int p2) => 0.89f - (p2 * 3f) / 100f;
                float yOff2(int p2) => 0.91f - (p2 * 3f) / 100f;
                if (pos > 0 && pos < 21) e.Add(new CuiButton {
                    Button = {
                        Command = $"nwgp.permslist {i} null null {group} null 1", Color = _config.ButtonColour
                    }
                    , RectTransform = {
                        AnchorMin = $"0.1 {yOff(pos)}", AnchorMax = $"0.3 {yOff2(pos)}"
                    }
                    , Text = {
                        Text = _plugList[i], FontSize = 10, Align = TextAnchor.MiddleCenter
                    }
                }
                , m);
                else if (pos > 20 && pos < 41) e.Add(new CuiButton {
                    Button = {
                        Command = $"nwgp.permslist {i} null null {group} null 1", Color = _config.ButtonColour
                    }
                    , RectTransform = {
                        AnchorMin = $"0.4 {yOff(pos - 20)}", AnchorMax = $"0.6 {yOff2(pos - 20)}"
                    }
                    , Text = {
                        Text = _plugList[i], FontSize = 10, Align = TextAnchor.MiddleCenter
                    }
                }
                , m);
                else if (pos > 40 && pos < 61) e.Add(new CuiButton {
                    Button = {
                        Command = $"nwgp.permslist {i} null null {group} null 1", Color = _config.ButtonColour
                    }
                    , RectTransform = {
                        AnchorMin = $"0.7 {yOff(pos - 40)}", AnchorMax = $"0.9 {yOff2(pos - 40)}"
                    }
                    , Text = {
                        Text = _plugList[i], FontSize = 10, Align = TextAnchor.MiddleCenter
                    }
                }
                , m);
            }
            e.Add(new CuiButton {
                Button = {
                    Command = $"nwgp.toggle {toggle} {backPage}", Color = _config.ButtonColour
                }
                , RectTransform = {
                    AnchorMin = "0.55 0.02", AnchorMax = "0.75 0.04"
                }
                , Text = {
                    Text = GetMessage(Lang.Back, p.UserIDString), FontSize = 11, Align = TextAnchor.MiddleCenter
                }
            }
            , m);
            e.Add(new CuiLabel {
                Text = {
                    Text = title, FontSize = 16, Align = TextAnchor.MiddleCenter
                }
                , RectTransform = {
                    AnchorMin = "0 0.95", AnchorMax = "1 1"
                }
            }
            , m);
            if (group == "false") {
                e.Add(new CuiButton {
                    Button = {
                        Command = "nwgp.revokeall", Color = _config.ButtonColour
                    }
                    , RectTransform = {
                        AnchorMin = "0.4 0.1", AnchorMax = "0.6 0.14"
                    }
                    , Text = {
                        Text = GetMessage(Lang.RevokeAll, p.UserIDString), FontSize = 11, Align = TextAnchor.MiddleCenter
                    }
                }
                , m);
                e.Add(new CuiButton {
                    Button = {
                        Command = "nwgp.groups 1", Color = _config.ButtonColour
                    }
                    , RectTransform = {
                        AnchorMin = "0.25 0.02", AnchorMax = "0.45 0.04"
                    }
                    , Text = {
                        Text = GetMessage(Lang.Groups, p.UserIDString), FontSize = 11, Align = TextAnchor.MiddleCenter
                    }
                }
                , m);
            }
            else e.Add(new CuiButton {
                Button = {
                    Command = "nwgp.playersin 1", Color = _config.ButtonColour
                }
                , RectTransform = {
                    AnchorMin = "0.25 0.02", AnchorMax = "0.45 0.04"
                }
                , Text = {
                    Text = GetMessage(Lang.Players, p.UserIDString), FontSize = 11, Align = TextAnchor.MiddleCenter
                }
            }
            , m);
            if (total > page * 60) e.Add(new CuiButton {
                Button = {
                    Command = $"nwgp.nav {group} {page + 1}", Color = _config.ButtonColour
                }
                , RectTransform = {
                    AnchorMin = "0.8 0.02", AnchorMax = "0.9 0.04"
                }
                , Text = {
                    Text = "->", FontSize = 11, Align = TextAnchor.MiddleCenter
                }
            }
            , m);
            if (page > 1) e.Add(new CuiButton {
                Button = {
                    Command = $"nwgp.nav {group} {page - 1}", Color = _config.ButtonColour
                }
                , RectTransform = {
                    AnchorMin = "0.1 0.02", AnchorMax = "0.2 0.04"
                }
                , Text = {
                    Text = "<-", FontSize = 11, Align = TextAnchor.MiddleCenter
                }
            }
            , m);
            CuiHelper.AddUi(p, e);
        }
        void DrawPermsUI(BasePlayer p, string title, int plugNum, string group, int page) {
            var s = GetSession(p);
            var e = new CuiElementContainer();
            var m = e.Add(new CuiPanel {
                Image = {
                    Color = "0 0 0 0"
                }
                , RectTransform = {
                    AnchorMin = "0.32 0.1", AnchorMax = "0.68 0.9"
                }
                , CursorEnabled = true
            }
            , "Overlay", "NWGPPerms");
            int total = 0, pos = 20 - (page * 20);
            // Grant/Revoke All buttons
            e.Add(new CuiButton {
                Button = {
                    Command = $"nwgp.permslist {plugNum} grant null {group} all {page}", Color = _config.ButtonColour
                }
                , RectTransform = {
                    AnchorMin = $"0.5 {0.89f - (pos * 3f) / 100f}", AnchorMax = $"0.6 {0.91f - (pos * 3f) / 100f}"
                }
                , Text = {
                    Text = GetMessage(Lang.GrantAll, p.UserIDString), FontSize = 10, Align = TextAnchor.MiddleCenter
                }
            }
            , m);
            e.Add(new CuiButton {
                Button = {
                    Command = $"nwgp.permslist {plugNum} revoke null {group} all {page}", Color = _config.ButtonColour
                }
                , RectTransform = {
                    AnchorMin = $"0.65 {0.89f - (pos * 3f) / 100f}", AnchorMax = $"0.75 {0.91f - (pos * 3f) / 100f}"
                }
                , Text = {
                    Text = GetMessage(Lang.RevokeAll, p.UserIDString), FontSize = 10, Align = TextAnchor.MiddleCenter
                }
            }
            , m);
            foreach (var perm in _numberedPerms) {
                SetButtons(true);
                pos++;
                total++;
                if (pos < 1 || pos > 20) continue;
                float y1 = 0.89f - (pos * 3f) / 100f, y2 = 0.91f - (pos * 3f) / 100f;
                string output = perm.Value.Substring(perm.Value.IndexOf('.') + 1);
                var check = CheckPerm(p, group, perm.Value);
                if ((bool)check[0]) SetButtons(false);
                var inherited = (List<string>)check[1];
                if (inherited.Count > 0) e.Add(new CuiButton {
                    Button = {
                        Command = $"nwgp.inherited {plugNum} {perm.Value} {group} {page} {perm.Value}", Color = _config.InheritedColour
                    }
                    , RectTransform = {
                        AnchorMin = $"0.8 {y1}", AnchorMax = $"0.9 {y2}"
                    }
                    , Text = {
                        Text = GetMessage(Lang.Inherited, p.UserIDString), FontSize = 10, Align = TextAnchor.MiddleCenter
                    }
                }
                , m);
                e.Add(new CuiButton {
                    Button = {
                        Color = _config.ButtonColour
                    }
                    , RectTransform = {
                        AnchorMin = $"0.1 {y1}", AnchorMax = $"0.45 {y2}"
                    }
                    , Text = {
                        Text = output, FontSize = 10, Align = TextAnchor.MiddleCenter
                    }
                }
                , m);
                e.Add(new CuiButton {
                    Button = {
                        Command = $"nwgp.permslist {plugNum} grant {perm.Value} {group} null {page}", Color = _btnOn
                    }
                    , RectTransform = {
                        AnchorMin = $"0.5 {y1}", AnchorMax = $"0.6 {y2}"
                    }
                    , Text = {
                        Text = GetMessage(Lang.Granted, p.UserIDString), FontSize = 10, Align = TextAnchor.MiddleCenter
                    }
                }
                , m);
                e.Add(new CuiButton {
                    Button = {
                        Command = $"nwgp.permslist {plugNum} revoke {perm.Value} {group} null {page}", Color = _btnOff
                    }
                    , RectTransform = {
                        AnchorMin = $"0.65 {y1}", AnchorMax = $"0.75 {y2}"
                    }
                    , Text = {
                        Text = GetMessage(Lang.Revoked, p.UserIDString), FontSize = 10, Align = TextAnchor.MiddleCenter
                    }
                }
                , m);
            }
            e.Add(new CuiButton {
                Button = {
                    Command = $"nwgp.nav {group} {s.PluginPage}", Color = _config.ButtonColour
                }
                , RectTransform = {
                    AnchorMin = "0.4 0.02", AnchorMax = "0.6 0.04"
                }
                , Text = {
                    Text = GetMessage(Lang.Back, p.UserIDString), FontSize = 11, Align = TextAnchor.MiddleCenter
                }
            }
            , m);
            e.Add(new CuiLabel {
                Text = {
                    Text = title, FontSize = 16, Align = TextAnchor.MiddleCenter
                }
                , RectTransform = {
                    AnchorMin = "0 0.95", AnchorMax = "1 1"
                }
            }
            , m);
            if (total > page * 20) e.Add(new CuiButton {
                Button = {
                    Command = $"nwgp.permslist {plugNum} null null {group} null {page + 1}", Color = _config.ButtonColour
                }
                , RectTransform = {
                    AnchorMin = "0.8 0.02", AnchorMax = "0.9 0.04"
                }
                , Text = {
                    Text = "->", FontSize = 11, Align = TextAnchor.MiddleCenter
                }
            }
            , m);
            if (page > 1) e.Add(new CuiButton {
                Button = {
                    Command = $"nwgp.permslist {plugNum} null null {group} null {page - 1}", Color = _config.ButtonColour
                }
                , RectTransform = {
                    AnchorMin = "0.1 0.02", AnchorMax = "0.2 0.04"
                }
                , Text = {
                    Text = "<-", FontSize = 11, Align = TextAnchor.MiddleCenter
                }
            }
            , m);
            CuiHelper.AddUi(p, e);
        }
        void DrawGroupsForPlayerUI(BasePlayer p, string title, int page) {
            var s = GetSession(p);
            var e = new CuiElementContainer();
            var m = e.Add(new CuiPanel {
                Image = {
                    Color = "0 0 0 0"
                }
                , RectTransform = {
                    AnchorMin = "0.32 0.1", AnchorMax = "0.68 0.9"
                }
                , CursorEnabled = true
            }
            , "Overlay", "NWGPPerms");
            int total = 0, pos = 20 - (page * 20);
            foreach (var g in permission.GetGroups().OrderBy(x => x)) {
                SetButtons(true);
                pos++;
                total++;
                if (pos < 1 || pos > 20) continue;
                float y1 = 0.89f - (pos * 3f) / 100f, y2 = 0.91f - (pos * 3f) / 100f;
                foreach (var u in permission.GetUsersInGroup(g)) if (u.Contains(s.Subject.UserIDString)) {
                    SetButtons(false);
                    break;
                }
                e.Add(new CuiButton {
                    Button = {
                        Color = _config.ButtonColour
                    }
                    , RectTransform = {
                        AnchorMin = $"0.2 {y1}", AnchorMax = $"0.5 {y2}"
                    }
                    , Text = {
                        Text = g, FontSize = 10, Align = TextAnchor.MiddleCenter
                    }
                }
                , m);
                e.Add(new CuiButton {
                    Button = {
                        Command = $"nwgp.groupmod add {NoSpaces(g)} {page}", Color = _btnOn
                    }
                    , RectTransform = {
                        AnchorMin = $"0.55 {y1}", AnchorMax = $"0.65 {y2}"
                    }
                    , Text = {
                        Text = GetMessage(Lang.Granted, p.UserIDString), FontSize = 10, Align = TextAnchor.MiddleCenter
                    }
                }
                , m);
                e.Add(new CuiButton {
                    Button = {
                        Command = $"nwgp.groupmod remove {NoSpaces(g)} {page}", Color = _btnOff
                    }
                    , RectTransform = {
                        AnchorMin = $"0.7 {y1}", AnchorMax = $"0.8 {y2}"
                    }
                    , Text = {
                        Text = GetMessage(Lang.Revoked, p.UserIDString), FontSize = 10, Align = TextAnchor.MiddleCenter
                    }
                }
                , m);
            }
            e.Add(new CuiButton {
                Button = {
                    Command = $"nwgp.removeallgroups {page}", Color = _config.ButtonColour
                }
                , RectTransform = {
                    AnchorMin = "0.4 0.1", AnchorMax = "0.6 0.14"
                }
                , Text = {
                    Text = GetMessage(Lang.RemoveFromAll, p.UserIDString), FontSize = 11, Align = TextAnchor.MiddleCenter
                }
            }
            , m);
            e.Add(new CuiButton {
                Button = {
                    Command = $"nwgp.nav false {s.PluginPage}", Color = _config.ButtonColour
                }
                , RectTransform = {
                    AnchorMin = "0.4 0.02", AnchorMax = "0.6 0.04"
                }
                , Text = {
                    Text = GetMessage(Lang.Back, p.UserIDString), FontSize = 11, Align = TextAnchor.MiddleCenter
                }
            }
            , m);
            e.Add(new CuiLabel {
                Text = {
                    Text = GetMessage(Lang.GroupsFor, p.UserIDString, title), FontSize = 16, Align = TextAnchor.MiddleCenter
                }
                , RectTransform = {
                    AnchorMin = "0 0.95", AnchorMax = "1 1"
                }
            }
            , m);
            if (total > page * 20) e.Add(new CuiButton {
                Button = {
                    Command = $"nwgp.groups {page + 1}", Color = _config.ButtonColour
                }
                , RectTransform = {
                    AnchorMin = "0.7 0.02", AnchorMax = "0.8 0.04"
                }
                , Text = {
                    Text = "->", FontSize = 11, Align = TextAnchor.MiddleCenter
                }
            }
            , m);
            if (page > 1) e.Add(new CuiButton {
                Button = {
                    Command = $"nwgp.groups {page - 1}", Color = _config.ButtonColour
                }
                , RectTransform = {
                    AnchorMin = "0.2 0.02", AnchorMax = "0.3 0.04"
                }
                , Text = {
                    Text = "<-", FontSize = 11, Align = TextAnchor.MiddleCenter
                }
            }
            , m);
            CuiHelper.AddUi(p, e);
        }
        void DrawPlayersInGroupUI(BasePlayer p, string groupName, int page) {
            var e = new CuiElementContainer();
            var m = e.Add(new CuiPanel {
                Image = {
                    Color = "0 0 0 0"
                }
                , RectTransform = {
                    AnchorMin = "0.32 0.1", AnchorMax = "0.68 0.9"
                }
                , CursorEnabled = true
            }
            , "Overlay", "NWGPPerms");
            int total = 0, pos = 20 - (page * 20);
            foreach (var u in permission.GetUsersInGroup(groupName)) {
                pos++;
                total++;
                if (pos > 0 && pos < 21) {
                    float y1 = 0.89f - (pos * 3f) / 100f, y2 = 0.91f - (pos * 3f) / 100f;
                    e.Add(new CuiButton {
                        Button = {
                            Color = _config.ButtonColour
                        }
                        , RectTransform = {
                            AnchorMin = $"0.2 {y1}", AnchorMax = $"0.8 {y2}"
                        }
                        , Text = {
                            Text = u, FontSize = 10, Align = TextAnchor.MiddleCenter
                        }
                    }
                    , m);
                }
            }
            e.Add(new CuiLabel {
                Text = {
                    Text = GetMessage(Lang.PlayersIn, p.UserIDString, groupName), FontSize = 16, Align = TextAnchor.MiddleCenter
                }
                , RectTransform = {
                    AnchorMin = "0 0.95", AnchorMax = "1 1"
                }
            }
            , m);
            e.Add(new CuiButton {
                Button = {
                    Command = "nwgp.emptygroup", Color = _config.ButtonColour
                }
                , RectTransform = {
                    AnchorMin = "0.25 0.02", AnchorMax = "0.45 0.04"
                }
                , Text = {
                    Text = GetMessage(Lang.RemoveAllPlayers, p.UserIDString), FontSize = 11, Align = TextAnchor.MiddleCenter
                }
            }
            , m);
            var s = GetSession(p);
            e.Add(new CuiButton {
                Button = {
                    Command = $"nwgp.nav true {s.PlayerPage}", Color = _config.ButtonColour
                }
                , RectTransform = {
                    AnchorMin = "0.55 0.02", AnchorMax = "0.75 0.04"
                }
                , Text = {
                    Text = GetMessage(Lang.Back, p.UserIDString), FontSize = 11, Align = TextAnchor.MiddleCenter
                }
            }
            , m);
            CuiHelper.AddUi(p, e);
        }
        void DrawDataUI(BasePlayer p) {
            var e = new CuiElementContainer();
            var m = e.Add(new CuiPanel {
                Image = {
                    Color = "0 0 0 0"
                }
                , RectTransform = {
                    AnchorMin = "0.32 0.1", AnchorMax = "0.68 0.9"
                }
                , CursorEnabled = true
            }
            , "Overlay", "NWGPData");
            e.Add(new CuiLabel {
                Text = {
                    Text = GetMessage(Lang.DataTitle, p.UserIDString), FontSize = 14, Align = TextAnchor.MiddleCenter, Color = "1 1 1 1"
                }
                , RectTransform = {
                    AnchorMin = "0 0.96", AnchorMax = "1 0.995"
                }
            }
            , m);
            // Local Backup Section
            e.Add(new CuiPanel {
                Image = {
                    Color = _config.HeaderColour
                }
                , RectTransform = {
                    AnchorMin = "0.05 0.84", AnchorMax = "0.95 0.87"
                }
            }
            , m);
            e.Add(new CuiLabel {
                Text = {
                    Text = GetMessage(Lang.LocalBackup, p.UserIDString), FontSize = 12, Align = TextAnchor.MiddleCenter, Color = "0.8 0.8 0.8 1"
                }
                , RectTransform = {
                    AnchorMin = "0.05 0.84", AnchorMax = "0.95 0.87"
                }
            }
            , m);
            e.Add(new CuiLabel {
                Text = {
                    Text = GetMessage(Lang.Save, p.UserIDString), FontSize = 11, Align = TextAnchor.MiddleRight
                }
                , RectTransform = {
                    AnchorMin = "0.05 0.8", AnchorMax = "0.25 0.83"
                }
            }
            , m);
            e.Add(new CuiButton {
                Button = {
                    Command = "nwgp.data 0", Color = _config.OnColour
                }
                , RectTransform = {
                    AnchorMin = "0.3 0.8", AnchorMax = "0.47 0.83"
                }
                , Text = {
                    Text = GetMessage(Lang.Groups, p.UserIDString), FontSize = 10, Align = TextAnchor.MiddleCenter
                }
            }
            , m);
            e.Add(new CuiButton {
                Button = {
                    Command = "nwgp.data 1", Color = _config.OnColour
                }
                , RectTransform = {
                    AnchorMin = "0.53 0.8", AnchorMax = "0.7 0.83"
                }
                , Text = {
                    Text = GetMessage(Lang.Players, p.UserIDString), FontSize = 10, Align = TextAnchor.MiddleCenter
                }
            }
            , m);
            e.Add(new CuiLabel {
                Text = {
                    Text = GetMessage(Lang.Load, p.UserIDString), FontSize = 11, Align = TextAnchor.MiddleRight
                }
                , RectTransform = {
                    AnchorMin = "0.05 0.76", AnchorMax = "0.25 0.79"
                }
            }
            , m);
            e.Add(new CuiButton {
                Button = {
                    Command = "nwgp.data 2", Color = _config.AccentColour
                }
                , RectTransform = {
                    AnchorMin = "0.3 0.76", AnchorMax = "0.47 0.79"
                }
                , Text = {
                    Text = GetMessage(Lang.Groups, p.UserIDString), FontSize = 10, Align = TextAnchor.MiddleCenter
                }
            }
            , m);
            e.Add(new CuiButton {
                Button = {
                    Command = "nwgp.data 3", Color = _config.AccentColour
                }
                , RectTransform = {
                    AnchorMin = "0.53 0.76", AnchorMax = "0.7 0.79"
                }
                , Text = {
                    Text = GetMessage(Lang.Players, p.UserIDString), FontSize = 10, Align = TextAnchor.MiddleCenter
                }
            }
            , m);
            e.Add(new CuiButton {
                Button = {
                    Command = "nwgp.data 4", Color = _config.OffColour
                }
                , RectTransform = {
                    AnchorMin = "0.3 0.72", AnchorMax = "0.7 0.75"
                }
                , Text = {
                    Text = GetMessage(Lang.WipeBackup, p.UserIDString), FontSize = 10, Align = TextAnchor.MiddleCenter
                }
            }
            , m);
            // Purge Section
            e.Add(new CuiPanel {
                Image = {
                    Color = _config.HeaderColour
                }
                , RectTransform = {
                    AnchorMin = "0.05 0.64", AnchorMax = "0.95 0.67"
                }
            }
            , m);
            e.Add(new CuiLabel {
                Text = {
                    Text = GetMessage(Lang.PurgeTitle, p.UserIDString), FontSize = 12, Align = TextAnchor.MiddleCenter, Color = "0.8 0.8 0.8 1"
                }
                , RectTransform = {
                    AnchorMin = "0.05 0.64", AnchorMax = "0.95 0.67"
                }
            }
            , m);
            e.Add(new CuiButton {
                Button = {
                    Command = "nwgp.data 5", Color = _config.ButtonColour
                }
                , RectTransform = {
                    AnchorMin = "0.25 0.6", AnchorMax = "0.75 0.63"
                }
                , Text = {
                    Text = GetMessage(Lang.PurgeGroups, p.UserIDString), FontSize = 10, Align = TextAnchor.MiddleCenter
                }
            }
            , m);
            e.Add(new CuiButton {
                Button = {
                    Command = "nwgp.data 6", Color = _config.ButtonColour
                }
                , RectTransform = {
                    AnchorMin = "0.25 0.56", AnchorMax = "0.75 0.59"
                }
                , Text = {
                    Text = GetMessage(Lang.PurgePlayers, p.UserIDString), FontSize = 10, Align = TextAnchor.MiddleCenter
                }
            }
            , m);
            // Global Remove Section
            e.Add(new CuiPanel {
                Image = {
                    Color = _config.HeaderColour
                }
                , RectTransform = {
                    AnchorMin = "0.05 0.48", AnchorMax = "0.95 0.51"
                }
            }
            , m);
            e.Add(new CuiLabel {
                Text = {
                    Text = GetMessage(Lang.GlobalRemove, p.UserIDString), FontSize = 12, Align = TextAnchor.MiddleCenter, Color = "1 0.4 0.4 1"
                }
                , RectTransform = {
                    AnchorMin = "0.05 0.48", AnchorMax = "0.95 0.51"
                }
            }
            , m);
            e.Add(new CuiButton {
                Button = {
                    Command = "nwgp.data 7", Color = _config.OffColour
                }
                , RectTransform = {
                    AnchorMin = "0.25 0.44", AnchorMax = "0.75 0.47"
                }
                , Text = {
                    Text = GetMessage(Lang.EmptyAllGroups, p.UserIDString), FontSize = 10, Align = TextAnchor.MiddleCenter
                }
            }
            , m);
            e.Add(new CuiButton {
                Button = {
                    Command = "nwgp.data 8", Color = _config.OffColour
                }
                , RectTransform = {
                    AnchorMin = "0.25 0.4", AnchorMax = "0.75 0.43"
                }
                , Text = {
                    Text = GetMessage(Lang.DeleteAllGroups, p.UserIDString), FontSize = 10, Align = TextAnchor.MiddleCenter
                }
            }
            , m);
            e.Add(new CuiButton {
                Button = {
                    Command = "nwgp.data 9", Color = _config.OffColour
                }
                , RectTransform = {
                    AnchorMin = "0.25 0.36", AnchorMax = "0.75 0.39"
                }
                , Text = {
                    Text = GetMessage(Lang.WipePlayerPerms, p.UserIDString), FontSize = 10, Align = TextAnchor.MiddleCenter
                }
            }
            , m);
            CuiHelper.AddUi(p, e);
        }
#endregion
#region Console Commands
        [ConsoleCommand("nwgp.close")]
        void CCClose(ConsoleSystem.Arg a) {
            var p = a.Player();
            if (p != null) CloseUI(p, true);
        }
        [ConsoleCommand("nwgp.toggle")]
        void CCToggle(ConsoleSystem.Arg a) {
            var p = a.Player();
            if (p == null || !IsAllowed(p) || a.Args?.Length < 2) return;
            bool grou
// ... [Code preview truncated due to length. Full source in attached file] ...

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