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

FREE TeleportGUI : 0.0.2 0.0.2

Нет прав для скачивания
C#:
// Все права принадлежат дискорд сообществу https://discord.gg/VgNHPpNrz6
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Facepunch;
using Oxide.Core;
using Oxide.Core.Plugins;
using Oxide.Game.Rust.Cui;
using UnityEngine;
namespace Oxide.Plugins {
    [Info("TeleportGUI", "A0001", "0.0.2")]
    class TeleportGUI : RustPlugin {
#region Fields
        private const string permUse = "teleportgui.use";
        private const string permCancel = "teleportgui.tpcancel";
        private const string permBack = "teleportgui.tpback";
        private const string permHere = "teleportgui.tphere";
        private const string permSleepers = "teleportgui.sleepers";
        private static TeleportGUI Instance;
        Dictionary<BasePlayer, bool> GUIOpen = new Dictionary<BasePlayer, bool>();
        Dictionary<BasePlayer, Vector3> LastTeleport = new Dictionary<BasePlayer, Vector3>();
        List<GameObject> GameObjects = new List<GameObject>();
        bool DebuggingMode = false;
        [PluginReference]
        Plugin Economics, ServerRewards, ZoneManager;
#endregion
#region Classes
        class GUIManager {
            public static Dictionary<BasePlayer, GUIManager> Players = new Dictionary<BasePlayer, GUIManager>();
            public int Page = 1;
            public bool TPHere = false;
            public bool Sleepers = false;
            public static GUIManager Get(BasePlayer player) {
                if (Players.ContainsKey(player)) return Players[player];
                Players.Add(player, new GUIManager());
                return Players[player];
            }
        }
        class TeleportRequest : MonoBehaviour {
            GameObject GameObject;
            int Time;
            public BasePlayer From;
            public BasePlayer To;
            public static void Create(BasePlayer From, BasePlayer To, int TimeoutTime) {
                TeleportRequest tr = new TeleportRequest();
                tr.GameObject = new GameObject();
                tr = tr.GameObject.AddComponent<TeleportRequest>();
                tr.Time = TimeoutTime;
                tr.From = From;
                tr.To = To;
                Instance.GameObjects.Add(tr.GameObject);
            }
            void Start() {
                Instance.SendReply(From, Instance.GetMessage("RequestSent").Replace("{0}", To.displayName));
                Instance.SendReply(To, Instance.GetMessage("RequestRecieved").Replace("{0}", From.displayName));
                PendingRequest pr = To.gameObject.AddComponent<PendingRequest>();
                pr.From = From;
                pr.TeleportRequest = this;
                InvokeRepeating("TimerTick", 0, 1.0f);
            }
            void TimerTick() {
                if (Time == 0) RequestTimeOut();
                Time--;
            }
            public void RequestAccepted() {
                int timeUntilTeleport = Instance.GetLowest(Instance.GetConfig<Dictionary<string, object>>("TimeUntilTeleport"), From, Instance.GetConfig<int>("DefaultTimeUntilTeleport"));
                Instance.SendReply(From, Instance.GetMessage("RequestToAccepted").Replace("{0}", To.displayName).Replace("{1}", timeUntilTeleport.ToString()));
                Instance.SendReply(To, Instance.GetMessage("RequestFromAccepted").Replace("{0}", From.displayName).Replace("{1}", timeUntilTeleport.ToString()));
                Teleporter teleporter = From.gameObject.AddComponent<Teleporter>();
                teleporter.Create(From, To, timeUntilTeleport);
                PendingRequest pr = To.gameObject.GetComponent<PendingRequest>();
                if (pr != null) GameObject.Destroy(pr);
                CancelInvoke();
                GameObject.Destroy(this.gameObject);
            }
            public void RequestDeclined() {
                if (From != null) {
                    Instance.SendReply(From, Instance.GetMessage("RequestToDenied").Replace("{0}", To.displayName));
                    if (Instance.EconomicsInstalled() && Instance.GetConfig<bool>("UseEconomicsPlugin")) Instance.RefundPlayerEconomics(From);
                    if (Instance.ServerRewardsInstalled() && Instance.GetConfig<bool>("UseServerRewardsPlugin")) Instance.RefundServerRewards(From);
                }
                if (To != null) {
                    Instance.SendReply(To, Instance.GetMessage("RequestFromDenied").Replace("{0}", From.displayName));
                }
                PendingRequest pr = To?.gameObject?.GetComponent<PendingRequest>();
                if (pr != null) GameObject.Destroy(pr);
                GameObject.Destroy(this.gameObject);
            }
            public void RequestCancelled() {
                if (From != null) {
                    Instance.SendReply(From, Instance.GetMessage("TeleportRequestToCancelled").Replace("{0}", To.displayName));
                    if (Instance.EconomicsInstalled() && Instance.GetConfig<bool>("UseEconomicsPlugin")) Instance.RefundPlayerEconomics(From);
                    if (Instance.ServerRewardsInstalled() && Instance.GetConfig<bool>("UseServerRewardsPlugin")) Instance.RefundServerRewards(From);
                }
                if (To != null) {
                    Instance.SendReply(To, Instance.GetMessage("TeleportRequestFromCancelled").Replace("{0}", From.displayName));
                }
                PendingRequest pr = To?.gameObject?.GetComponent<PendingRequest>();
                if (pr != null) GameObject.Destroy(pr);
                GameObject.Destroy(this.gameObject);
            }
            void RequestTimeOut() {
                if (From != null) {
                    Instance.SendReply(From, Instance.GetMessage("RequestToTimedOut").Replace("{0}", To.displayName));
                    if (Instance.EconomicsInstalled() && Instance.GetConfig<bool>("UseEconomicsPlugin")) Instance.RefundPlayerEconomics(From);
                    if (Instance.ServerRewardsInstalled() && Instance.GetConfig<bool>("UseServerRewardsPlugin")) Instance.RefundServerRewards(From);
                }
                if (To != null) {
                    Instance.SendReply(To, Instance.GetMessage("RequestFromTimedOut").Replace("{0}", From.displayName));
                }
                PendingRequest pr = To?.gameObject?.GetComponent<PendingRequest>();
                if (pr != null) GameObject.Destroy(pr);
                GameObject.Destroy(this.gameObject);
            }
            void CancelRequest() {
                Instance.SendReply(From, Instance.GetMessage("BlockTPTakeDamage"));
                if (Instance.EconomicsInstalled() && Instance.GetConfig<bool>("UseEconomicsPlugin")) Instance.RefundPlayerEconomics(From);
                if (Instance.ServerRewardsInstalled() && Instance.GetConfig<bool>("UseServerRewardsPlugin")) Instance.RefundServerRewards(From);
                PendingRequest pr = To.gameObject.GetComponent<PendingRequest>();
                if (pr != null) GameObject.Destroy(pr);
                GameObject.Destroy(this.gameObject);
            }
            void OnDestroy() {
                CancelInvoke();
                Instance.GameObjects.Remove(GameObject);
            }
        }
        class PendingRequest : MonoBehaviour {
            public BasePlayer From;
            public TeleportRequest TeleportRequest;
        }
        class Teleporter : MonoBehaviour {
            GameObject GameObject;
            int TimeUntilTeleport;
            BasePlayer From;
            BasePlayer To;
            public void Create(BasePlayer from, BasePlayer to, int timeUntilTeleport) {
                this.GameObject = new GameObject();
                this.TimeUntilTeleport = timeUntilTeleport;
                this.From = from;
                this.To = to;
                Instance.GameObjects.Add(GameObject);
            }
            void Start() => InvokeRepeating("TimerTick", 0, 1.0f);
            void TimerTick() {
                if (TimeUntilTeleport == 0) Teleport();
                TimeUntilTeleport--;
            }
            void Teleport() {
                Vector3 currentPos = From.transform.position;
                Instance.RecordLastTP(From, currentPos);
                Instance.Teleport(From, To);
                Instance.SendReply(From, Instance.GetMessage("YouTeleportedTo").Replace("{0}", To.displayName));
                Instance.SendReply(To, Instance.GetMessage("TeleportedToYou").Replace("{0}", From.displayName));
                int cooldown = Instance.GetLowest(Instance.GetConfig<Dictionary<string, object>>("Cooldowns"), From, Instance.GetConfig<int>("DefaultCooldown"));
                Instance.storedData.Cooldowns.Add(From.userID, cooldown);
                if (Instance.GetConfig<int>("DefaultDailyLimit") != -1) {
                    int usesRemaining = Instance.IncrementUses(From);
                    Instance.SendReply(From, Instance.GetMessage("TeleportsRemaining").Replace("{0}", usesRemaining.ToString()));
                }
                GameObject.Destroy(this.gameObject.GetComponent<Teleporter>());
            }
            public void CancelTeleport() {
                Instance.SendReply(From, Instance.GetMessage("TeleportToCancelled").Replace("{0}", To.displayName));
                Instance.SendReply(To, Instance.GetMessage("TeleportFromCancelled").Replace("{0}", From.displayName));
                if (Instance.EconomicsInstalled() && Instance.GetConfig<bool>("UseEconomicsPlugin")) Instance.RefundPlayerEconomics(From);
                if (Instance.ServerRewardsInstalled() && Instance.GetConfig<bool>("UseServerRewardsPlugin")) Instance.RefundServerRewards(From);
                GameObject.Destroy(this.gameObject.GetComponent<Teleporter>());
            }
            void StartSleeping(BasePlayer player) {
                if (player.IsSleeping()) return;
                player.SetPlayerFlag(BasePlayer.PlayerFlags.Sleeping, true);
                if (!BasePlayer.sleepingPlayerList.Contains(player)) BasePlayer.sleepingPlayerList.Add(player);
                player.CancelInvoke("InventoryUpdate");
            }
            void OnDestory() {
                CancelInvoke();
                Instance.GameObjects.Remove(GameObject);
            }
        }
        class CooldownManager : MonoBehaviour {
            GameObject GameObject;
            public static void Create() {
                CooldownManager cm = new CooldownManager();
                cm.GameObject = new GameObject();
                cm.GameObject.AddComponent<CooldownManager>();
                Instance.GameObjects.Add(cm.GameObject);
            }
            void Start() {
                InvokeRepeating("TimerTick", 0, 1.0f);
            }
            void TimerTick() {
                if (Instance?.storedData?.Cooldowns == null) return;
                Dictionary<ulong, int> dict = new Dictionary<ulong, int>(Instance.storedData.Cooldowns);
                foreach (KeyValuePair<ulong, int> kvp in dict) {
                    Instance.storedData.Cooldowns[kvp.Key]--;
                    if (kvp.Value == 0) Instance.storedData.Cooldowns.Remove(kvp.Key);
                }
            }
            void OnDestroy() {
                Instance?.SaveData();
                CancelInvoke();
                Instance.GameObjects.Remove(GameObject);
            }
        }
        class StoredData {
            public Dictionary<ulong, int> Cooldowns = new Dictionary<ulong, int>();
            public Dictionary<ulong, int> UsesToday = new Dictionary<ulong, int>();
        }
        StoredData storedData;
#endregion
#region Oxide Hooks
        void Init() {
            //Debugging mode should be enabled?
            if (ConVar.Server.hostname == "PsychoTea's Testing Server") {
                DebuggingMode = true;
                Puts("Debugging mode enabled.");
            }
            //Register permissions
            permission.RegisterPermission(permUse, this);
            permission.RegisterPermission(permCancel, this);
            permission.RegisterPermission(permBack, this);
            permission.RegisterPermission(permHere, this);
            permission.RegisterPermission(permSleepers, this);
            foreach (string perm in GetConfig<Dictionary<string, object>>("Cooldowns").Keys) permission.RegisterPermission(perm, this);
            lang.RegisterMessages(new Dictionary<string, string>() {
                {
                    "NoPermission", "У вас нет разрешения на использование этой команды."
                }
                , {
                    "TeleportTitle", "Телепорт"
                }
                , {
                    "RequestSent", "Запрос телепорта отправлен к {0}."
                }
                , {
                    "RequestRecieved", "Запрос телепорта от {0}.Откройте графический интерфейс (/tp) чтобы принять телепорт."
                }
                , {
                    "RequestToTimedOut", "Истекло время ожидания ответа {0} на ваш запрос телепорта."
                }
                , {
                    "RequestFromTimedOut", "Истекло время ответа на запрос телепорт от {0}."
                }
                , {
                    "HasPendingRequest", "У {0} уже есть ожидающий запрос телепорта."
                }
                , {
                    "RequestFrom", "Запрос от {0}"
                }
                , {
                    "RequestToAccepted", "Ваш запрос на телепорт был принят {0}.Телепортация через {1} секунд."
                }
                , {
                    "RequestFromAccepted", "Запрос телепорта от {0} принят.Телепортация через {1} секунд."
                }
                , {
                    "RequestToDenied", "Ваш запрос на телепорт к {0} отклонён."
                }
                , {
                    "RequestFromDenied", "Запрос телепорта от {0} отменён."
                }
                , {
                    "YouTeleportedTo", "Ты телепортировался к {0}."
                }
                , {
                    "TeleportedToYou", "{0} телепортироваться к вам."
                }
                , {
                    "OnCooldown", "Ваш телепорт откатится через {0} секунд."
                }
                , {
                    "NoPendingRequests", "У вас нет запросов на телепорт."
                }
                , {
                    "SyntaxTPR", "Неверная команда! Пиши: /tpr {name}"
                }
                , {
                    "PlayerNotFound", "Игрок \"{0}\" не найден."
                }
                , {
                    "PlayerIDNotFound", "Игрок с таким ID {0} не найден."
                }
                , {
                    "MultiplePlayersFound", "Найдено несколько игроков с именем {0}."
                }
                , {
                    "CantTeleportToSelf", "Ты не можешь телепортироваться сам к себе!"
                }
                , {
                    "PlayerIsBuildBlocked", "Вы не можете использовать телепорт во время блокировки строительства!"
                }
                , {
                    "TargetIsBuildBlocked", "Человек, к которому вы пытаетесь телепортироваться, заблокирован."
                }
                , {
                    "LocationIsBuildBlocked", "Здание заблокировано в том месте, куда вы пытаетесь телепортироваться."
                }
                , {
                    "PlayerIsBleeding", "Вы не можете использовать телепорт во время кровотечения."
                }
                , {
                    "CantAffordEconomics", "Вы не можете себе этого позволить! Цена: ${0}"
                }
                , {
                    "EconomicsYouSpent", "Вы потратили ${0} на этот телепорт."
                }
                , {
                    "EconomicsRefunded", "Вам были возвращены ${0}."
                }
                , {
                    "CantAffordServerRewards", "Вы не можете себе этого позволить! Цена: {0}RP"
                }
                , {
                    "ServerRewardsYouSpent", "Вы потратили {0}RP на этот телепорт."
                }
                , {
                    "ServerRewardsRefunded", "Вам были возвращены {0}RP."
                }
                , {
                    "BlockTPCrafting", "Вы не можете использовать телепорт во время крафта."
                }
                , {
                    "MaxTeleportsReached", "На сегодня ваши телепорты закончились."
                }
                , {
                    "TeleportsRemaining", "{0} телепортов, осталось на сегодня."
                }
                , {
                    "TeleportRequestFromCancelled", "Запрос телепортации от {0} отменен."
                }
                , {
                    "TeleportRequestToCancelled", "Телепорт на {0} отменен."
                }
                , {
                    "TeleportRequestCancelled", "Запрос на телепорт отменен."
                }
                , {
                    "TeleportToCancelled", "Телепорт в {0} отменен."
                }
                , {
                    "TeleportFromCancelled", "Телепорт к {0} отменен."
                }
                , {
                    "NoBackLocation", "У вас нет предыдущего места для возврата."
                }
                , {
                    "TeleportedBack", "Телепортация обратно в ваше предыдущее местоположение."
                }
                , {
                    "SummonedToYou", "{0} был вызван к вам."
                }
                , {
                    "SummonedTo", "Вы были вызваны {0}."
                }
                , {
                    "SyntaxTPHere", "Неизвесная команда! Пиши: /tphere {name}"
                }
                , {
                    "TPPos-InvalidSyntax", "Неизвесная команда! Пиши: /tp {x} {y} {z}"
                }
                , {
                    "TPToPos", "Телепортация в {x}, {y}, {z}"
                }
                , {
                    "NothingToCancel", "У вас нет телепортов для отмены."
                }
                , {
                    "CantTeleportFromZone", "Вы не можете телепортироваться из этой зоны."
                }
                , {
                    "CantTeleportToZone", "Вы не можете телепортироваться в эту зону."
                }
                , {
                    "CantTPWhilstWounded", "Вы не можете телепортироваться, пока ранены."
                }
            }
            , this, "en");
            ReadData();
            foreach (string cmdAlias in GetConfig<List<object>>("TPCommandAliases")) cmd.AddChatCommand(cmdAlias, this, "tpCommand");
            timer.Once(TimeUntilMidnight(), () => ResetDailyUses());
            if (DebuggingMode) BasePlayer.activePlayerList.ForEach(x => ShowTeleportUI(x));
        }
        void OnServerInitialized() {
            Instance = this;
            CooldownManager.Create();
            if (Economics == null && GetConfig<bool>("UseEconomicsPlugin")) {
                Debug.LogError("[TeleportGUI] Error! Economics is enabled in the config but is not installed! Please install Economics or disable 'UseEconomicsPlugin' in the config!");
            }
            if (ServerRewards == null && GetConfig<bool>("UseServerRewardsPlugin")) {
                Debug.LogError("[TeleportGUI] Error! ServerRewards is enabled in the config but is not installed! Please install ServerRewards or disable 'UseServerRewardsPlugin' in the config!");
            }
        }
        void OnEntityTakeDamage(BaseCombatEntity entity, HitInfo info) {
            if (!(entity is BasePlayer)) return;
            BasePlayer player = entity as BasePlayer;
            if (player == null) return;
            if (!HasComponent<Teleporter>(player)) return;
            if (!GetConfig<bool>("CancelTeleportOnDamage")) return;
            var teleporter = player.gameObject.GetComponent<Teleporter>();
            teleporter.CancelTeleport();
        }
        void Unload() {
            foreach (GameObject go in GameObjects) {
                if (go == null) continue;
                if (HasComponent<Teleporter>(go) || HasComponent<PendingRequest>(go) || HasComponent<CooldownManager>(go)) GameObject.Destroy(go);
            }
            GameObjects.Clear();
            foreach (BasePlayer player in BasePlayer.activePlayerList) CloseUI(player);
            SaveData();
        }
        protected override void LoadDefaultConfig() {
            PrintWarning("Creating a new configuration file.");
            Config["PrefixEnabled"] = true;
            Config["PrefixText"] = "<color=orange>TP: </color>";
            Config["DefaultTimeUntilTeleport"] = 25;
            Config["TimeUntilTeleport"] = new Dictionary<string, int>() {
                {
                    "teleportgui.vip", 20
                }
                , {
                    "teleportgui.elite", 15
                }
                , {
                    "teleportgui.god", 5
                }
                , {
                    "teleportgui.none", 0
                }
            }
            ;
            Config["TPCommandAliases"] = new List<string>() {
                "teleport"
            }
            ;
            Config["RequestTimeoutTime"] = 30;
            Config["DefaultCooldown"] = 180;
            Config["Cooldowns"] = new Dictionary<string, int>() {
                {
                    "teleportgui.vip", 60
                }
                , {
                    "teleportgui.elite", 30
                }
                , {
                    "teleportgui.god", 15
                }
                , {
                    "teleportgui.none", 0
                }
            }
            ;
            Config["DefaultDailyLimit"] = 3;
            Config["DailyLimit"] = new Dictionary<string, int>() {
                {
                    "teleportgui.vip", 5
                }
                , {
                    "teleportgui.elite", 8
                }
                , {
                    "teleportgui.god", 15
                }
                , {
                    "teleportgui.none", 9999
                }
            }
            ;
            Config["AdminTPSilent"] = false;
            Config["AdminTPEnabled"] = false;
            Config["AllowTeleportWhilstBleeding"] = false;
            Config["AllowTeleportToBuildBlockedPlayer"] = false;
            Config["AllowTeleportIntoBuildBlock"] = false;
            Config["AllowTeleportFromBuildBlock"] = false;
            Config["UseEconomicsPlugin"] = false;
            Config["EconomicsPrice"] = 100;
            Config["UseServerRewardsPlugin"] = false;
            Config["ServerRewardsPrice"] = 10;
            Config["BlockTPCrafting"] = true;
            Config["AllowSpecialCharacters"] = false;
            Config["CancelTeleportOnDamage"] = true;
            Config["CanTeleportIntoZone"] = true;
            Config["CanTeleportFromZone"] = true;
        }
#endregion
#region Commands
        [ChatCommand("tp")]
        void TPCommand(BasePlayer player, string command, string[] args) {
            if (!HasPerm(player)) {
                SendReply(player, GetMessage("NoPermission"));
                return;
            }
            if (player.IsAdmin && args.Length > 0) {
                if (args.Length < 3) {
                    SendReply(player, GetMessage("TPPos-InvalidSyntax"));
                    return;
                }
                float x, y, z;
                if (!float.TryParse(args[0], out x) || !float.TryParse(args[1], out y) || !float.TryParse(args[2], out z)) {
                    SendReply(player, GetMessage("TPPos-InvalidSyntax"));
                    return;
                }
                Teleport(player, new Vector3(x, y, z));
                SendReply(player, GetMessage("TPToPos").Replace("{x}", x.ToString("N1")).Replace("{y}", y.ToString("N1")).Replace("{z}", z.ToString("N1")));
                return;
            }
            ShowTeleportUI(player);
        }
        [ChatCommand("tpr")]
        void TPRCommand(BasePlayer player, string command, string[] args) {
            if (!HasPerm(player)) {
                SendReply(player, GetMessage("NoPermission"));
                return;
            }
            if (args.Length < 1) {
                SendReply(player, GetMessage("SyntaxTPR"));
                return;
            }
            string name = args[0];
            for (int i = 1; i < args.Length; i++) name += " " + args[i];
            List<BasePlayer> matches = FindByNameMulti(name);
            if (matches.Count() == 0) {
                SendReply(player, GetMessage("PlayerNotFound").Replace("{0}", name));
                return;
            }
            else if (matches.Count() > 1) {
                SendReply(player, GetMessage("MultiplePlayersFound").Replace("{0}", name));
                return;
            }
            BasePlayer targetPlayer = matches.First();
            if (targetPlayer == player && !DebuggingMode) {
                SendReply(player, GetMessage("CantTeleportToSelf"));
                return;
            }
            TPR(player, targetPlayer);
            return;
        }
        [ChatCommand("tpa")]
        void TPACommand(BasePlayer player, string command, string[] args) {
            if (!HasPerm(player)) {
                SendReply(player, GetMessage("NoPermission"));
                return;
            }
            TeleportRequest tr = player.gameObject.GetComponent<PendingRequest>()?.TeleportRequest;
            if (tr == null) {
                SendReply(player, GetMessage("NoPendingRequests"));
                return;
            }
            tr.RequestAccepted();
            CloseUI(player);
        }
        [ChatCommand("tpd")]
        void TPDCommand(BasePlayer player, string command, string[] args) {
            if (!HasPerm(player)) {
                SendReply(player, GetMessage("NoPermission"));
                return;
            }
            TeleportRequest tr = player.gameObject.GetComponent<PendingRequest>()?.TeleportRequest;
            if (tr == null) {
                SendReply(player, GetMessage("NoPendingRequests"));
                return;
            }
            tr.RequestDeclined();
            CloseUI(player);
        }
        [ChatCommand("tpc")]
        void TPCCommand(BasePlayer player, string command, string[] args) {
            if (!HasPerm(player, permCancel)) {
                SendReply(player, GetMessage("NoPermission"));
                return;
            }
            TPC(player);
        }
        [ChatCommand("tpb")]
        void TPBCommand(BasePlayer player, string command, string[] args) {
            if (!HasPerm(player, permBack)) {
                SendReply(player, GetMessage("NoPermission"));
                return;
            }
            TPB(player);
        }
        [ChatCommand("tphere")]
        void TPHereCommand(BasePlayer player, string command, string[] args) {
            if (!HasPerm(player, permHere)) {
                SendReply(player, GetMessage("NoPermission"));
                return;
            }
            if (args.Length < 1) {
                SendReply(player, GetMessage("SyntaxTPHere"));
                return;
            }
            string targetName = string.Join(" ", args);
            List<BasePlayer> matches = FindByNameMulti(targetName);
            if (matches.Count() == 0) {
                SendReply(player, GetMessage("PlayerNotFound").Replace("{0}", targetName));
                return;
            }
            if (matches.Count > 1) {
                SendReply(player, GetMessage("MultiplePlayersFound").Replace("{0}", targetName));
                return;
            }
            BasePlayer targetPlayer = matches.First();
            TPHere(player, targetPlayer.userID);
        }
        [ConsoleCommand("tpgui")]
        void TPGuiCommand(ConsoleSystem.Arg arg) {
            if (arg.Player() == null) return;
            BasePlayer player = arg.Player();
            string[] args = arg.Args ?? new string[] {
            }
            ;
#region Check Perm
            if (!HasPerm(player)) {
                SendReply(player, GetMessage("NoPermission"));
                return;
            }
#endregion
#region Open GUI
            if (args.Length == 0) {
                ShowTeleportUI(player);
                return;
            }
            if (args[0] == "True")  //Because apparently bind b tpgui runs "tpgui True" -.-
            {
                ShowTeleportUI(player);
                return;
            }
#endregion
#region Close
            if (args[0] == "close") {
                CloseUI(player);
                return;
            }
#endregion
#region To
            if (args[0] == "to") {
                if (args.Length < 2) return;
                CloseUI(player);
                string userIDString = args[1];
                ulong userID;
                if (!ulong.TryParse(userIDString, out userID)) return;
                var guiSettings = GUIManager.Get(player);
                if (guiSettings.Sleepers) {
                    var target = BasePlayer.sleepingPlayerList.FirstOrDefault(x => x.userID == userID);
                    if (target == null) {
                        SendReply(player, GetMessage("PlayerIDNotFound").Replace("{0}", userIDString));
                        return;
                    }
                    SendReply(player, GetMessage("YouTeleportedTo").Replace("{0}", target.displayName));
                    RecordLastTP(player, player.transform.position);
                    Teleport(player, target);
                    return;
                }
                BasePlayer targetPlayer = BasePlayer.FindByID(userID);
                if (targetPlayer == null) {
                    SendReply(player, GetMessage("PlayerIDNotFound").Replace("{0}", userIDString));
                    return;
                }
                TPR(player, targetPlayer);
                return;
            }
#endregion
#region Accept
            if (args[0] == "accept") {
                TeleportRequest tr = player.gameObject.GetComponent<PendingRequest>()?.TeleportRequest;
                if (tr == null) {
                    SendReply(player, GetMessage("NoPendingRequests"));
                    return;
                }
                tr.RequestAccepted();
                CloseUI(player);
                return;
            }
#endregion
#region Decline
            if (args[0] == "decline") {
                TeleportRequest tr = player.gameObject.GetComponent<PendingRequest>()?.TeleportRequest;
                if (tr == null) {
                    SendReply(player, GetMessage("NoPendingRequests"));
                    return;
                }
                tr.RequestDeclined();
                CloseUI(player);
                return;
            }
#endregion
#region Back
            if (args[0] == "back") {
                if (!HasPerm(player, permBack)) {
                    SendReply(player, GetMessage("NoPermission"));
                    return;
                }
                TPB(player);
                CloseUI(player);
                return;
            }
#endregion
#region Cancel
            if (args[0] == "cancel") {
                if (!HasPerm(player, permCancel)) {
                    SendReply(player, GetMessage("NoPermission"));
                    return;
                }
                TPC(player);
                CloseUI(player);
                return;
            }
#endregion
#region Here TP
            if (args[0] == "heretp") {
                if (!HasPerm(player, permHere)) {
                    SendReply(player, GetMessage("NoPermission"));
                    return;
                }
                if (args.Length < 2) return;
                string userIDString = args[1];
                ulong userID;
                if (!ulong.TryParse(userIDString, out userID)) return;
                TPHere(player, userID);
                return;
            }
#endregion
#region Set
            if (args[0] == "set") {
                if (args.Length < 3) return;
                switch (args[1]) {
                    case "page" : int page;
                    if (!Int32.TryParse(args[2], out page)) return;
                    GUIManager.Get(player).Page = page;
                    UIChooser(player);
                    break;
                    case "tphere" : if (!HasPerm(player, permHere)) {
                        SendReply(player, GetMessage("NoPermission"));
                        return;
                    }
                    bool here = args[2] == bool.TrueString;
                    GUIManager.Get(player).TPHere = here;
                    UIChooser(player);
                    break;
                    case "sleepers" : if (!HasPerm(player, permSleepers)) {
                        SendReply(player, GetMessage("NoPermission"));
                        return;
                    }
                    bool sleepers = args[2] == bool.TrueString;
                    GUIManager.Get(player).Sleepers = sleepers;
                    UIChooser(player);
                    break;
                }
                return;
            }
#endregion
        }
        [ConsoleCommand("resetdatafile")]
        void ResetAllCommand(ConsoleSystem.Arg arg) {
            if (arg.Player() != null) return;
            if (!DebuggingMode) {
                Debug.LogError("[TeleportGUI] Вы не можете использовать эту команду.Предупреждение: это непроверенно и небезопасно.Пожалуйста, не пропустите это предупреждение.");
                return;
            }
            storedData.Cooldowns.Clear();
            storedData.UsesToday.Clear();
            SaveData();
            Puts("Cleared data file and saved.");
        }
#endregion
#region GUIs
        void ShowTeleportUI(BasePlayer player) {
            if (!GUIOpen.ContainsKey(player)) GUIOpen.Add(player, false);
            if (GUIOpen[player]) {
                CloseUI(player);
                GUIOpen[player] = false;
                return;
            }
            GUIOpen[player] = true;
            UIChooser(player);
        }
        void UIChooser(BasePlayer player) {
            var guiSettings = GUIManager.Get(player);
            if (BasePlayer.activePlayerList.Count > 25 || guiSettings.Sleepers) {
                BigUI(player);
                return;
            }
            SmallUI(player);
        }
        void CloseUI(BasePlayer player) {
            if (!GUIOpen.ContainsKey(player)) GUIOpen.Add(player, false);
            GUIOpen[player] = false;
            CuiHelper.DestroyUi(player, "smallTeleportGUI");
            CuiHelper.DestroyUi(player, "bigTeleportGUI");
        }
        void SmallUI(BasePlayer player) {
            var GUIElement = new CuiElementContainer();
            var guiSettings = GUIManager.Get(player);
            List<BasePlayer> players = !guiSettings.Sleepers ? BasePlayer.activePlayerList : BasePlayer.sleepingPlayerList;
            players = new List<BasePlayer>(players);
            if (!DebuggingMode && players.Contains(player)) {
                players.Remove(player);
            }
            //if (debuggingMode) players.AddRange(SpareNames());
            players = players.OrderBy(x => x.displayName).ToList();
#region Whole Panel
            var smallTeleportGUI = GUIElement.Add(new CuiPanel {
                Image = {
                    Color = "0 0 0 0.75"
                }
                , RectTransform = {
                    AnchorMin = "0.3 0.3",  //Left Bottom
                    AnchorMax = "0.7 0.75"  // Right Top
                }
                , CursorEnabled = true
            }
            , "Hud", "smallTeleportGUI");
#endregion
#region Title Bar
            var titleBar = GUIElement.Add(new CuiPanel {
                Image = {
                    Color = "0 0 0 0.75"
                }
                , RectTransform = {
                    AnchorMin = "0 0.9",  //Left Bottom
                    AnchorMax = "0.998 0.999"  // Right Top
                }
            }
            , smallTeleportGUI);
#region Pending Request Buttons
            bool pendingRequest = (player.gameObject.GetComponent<PendingRequest>() != null);
            string requestFrom = player.gameObject.GetComponent<PendingRequest>()?.From.displayName;
            if (pendingRequest) {
                GUIElement.Add(new CuiButton {
                    RectTransform = {
                        AnchorMin = "0 0", AnchorMax = "0.12 0.96"
                    }
                    , Button = {
                        Command = "tpgui accept", Color = "0 1 0 1",
                    }
                    , Text = {
                        Text = "Accept", FontSize = 18, Color = "1 1 1 1", Align = TextAnchor.MiddleCenter
                    }
                }
                , titleBar);
                GUIElement.Add(new CuiButton {
                    RectTransform = {
                        AnchorMin = "0.122 0", AnchorMax = "0.24 0.96"
                    }
                    , Button = {
                        Command = "tpgui decline", Color = "1 0 0 1",
                    }
                    , Text = {
                        Text = "Decline", FontSize = 18, Color = "1 1 1 1", Align = TextAnchor.MiddleCenter
                    }
                }
                , titleBar);
                GUIElement.Add(new CuiLabel {
                    Text = {
                        Text = lang.GetMessage("RequestFrom", this).Replace("{0}", requestFrom), FontSize = 16, Align = TextAnchor.MiddleLeft
                    }
                    , RectTransform = {
                        AnchorMin = "0.26 0", AnchorMax = "1 1"
                    }
                }
                , titleBar);
            }
#endregion
#region Title
            if (!pendingRequest) {
                GUIElement.Add(new CuiLabel {
                    Text = {
                        Text = lang.GetMessage("TeleportTitle", this), FontSize = 20, Align = TextAnchor.MiddleCenter
                    }
                    , RectTransform = {
                        AnchorMin = "0 0", AnchorMax = "1 1"
                    }
                }
                , titleBar);
            }
#endregion
#region Sleepers
            if (HasPerm(player, permSleepers)) {
                var sleepers = GUIManager.Get(player).Sleepers;
                string colour = (sleepers) ? "1 0.2 0.2 1" : "0.5 0.5 0.5 1";
                GUIElement.Add(new CuiButton {
                    RectTransform = {
                        AnchorMin = "0.61 0", AnchorMax = "0.71 0.97"
                    }
                    , Text = {
                        Text = "Sleepers", Color = "1 1 1 1", Align = TextAnchor.MiddleCenter
                    }
                    , Button = {
                        Command = $"tpgui set sleepers {!sleepers}", Color = colour
                    }
                }
                , titleBar);
            }
#endregion
#region TPHere
            if (HasPerm(player, permHere)) {
                var tpHere = GUIManager.Get(player).TPHere;
                string colour = (tpHere) ? "0 1 0 1" : "0.5 0.5 0.5 1";
                GUIElement.Add(new CuiButton {
                    RectTransform = {
                        AnchorMin = "0.71 0", AnchorMax = "0.78 0.97"
                    }
                    , Text = {
                        Text = "Here", Color = "1 1 1 1", Align = TextAnchor.MiddleCenter
                    }
                    , Button = {
                        Command = $"tpgui set tphere {!tpHere}", Color = colour
                    }
                }
                , titleBar);
            }
#endregion
#region TPBack
            if (HasPerm(player, permBack)) {
                var colour = (LastTeleport.ContainsKey(player)) ? "0.15 0.15 1 1" : "0.5 0.5 0.5 1";
                var command = (LastTeleport.ContainsKey(player)) ? "tpgui back" : "";
                GUIElement.Add(new CuiButton {
                    RectTransform = {
                        AnchorMin = "0.78 0", AnchorMax = "0.85 0.97"
                    }
                    , Text = {
                        Text = "Back", Color = "1 1 1 1", Align = TextAnchor.MiddleCenter
                    }
                    , Button = {
                        Command = command, Color = colour
                    }
                }
                , titleBar);
            }
#endregion
#region TPCancel
            if (HasPerm(player, permCancel)) {
                var colour = (HasPendingTeleport(player)) ? "1 0.5 0 1" : "0.5 0.5 0.5 1";
                var command = (HasPendingTeleport(player)) ? "tpgui cancel" : "";
                GUIElement.Add(new CuiButton {
                    RectTransform = {
                        AnchorMin = "0.85 0", AnchorMax = "0.934 0.97"
                    }
                    , Text = {
                        Text = "Cancel", Color = "1 1 1 1", Align = TextAnchor.MiddleCenter
                    }
                    , Button = {
                        Command = command, Color = colour
                    }
                }
                , titleBar);
            }
#endregion
#region Close Button
            GUIElement.Add(new CuiButton {
                RectTransform = {
                    AnchorMin = "0.935 0", AnchorMax = "0.998 0.97"
                }
                , Button = {
                    Command = "tpgui close", Color = "1 0 0 1"
                }
                , Text = {
                    Text = "X", FontSize = 20, Align = TextAnchor.MiddleCenter, Color = "1 1 1 1"
                }
            }
            , titleBar);
#endregion
#endregion
#region Player List
            var playerList = GUIElement.Add(new CuiPanel {
                Image = {
                    Color = "0 0 0 0"
                }
                , RectTransform = {
                    AnchorMin = "0 0", AnchorMax = "1 0.9"
                }
            }
            , smallTeleportGUI);
            const float columnWidth = 0.2f;
            const float rowWidth = 0.2f;
            int playerCount = 0;
            for (int i = 0; i < 5; i++) {
                for (int j = 0; j < 5; j++) {
                    if (players.Count <= playerCount) continue;
                    BasePlayer target = players[playerCount];
                    var panel = GUIElement.Add(new CuiPanel {
                        RectTransform = {
                            AnchorMin = (columnWidth * j).ToString() + " " + (1f - (rowWidth * i) - rowWidth).ToString(), AnchorMax = ((columnWidth * j) + columnWidth).ToString() + " " + (1f - (rowWidth * i)).ToString()
                        }
                        , Image = {
                            Color = "0 0 0 0"
                        }
                    }
                    , playerList);
                    GUIElement.Add(new CuiButton {
                        RectTransform = {
                            AnchorMin = "0 0", AnchorMax = "1 1"
                        }
                        , Text = {
                            Text = CleanText(target.displayName), Align = TextAnchor.MiddleCenter, FontSize = 18, Color = "1 1 1 1", Font = "robotocondensed-regular.ttf"
                        }
                        , Button = {
                            Command = $"tpgui to {target.userID}", Color = "0 0 0 0"
                        }
                    }
                    , panel);
                    if (GUIManager.Get(player).TPHere) {
                        GUIElement.Add(new CuiButton {
                            RectTransform = {
                                AnchorMin = "0.7 0.005", AnchorMax = "0.97 0.2"
                            }
                            , Text = {
                                Text = "Here", Color = "1 1 1 1", Align = TextAnchor.MiddleCenter, FontSize = 12
                            }
                            , Button = {
                                Command = $"tpgui heretp {target.userID}", Color = "0 1 0 0.5"
                            }
                        }
                        , panel);
                    }
                    playerCount++;
                }
            }
#endregion
#region Empty List
            if (players.Count == 0) {
                GUIElement.Add(new CuiLabel {
                    Text = {
                        Text = "Looks like you're a lone survivor!", FontSize = 20, Align = TextAnchor.MiddleCenter
                    }
                    , RectTransform = {
                        AnchorMin = "0 0.1", AnchorMax = "1 1"
                    }
                }
                , playerList);
            }
#endregion
            CuiHelper.DestroyUi(player, "smallTeleportGUI");
            CuiHelper.DestroyUi(player, "bigTeleportGUI");
            CuiHelper.AddUi(player, GUIElement);
        }
        void BigUI(BasePlayer player) {
            var GUIElement = new CuiElementContainer();
            var guiSettings = GUIManager.Get(player);
            List<BasePlayer> players = !guiSettings.Sleepers ? BasePlayer.activePlayerList : BasePlayer.sleepingPlayerList;
            players = new List<BasePlayer>(players);
            if (!DebuggingMode && players.Contains(player)) {
                players.Remove(player);
            }
            //if (debuggingMode) players.AddRange(SpareNames());
            players = players.OrderBy(x => x.displayName).ToList();
            int maxPages = CalculatePages(players.Count);
#region Whole Panel
            var bigTeleportGUI = GUIElement.Add(new CuiPanel {
                Image = {
                    Color = "0 0 0 0.75"
                }
                , RectTransform = {
                    AnchorMin = "0.2 0.125",  //Left Bottom
                    AnchorMax = "0.8 0.9"  // Right Top
                }
                , CursorEnabled = true
            }
            , "Hud", "bigTeleportGUI");
#endregion
#region Title Bar
            var titleBar = GUIElement.Add(new CuiPanel {
                Image = {
                    Color = "0 0 0 0.75"
                }
                , RectTransform = {
                    AnchorMin = "0 0.935",  //Left Bottom
                    AnchorMax = "0.997 1.0"  // Right Top
                }
            }
            , bigTeleportGUI);
#region Pending Request Buttons
            bool pendingRequest = (player.gameObject.GetComponent<PendingRequest>() != null);
            string requestFrom = player.gameObject.GetComponent<PendingRequest>()?.From.displayName;
            if (pendingRequest) {
                GUIElement.Add(new CuiButton {
                    RectTransform = {
                        AnchorMin = "0 0.01", AnchorMax 
// ... [Code preview truncated due to length. Full source in attached file] ...

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