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

FREE VipRemainInfo : 2.0 2.0

Нет прав для скачивания
C#:
// Все права принадлежат дискорд сообществу https://discord.gg/VgNHPpNrz6
using System;
using System.Linq;
using System.Collections.Generic;
using Oxide.Core.Plugins;
using Newtonsoft.Json;
using Oxide.Game.Rust.Cui;
using UnityEngine;
namespace Oxide.Plugins {
    [Info("VipRemainInfo", "anfunny", "2.0")]
    class VipRemainInfo : RustPlugin {
        [PluginReference]
        private Plugin Grant, ImageLibrary, MenuSystem;
        private Dictionary<ulong, bool> ShowedVipInfo = new Dictionary<ulong, bool>();
        public string Layer = "VipRemainInfo_UI";
        private void Init() {
            LoadConfigVariables();
            LoadDefaultMessages();
            if (configData.ShowDelay < 0f) {
                Unsubscribe(nameof(OnPlayerConnected));
                Unsubscribe(nameof(OnPlayerSleepEnded));
            }
        }
        private void OnServerInitialized() {
            if (Grant == null) PrintWarning("Не найден плагин 'Grant'.Работа плагина невозможна !");
        }
        private void OnPlayerConnected(BasePlayer player) {
            if (player == null) return;
            if (!ShowedVipInfo.ContainsKey(player.userID)) ShowedVipInfo.Add(player.userID, false);
            else ShowedVipInfo[player.userID] = false;
        }
        private void OnPlayerSleepEnded(BasePlayer player) {
            if (player == null) return;
            if (!ShowedVipInfo.ContainsKey(player.userID)) return;
            if (!ShowedVipInfo[player.userID]) timer.Once(configData.ShowDelay, () => ShowRemainVipInfo(player));
        }
        [ChatCommand("timedonate")]
        private void cmdVipInfo(BasePlayer player, string command, string[] args) {
            if (player == null) return;
            MenuSystem?.Call("MS_CustomCMD", player, "profile", true);
        }
        private void ShowRemainVipInfo(BasePlayer player, bool isSilent = true, int Page = 0) {
            if (Grant == null) return;
            var result = "";
            var showHead = false;
            var color = "";
            int i = 0;
            var groupInfo = (Dictionary<string, int>)(Grant.CallHook("GetGroups", player.userID));
            var privsInfo = (Dictionary<string, int>)(Grant.CallHook("GetPermissions", player.userID));
            bool Check_PrivsGroups = (privsInfo != null && groupInfo != null) ? true : false;
            CuiHelper.DestroyUi(player, Layer);
            if(isSilent == false) {
                var container = new CuiElementContainer();
                container.Add(new CuiElement {
                    Parent = "ProfileMenu_UI", Name = Layer, Components = {
                        new CuiImageComponent {
                            Color = "0 0 0 0"
                        }
                        , new CuiRectTransformComponent {
                            AnchorMin = "0 0.480", AnchorMax = "0 0.9025", OffsetMin = "50 0", OffsetMax = "400 0"
                        }
                    }
                }
                );
                container.Add(new CuiElement {
                    Name = "Background", Parent = Layer, Components = {
                        new CuiRawImageComponent {
                            Png = (string) ImageLibrary.Call("GetImage", "BgrndPrivileges"), Color = "1 1 1 0.75"
                        }
                        , new CuiRectTransformComponent {
                            AnchorMin = "0 0", AnchorMax = "1 1"
                        }
                    }
                }
                );
                if (Check_PrivsGroups) {
                    if (groupInfo != null && privsInfo != null) {
                        foreach(var info in groupInfo.Union(privsInfo).Skip(Page * 4)) {
                            string privs = "";
                            var name = info.Key;
                            if (configData.GroupsNewName.ContainsKey(info.Key)) name = configData.GroupsNewName[info.Key];
                            if (configData.GroupsColor.TryGetValue(info.Key, out color)) privs = string.Format(lang.GetMessage("VRI.PRIV_TEXT", this, player.UserIDString), color, name, GetTime(info.Value)) + "\n";
                            else if (configData.GroupsColor.TryGetValue("default", out color)) privs = string.Format(lang.GetMessage("VRI.PRIV_TEXT", this, player.UserIDString), color, name, GetTime(info.Value)) + "\n";
                            else privs = string.Format(lang.GetMessage("VRI.PRIV_TEXT", this, player.UserIDString), "white", name, GetTime(info.Value)) + "\n";
                            container.Add(new CuiElement {
                                Parent = "Background", Name = "PrivsMenu", Components = {
                                    new CuiRawImageComponent {
                                        Png = (string) ImageLibrary.Call("GetImage", "ProfileLine"), Color = "0.65 0.65 0.65 0.7"
                                    }
                                    , new CuiRectTransformComponent {
                                        AnchorMin = "0.5 1", AnchorMax = $"0.5 1", OffsetMin = $"-150 {-50 + (-50 * i)}", OffsetMax = $"150 {-10 + (-50 * i)}"
                                    }
                                }
                            }
                            );
                            container.Add(new CuiLabel {
                                RectTransform = {
                                    AnchorMin = "0 0", AnchorMax = $"1 1", OffsetMin = "", OffsetMax = ""
                                }
                                , Text = {
                                    Text = privs, Color = "0.87 0.87 0.87 1", Align = TextAnchor.MiddleCenter, FontSize = 14, Font = "robotocondensed-bold.ttf"
                                }
                            }
                            , "PrivsMenu");
                            i++;
                            if(i == 4) {
                                i = 0;
                                break;
                            }
                        }
                    }
                }
                else {
                    container.Add(new CuiLabel {
                        RectTransform = {
                            AnchorMin = "0 0", AnchorMax = $"1 1", OffsetMax = "0 0"
                        }
                        , Text = {
                            Text = string.Format(lang.GetMessage("VRI.NO_PRIVS", this, player.UserIDString).ToUpper()), Color = "0.929 0.882 0.847 0.8", Align = TextAnchor.MiddleCenter, FontSize = 19, Font = "robotocondensed-bold.ttf"
                        }
                    }
                    , "Background");
                }
                string leftCommand = $"VipRemainInfo_Pages back {Page}";
                string rightCommand = $"VipRemainInfo_Pages next {Page}";
                bool leftActive = Page != 0;
                bool rightActive = Check_PrivsGroups ? groupInfo.Union(privsInfo).Count() > ((Page + 1) * 4) : false;
                container.Add(new CuiButton {
                    RectTransform = {
                        AnchorMin = "0 0.5", AnchorMax = "0 0.5", OffsetMin = "7 -8", OffsetMax = "22 8"
                    }
                    , Button = {
                        Color = "0 0 0 0", Command = leftActive ? leftCommand : ""
                    }
                    , Text = {
                        Text = ""
                    }
                }
                , "Background", "BackPage");
                container.Add(new CuiElement {
                    Parent = "BackPage", Components = {
                        new CuiRawImageComponent {
                            Png = (string) ImageLibrary.Call("GetImage", "LeftPage"), Color = "1 1 1 1"
                        }
                        , new CuiRectTransformComponent {
                            AnchorMin = "0 0", AnchorMax = $"1 1"
                        }
                    }
                }
                );
                container.Add(new CuiButton {
                    RectTransform = {
                        AnchorMin = "1 0.5", AnchorMax = "1 0.5", OffsetMin = "-22 -8", OffsetMax = "-7 8"
                    }
                    , Button = {
                        Color = "0 0 0 0", Command = rightActive ? rightCommand : ""
                    }
                    , Text = {
                        Text = ""
                    }
                }
                , "Background", "NextPage");
                container.Add(new CuiElement {
                    Parent = "NextPage", Components = {
                        new CuiRawImageComponent {
                            Png = (string) ImageLibrary.Call("GetImage", "RightPage"), Color = "1 1 1 1"
                        }
                        , new CuiRectTransformComponent {
                            AnchorMin = "0 0", AnchorMax = $"1 1"
                        }
                    }
                }
                );
                CuiHelper.AddUi(player, container);
            }
            else {
                if (Check_PrivsGroups) {
                    foreach(var info in groupInfo) {
                        if (!showHead) {
                            result += lang.GetMessage("VRI.PASS_TIME", this, player.UserIDString) + "\n";
                            showHead = true;
                        }
                        var name = info.Key;
                        if (configData.GroupsNewName.ContainsKey(info.Key)) name = configData.GroupsNewName[info.Key];
                        if (configData.GroupsColor.TryGetValue(info.Key, out color)) result += string.Format(lang.GetMessage("VRI.PRIV_TEXT", this, player.UserIDString), color, name, GetTime(info.Value)) + "\n";
                        else if (configData.GroupsColor.TryGetValue("default", out color)) result += string.Format(lang.GetMessage("VRI.PRIV_TEXT", this, player.UserIDString), color, name, GetTime(info.Value)) + "\n";
                        else result += string.Format(lang.GetMessage("VRI.PRIV_TEXT", this, player.UserIDString), "white", name, GetTime(info.Value)) + "\n";
                    }
                    foreach(var info in privsInfo) {
                        if (!showHead) {
                            result += lang.GetMessage("VRI.PASS_TIME", this, player.UserIDString) + "\n";
                            showHead = true;
                        }
                        var name = info.Key;
                        if (configData.GroupsNewName.ContainsKey(info.Key)) name = configData.GroupsNewName[info.Key];
                        if (configData.GroupsColor.TryGetValue(info.Key, out color)) result += string.Format(lang.GetMessage("VRI.PRIV_TEXT", this, player.UserIDString), color, name, GetTime(info.Value)) + "\n";
                        else if (configData.GroupsColor.TryGetValue("default", out color)) result += string.Format(lang.GetMessage("VRI.PRIV_TEXT", this, player.UserIDString), color, name, GetTime(info.Value)) + "\n";
                        else result += string.Format(lang.GetMessage("VRI.PRIV_TEXT", this, player.UserIDString), "white", name, GetTime(info.Value)) + "\n";
                    }
                    SendReply(player, result.TrimEnd('\n'));
                }
                ShowedVipInfo[player.userID] = true;
            }
        }
        [ConsoleCommand("VipRemainInfo_Pages")]
        private void PrivsPages(ConsoleSystem.Arg arg) {
            BasePlayer player = arg.Player();
            int Page = int.Parse(arg.Args[1]);
            switch (arg.Args[0]) {
                case "next" : {
                    ShowRemainVipInfo(player, false, Page + 1);
                    break;
                }
                case "back" : {
                    ShowRemainVipInfo(player, false, Page - 1);
                    break;
                }
            }
        }
        private string GetTime(int rawSeconds) {
            int days = (int)Math.Truncate((((decimal)rawSeconds/60)/60)/24);
            int hours = (int)Math.Truncate((((decimal)rawSeconds-days*24*60*60)/60)/60);
            int minutes = (int)Math.Truncate((((decimal)rawSeconds-days*24*60*60)/60)%60);
            string time = "";
            if (days!=0) time += $"{days}д ";
            if (hours!=0) time += $"{hours}ч ";
            if (minutes!=0) time += $"{minutes}м ";
            if (string.IsNullOrEmpty(time)) time = "несколько секунд";
            return time;
        }
        private void LoadDefaultMessages() {
            lang.RegisterMessages(new Dictionary<string, string> {
                {
                    "VRI.PASS_TIME", "Your privileges have the rest of the time:"
                }
                , {
                    "VRI.PRIV_TEXT", "Privilege <color={0}>{1}</color> - left {2}"
                }
                , {
                    "VRI.NO_PRIVS", "You don't have active privileges"
                }
                ,
            }
            , this);
            lang.RegisterMessages(new Dictionary<string, string> {
                {
                    "VRI.PASS_TIME", "Остаток времени у ваших привилегий:"
                }
                , {
                    "VRI.PRIV_TEXT", "Привилегия <color={0}>{1}</color> - осталось {2}"
                }
                , {
                    "VRI.NO_PRIVS", "У вас нет активных привилегий"
                }
                ,
            }
            , this, "ru");
        }
        private static ConfigData configData;
        private class ConfigData {
            [JsonProperty(PropertyName = "Цвета вип групп и отдельных привилегий")]
            public Dictionary<string, string> GroupsColor;
            [JsonProperty(PropertyName = "Названия вип групп и отдельных привилегий")]
            public Dictionary<string, string> GroupsNewName;
            [JsonProperty(PropertyName = "Задержка на показ остатка времени у групп и отдельных привилегий при заходе на сервер (-1 = отключить показ)")]
            public float ShowDelay;
        }
        private void LoadDefaultConfig() {
            configData = new ConfigData {
                GroupsColor = new Dictionary<string, string>() {
                    {
                        "vip", "#0FED02"
                    }
                    , {
                        "premium", "#A202ED"
                    }
                    , {
                        "kits.premium", "#FF170A"
                    }
                    , {
                        "default", "#FFA500"
                    }
                }
                , GroupsNewName = new Dictionary<string, string>() {
                    {
                        "vip", "VIP"
                    }
                    , {
                        "premium", "PRIME"
                    }
                    , {
                        "kits.premium", "Кит BigBoss"
                    }
                }
                , ShowDelay = 2f
            }
            ;
            SaveConfig(configData);
            timer.Once(0.1f, ()=> SaveConfig(configData));
        }
        private void LoadConfigVariables() => configData = Config.ReadObject<ConfigData>();
        private void SaveConfig(ConfigData config) => Config.WriteObject(config, true);
    }
}

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