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

FREE TeleportGUI : 1.7.18 1.7.18

Нет прав для скачивания
C#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Oxide.Core;
using Oxide.Core.Plugins;
using Oxide.Game.Rust.Cui;
using UnityEngine;
namespace Oxide.Plugins {
    /*
        This plugin was written solely by PsychoTea.Please do not, under any circumstances, redistribute this code.If you find any bugs, please report them either directly to me at bensparkes8@gmail.com,
        or on the chaoscode.io page.The same applies for feature requests.For any enquiries please also email me at bensparkes8@gmail.com
        I am open to offers for private plugins.*/
    [Info("TeleportGUI", "oxide-russia.ru", "1.7.18")]
    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 const string permAutoAccept = "teleportgui.autoaccept";
        private const string permLocation = "teleportgui.location";
        private static TeleportGUI Instance;
        private Dictionary<BasePlayer, bool> GUIOpen = new Dictionary<BasePlayer, bool>();
        private Dictionary<ulong, Vector3> LastTeleport = new Dictionary<ulong, Vector3>();
        private List<Vector3> OilRigs = new List<Vector3>();
        private bool DebuggingMode = false;
        [PluginReference]
        private Plugin Economics, ServerRewards, NoEscape, ZoneManager;
#endregion
#region Classes
        class GUIManager {
            public static Dictionary<BasePlayer, GUIManager> Players = new Dictionary<BasePlayer, GUIManager>();
            public int Page = 1;
            public bool SettingsOpen = false;
            public bool TPHere = false;
            public bool Sleepers = false;
            public bool AutoAccept = false;
            public static GUIManager Get(BasePlayer player) {
                if (!Players.ContainsKey(player)) {
                    Players.Add(player, new GUIManager());
                }
                return Players[player];
            }
        }
        class TeleportRequest : MonoBehaviour {
            private BasePlayer _from;
            private BasePlayer _to;
            private bool _tpHere;
            private double _time;
            private bool _playerIsPaying;
            private bool _isInstant;
            public static void Create(BasePlayer from, BasePlayer to, double timeoutTime, bool tpHere, bool playerIsPaying) {
                var gameObject = new GameObject();
                var tpReq = gameObject.AddComponent<TeleportRequest>();
                tpReq._from = from;
                tpReq._to = to;
                tpReq._tpHere = tpHere;
                tpReq._time = timeoutTime;
                tpReq._playerIsPaying = playerIsPaying;
            }
            void Start() {
                if (_tpHere) {
                    SendReply(_from, Instance.GetMessage("HereRequestSent").Replace("{0}", _to.displayName));
                    SendReply(_to, Instance.GetMessage("HereRequestRecieved").Replace("{0}", _from.displayName));
                }
                else {
                    SendReply(_from, Instance.GetMessage("RequestSent").Replace("{0}", _to.displayName));
                    SendReply(_to, Instance.GetMessage("RequestRecieved").Replace("{0}", _from.displayName));
                }
                PendingRequest pr = _to.gameObject.AddComponent<PendingRequest>();
                pr.From = _from;
                pr.TeleportRequest = this;
                var targetSettings = GUIManager.Get(_to);
                if (targetSettings.AutoAccept && !(_tpHere && !Instance.ConfigFile.AllowAutoAcceptOnHereTPs)) {
                    _isInstant = true;
                    RequestAccepted();
                    return;
                }
                InvokeHandler.InvokeRepeating(this, TimerTick, 0, 1.0f);
            }
            void TimerTick() {
                if (_time == 0) {
                    RequestTimeOut();
                    return;
                }
                if (_to == null || !_to.IsConnected || _from == null || !_from.IsConnected) {
                    RequestCancelled();
                    return;
                }
                _time--;
            }
            public void RequestAccepted() {
                int timeUntilTP = Instance.ConfigFile.DefaultTimeUntilTeleport;
                var lowestTimeUntilTP = Instance.ConfigFile.TimeUntilTeleport.Where(x => Instance.permission.UserHasPermission(_from.UserIDString, x.Key) && x.Value < timeUntilTP).OrderBy(x => x.Value).FirstOrDefault();
                if (!lowestTimeUntilTP.Equals(default(KeyValuePair<string, int>))) {
                    timeUntilTP = lowestTimeUntilTP.Value;
                }
                if (_isInstant) {
                    SendReply(_from, Instance.GetMessage("InstantRequestToAccepted").Replace("{0}", _to.displayName));
                    SendReply(_to, Instance.GetMessage("InstantRequestFromAccepted").Replace("{0}", _from.displayName));
                }
                else {
                    SendReply(_from, Instance.GetMessage("RequestToAccepted").Replace("{0}", _to.displayName).Replace("{1}", timeUntilTP.ToString("N1")));
                    SendReply(_to, Instance.GetMessage("RequestFromAccepted").Replace("{0}", _from.displayName).Replace("{1}", timeUntilTP.ToString("N1")));
                }
                Teleporter teleporter = _from.gameObject.AddComponent<Teleporter>();
                teleporter.Create(_from, _to, timeUntilTP);
                Cleanup();
            }
            public void RequestDeclined() {
                if (_from != null) {
                    if (_tpHere) {
                        SendReply(_from, Instance.GetMessage("HereRequestToDenied").Replace("{0}", _to.displayName));
                    }
                    else {
                        SendReply(_from, Instance.GetMessage("RequestToDenied").Replace("{0}", _to.displayName));
                    }
                    if (Instance.EconomicsInstalled() && Instance.ConfigFile.UseEconomicsPlugin && _playerIsPaying) {
                        Instance.RefundPlayerEconomics(_from);
                    }
                    if (Instance.ServerRewardsInstalled() && Instance.ConfigFile.UseServerRewardsPlugin && _playerIsPaying) {
                        Instance.RefundServerRewards(_from);
                    }
                }
                if (_to != null) {
                    if (_tpHere) {
                        SendReply(_to, Instance.GetMessage("HereRequestFromDenied").Replace("{0}", _from.displayName));
                    }
                    else {
                        SendReply(_to, Instance.GetMessage("RequestFromDenied").Replace("{0}", _from.displayName));
                    }
                }
                Cleanup();
            }
            public void RequestCancelled() {
                if (_from != null) {
                    SendReply(_from, Instance.GetMessage("TeleportRequestToCancelled").Replace("{0}", _to.displayName));
                    if (Instance.EconomicsInstalled() && Instance.ConfigFile.UseEconomicsPlugin && _playerIsPaying) {
                        Instance.RefundPlayerEconomics(_from);
                    }
                    if (Instance.ServerRewardsInstalled() && Instance.ConfigFile.UseServerRewardsPlugin && _playerIsPaying) {
                        Instance.RefundServerRewards(_from);
                    }
                }
                if (_to != null) {
                    SendReply(_to, Instance.GetMessage("TeleportRequestFromCancelled").Replace("{0}", _from.displayName));
                }
                Cleanup();
            }
            void RequestTimeOut() {
                if (_from != null) {
                    if (!string.IsNullOrEmpty(_to?.displayName)) {
                        if (_tpHere) {
                            SendReply(_from, Instance.GetMessage("HereRequestToTimedOut").Replace("{0}", _to.displayName));
                            SendReply(_to, Instance.GetMessage("HereRequestFromTimedOut").Replace("{0}", _from.displayName));
                        }
                        else {
                            SendReply(_from, Instance.GetMessage("RequestToTimedOut").Replace("{0}", _to.displayName));
                            SendReply(_to, Instance.GetMessage("RequestFromTimedOut").Replace("{0}", _from.displayName));
                        }
                    }
                    if (Instance.EconomicsInstalled() && Instance.ConfigFile.UseEconomicsPlugin && _playerIsPaying) {
                        Instance.RefundPlayerEconomics(_from);
                    }
                    if (Instance.ServerRewardsInstalled() && Instance.ConfigFile.UseServerRewardsPlugin && _playerIsPaying) {
                        Instance.RefundServerRewards(_from);
                    }
                }
                Cleanup();
            }
            void CancelRequest() {
                if (_from != null) SendReply(_from, Instance.GetMessage("BlockTPTakeDamage"));
                if (Instance.EconomicsInstalled() && Instance.ConfigFile.UseEconomicsPlugin && _playerIsPaying) {
                    Instance.RefundPlayerEconomics(_from);
                }
                if (Instance.ServerRewardsInstalled() && Instance.ConfigFile.UseServerRewardsPlugin && _playerIsPaying) {
                    Instance.RefundServerRewards(_from);
                }
                Cleanup();
            }
            void Cleanup() {
                InvokeHandler.CancelInvoke(this, TimerTick);
                PendingRequest pr = _to?.gameObject?.GetComponent<PendingRequest>();
                if (pr != null) Destroy(pr);
                Destroy(this.gameObject);
            }
        }
        class PendingRequest : MonoBehaviour {
            public BasePlayer From;
            public TeleportRequest TeleportRequest;
        }
        class Teleporter : MonoBehaviour {
            private BasePlayer _from;
            private BasePlayer _to;
            private int _timeUtilTeleport;
            public void Create(BasePlayer from, BasePlayer to, int timeUntilTeleport) {
                this._timeUtilTeleport = timeUntilTeleport;
                this._from = from;
                this._to = to;
            }
            void Start() => InvokeHandler.InvokeRepeating(this, TimerTick, 0, 1.0f);
            void TimerTick() {
                if (_timeUtilTeleport == 0) {
                    Teleport();
                    return;
                }
                if (_to == null || !_to.IsConnected || _from == null || !_from.IsConnected) {
                    CancelTeleport();
                    return;
                }
                _timeUtilTeleport--;
            }
            void Teleport() {
                if (!_to.IsAlive()) {
                    SendReply(_from, Instance.GetMessage("TargetHasDied"));
                    Destroy(this);
                    return;
                }
                bool escapeBlocked = Instance.NoEscape?.Call<bool>("IsBlocked", _from) ?? false;
                if (escapeBlocked) {
                    SendReply(_from, Instance.GetMessage("IsEscapeBlocked"));
                    return;
                }
                if (!Instance.ConfigFile.AllowTeleportToRaidBlockedPlayer) {
                    bool targetBlocked = Instance.NoEscape?.Call<bool>("IsBlocked", _to) ?? false;
                    if (targetBlocked) {
                        SendReply(_from, Instance.GetMessage("TargetIsEscapeBlocked"));
                        return;
                    }
                }
                if (!Instance.ConfigFile.AllowTeleportFromCargoShip && _from.GetParentEntity() is CargoShip) {
                    SendReply(_from, Instance.GetMessage("PlayerIsOnCargoShip"));
                    Destroy(this);
                    return;
                }
                if (_to.GetParentEntity() is CargoShip) {
                    SendReply(_from, Instance.GetMessage("TargetIsOnCargoShip"));
                    Destroy(this);
                    return;
                }
                if (!Instance.ConfigFile.AllowTeleportFromHotAirBalloon && _from.GetParentEntity() is HotAirBalloon) {
                    SendReply(_from, Instance.GetMessage("PlayerIsOnHotAirBalloon"));
                    Destroy(this);
                    return;
                }
                if (_to.GetParentEntity() is HotAirBalloon) {
                    SendReply(_from, Instance.GetMessage("TargetIsOnHotAirBalloon"));
                    Destroy(this);
                    return;
                }
                if (!Instance.ConfigFile.AllowTeleportFromMounted && _from.isMounted) {
                    SendReply(_from, Instance.GetMessage("PlayerIsMounted"));
                    Destroy(this);
                    return;
                }
                if (!Instance.ConfigFile.AllowTeleportToMounted && _to.isMounted) {
                    SendReply(_from, Instance.GetMessage("TargetIsMounted"));
                    Destroy(this);
                    return;
                }
                if (!Instance.ConfigFile.AllowTeleportFromOilRig && Instance.IsNearOilRig(_from)) {
                    SendReply(_from, Instance.GetMessage("PlayerIsNearOilRig"));
                    Destroy(this);
                    return;
                }
                if (!Instance.ConfigFile.AllowTeleportToOilRig && Instance.IsNearOilRig(_to)) {
                    SendReply(_to, Instance.GetMessage("TargetIsNearOilRig"));
                    Destroy(this);
                    return;
                }
                if (!Instance.ConfigFile.AllowTeleportFromBuildBlock && !_from.CanBuild()) {
                    SendReply(_from, Instance.GetMessage("PlayerIsBuildBlocked"));
                    Destroy(this);
                    return;
                }
                if (!Instance.ConfigFile.AllowTeleportToBuildBlockedPlayer && !_to.CanBuild()) {
                    SendReply(_from, Instance.GetMessage("TargetIsBuildBlocked"));
                    Destroy(this);
                    return;
                }
                Instance.Teleport(_from, _to);
                SendReply(_from, Instance.GetMessage("YouTeleportedTo").Replace("{0}", _to.displayName));
                SendReply(_to, Instance.GetMessage("TeleportedToYou").Replace("{0}", _from.displayName));
                double cooldown = Instance.ConfigFile.DefaultCooldown;
                var lowestCooldown = Instance.ConfigFile.Cooldowns.Where(x => Instance.permission.UserHasPermission(_from.UserIDString, x.Key) && x.Value < cooldown).OrderBy(x => x.Value).FirstOrDefault();
                if (!lowestCooldown.Equals(default(KeyValuePair<string, double>))) {
                    cooldown = lowestCooldown.Value;
                }
                if (!Instance.storedData.Cooldowns.ContainsKey(_from.userID)) {
                    Instance.storedData.Cooldowns.Add(_from.userID, cooldown);
                }
                else {
                    Instance.storedData.Cooldowns[_from.userID] = cooldown;
                }
                if (Instance.ConfigFile.DefaultDailyLimit > 0 && !Instance.HasReachedDailyLimit(_from)) {
                    int usesRemaining = Instance.IncrementUses(_from);
                    SendReply(_from, Instance.GetMessage("TeleportsRemaining").Replace("{0}", usesRemaining.ToString()));
                }
                Destroy(this);
            }
            public void CancelTeleport() {
                SendReply(_from, Instance.GetMessage("TeleportToCancelled").Replace("{0}", _to.displayName));
                SendReply(_to, Instance.GetMessage("TeleportFromCancelled").Replace("{0}", _from.displayName));
                if (Instance.EconomicsInstalled() && Instance.ConfigFile.UseEconomicsPlugin) Instance.RefundPlayerEconomics(_from);
                if (Instance.ServerRewardsInstalled() && Instance.ConfigFile.UseServerRewardsPlugin) Instance.RefundServerRewards(_from);
                Destroy(this);
            }
            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 OnDestroy() {
                InvokeHandler.CancelInvoke(this, TimerTick);
            }
        }
        class CooldownManager : MonoBehaviour {
            public static void Create() {
                new GameObject().AddComponent<CooldownManager>();
            }
            void Start() {
                InvokeHandler.InvokeRepeating(this, TimerTick, 0, 1.0f);
            }
            void TimerTick() {
                if (Instance?.storedData?.Cooldowns == null) return;
                var allCooldowns = new Dictionary<ulong, double>(Instance.storedData.Cooldowns);
                foreach (KeyValuePair<ulong, double> kvp in allCooldowns) {
                    Instance.storedData.Cooldowns[kvp.Key]--;
                    if ((int)kvp.Value <= 0) {
                        Instance.storedData.Cooldowns.Remove(kvp.Key);
                    }
                }
            }
            void OnDestroy() {
                if (!Interface.Oxide.IsShuttingDown) Instance?.SaveData();
                InvokeHandler.CancelInvoke(this, TimerTick);
            }
        }
        class StoredData {
            public Dictionary<ulong, double> Cooldowns = new Dictionary<ulong, double>();
            public Dictionary<ulong, int> UsesToday = new Dictionary<ulong, int>();
            public Hash<ulong, Hash<string, Vector3Serialized>> Locations = new Hash<ulong, Hash<string, Vector3Serialized>>();
            public class Vector3Serialized {
                public float x, y, z;
                public Vector3Serialized() {
                }
                public Vector3Serialized(Vector3 v) {
                    this.x = v.x;
                    this.y = v.y;
                    this.z = v.z;
                }
                public static implicit operator Vector3(Vector3Serialized v) {
                    return new Vector3(v.x, v.y, v.z);
                }
            }
        }
        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 regular permissions
            permission.RegisterPermission(permUse, this);
            permission.RegisterPermission(permCancel, this);
            permission.RegisterPermission(permBack, this);
            permission.RegisterPermission(permHere, this);
            permission.RegisterPermission(permSleepers, this);
            permission.RegisterPermission(permAutoAccept, this);
            permission.RegisterPermission(permLocation, this);
            // Register config permissions
            foreach (string perm in ConfigFile.Cooldowns.Keys) if (!permission.PermissionExists(perm, this)) permission.RegisterPermission(perm, this);
            foreach (string perm in ConfigFile.DailyLimit.Keys) if (!permission.PermissionExists(perm, this)) permission.RegisterPermission(perm, this);
            foreach (string perm in ConfigFile.TimeUntilTeleport.Keys) if (!permission.PermissionExists(perm, this)) permission.RegisterPermission(perm, this);
            lang.RegisterMessages(new Dictionary<string, string>() {
                {
                    "NoPermission", "You do not have permission to use this command."
                }
                , {
                    "TeleportTitle", "Teleport"
                }
                , {
                    "SettingsTitle", "Settings"
                }
                , {
                    "RequestSent", "Teleport request sent to {0}."
                }
                , {
                    "HereRequestSent", "Teleport here request sent to {0}."
                }
                , {
                    "RequestRecieved", "Teleport request from {0}.Open the teleport GUI (/tp) to accept."
                }
                , {
                    "HereRequestRecieved", "Teleport here request from {0}.Open the teleport GUI (/tp) to accept."
                }
                , {
                    "RequestToTimedOut", "Your teleport request to {0} timed out."
                }
                , {
                    "HereRequestToTimedOut", "Your teleport here request to {0} timed out."
                }
                , {
                    "RequestFromTimedOut", "The teleport request from {0} timed out."
                }
                , {
                    "HereRequestFromTimedOut", "The teleport here request from {0} timed out."
                }
                , {
                    "HasPendingRequest", "{0} already has a pending teleport request."
                }
                , {
                    "RequestFrom", "Request from {0}"
                }
                , {
                    "RequestToAccepted", "Your teleport request to {0} was accepted.Teleporting in {1} seconds."
                }
                , {
                    "RequestFromAccepted", "Teleport request from {0} accepted.Telporting in {1} seconds."
                }
                , {
                    "RequestToDenied", "Your teleport request to {0} was denied."
                }
                , {
                    "HereRequestToDenied", "Your teleport here request to {0} was denied."
                }
                , {
                    "RequestFromDenied", "Teleport request from {0} denied."
                }
                , {
                    "HereRequestFromDenied", "Teleport here request from {0} denied."
                }
                , {
                    "YouTeleportedTo", "You teleported to {0}."
                }
                , {
                    "TeleportedToYou", "{0} teleported to you."
                }
                , {
                    "OnCooldown", "Your teleport is on cooldown for {0} seconds."
                }
                , {
                    "NoPendingRequests", "You don't have any pending requests."
                }
                , {
                    "SyntaxTPR", "Incorrect usage! /tpr {name}"
                }
                , {
                    "PlayerNotFound", "The player \"{0}\" was not found."
                }
                , {
                    "PlayerIDNotFound", "A player with the user ID {0} was not found."
                }
                , {
                    "MultiplePlayersFound", "Multiple players were found with the name {0}: {1}"
                }
                , {
                    "CantTeleportToSelf", "You can't teleport to yourself, silly!"
                }
                , {
                    "PlayerIsBuildBlocked", "You may not use teleport whilst building blocked!"
                }
                , {
                    "TargetIsBuildBlocked", "The person you're trying to teleport to is building blocked."
                }
                , {
                    "LocationIsBuildBlocked", "You are building blocked in the location you're trying to teleport to."
                }
                , {
                    "PlayerIsBleeding", "You may not use teleport whilst bleeding."
                }
                , {
                    "CantAffordEconomics", "You can't afford this! Price: ${0}"
                }
                , {
                    "EconomicsYouSpent", "You spent ${0} on this teleport."
                }
                , {
                    "EconomicsRefunded", "You were refunded ${0}."
                }
                , {
                    "CantAffordServerRewards", "You can't afford this! Price: {0}RP"
                }
                , {
                    "ServerRewardsYouSpent", "You spent {0}RP on this teleport."
                }
                , {
                    "ServerRewardsRefunded", "You were refunded {0}RP."
                }
                , {
                    "BlockTPCrafting", "You may not use teleport whilst crafting."
                }
                , {
                    "MaxTeleportsReached", "You have reached your max teleports for today."
                }
                , {
                    "TeleportsRemaining", "{0} teleports remaining today."
                }
                , {
                    "TeleportRequestFromCancelled", "Teleport request from {0} cancelled."
                }
                , {
                    "TeleportRequestToCancelled", "Teleport request to {0} cancelled."
                }
                , {
                    "TeleportRequestCancelled", "Teleport request cancelled."
                }
                , {
                    "TeleportToCancelled", "Teleport to {0} cancelled."
                }
                , {
                    "TeleportFromCancelled", "Teleport from {0} cancelled."
                }
                , {
                    "NoBackLocation", "You have no previous location to return to."
                }
                , {
                    "TeleportedBack", "Teleported back to your previous location."
                }
                , {
                    "SyntaxTPRHere", "Incorrect usage! /tprhere {name}"
                }
                , {
                    "TPPos-InvalidSyntax", "Incorrect usage! /tp {x} {y} {z}"
                }
                , {
                    "TPToPos", "Teleported to {x}, {y}, {z}"
                }
                , {
                    "NothingToCancel", "You have no teleports to cancel."
                }
                , {
                    "CantTeleportFromZone", "You may not teleport out of a ZoneManager zone."
                }
                , {
                    "CantTeleportToZone", "You may not teleport into a ZoneManager zone."
                }
                , {
                    "CantTPWhilstWounded", "You may not TP whilst wounded."
                }
                , {
                    "IsEscapeBlocked", "You are currently escape blocked and may not teleport."
                }
                , {
                    "TargetIsEscapeBlocked", "The player you are trying to teleport to is currently escape blocked."
                }
                , {
                    "PlayerIsOnCargoShip", "You may not teleport whilst on a cargoship."
                }
                , {
                    "TargetIsOnCargoShip", "You may not teleport to a player on a cargoship."
                }
                , {
                    "PlayerIsOnHotAirBalloon", "You may not teleport whilst on a hot air balloon."
                }
                , {
                    "TargetIsOnHotAirBalloon", "You may not teleport to a player who is in a hot air balloon."
                }
                , {
                    "PlayerIsNearOilRig", "You may not teleport whilst within 100m of an oil rig."
                }
                , {
                    "TargetIsNearOilRig", "You may not teleport to a player who is within 100m of an oil rig."
                }
                , {
                    "TargetHasDied", "The target player has died."
                }
                , {
                    "SummonedToYou", "{0} has been summoned to you."
                }
                , {
                    "SummonedTo", "You have been summoned to {0}."
                }
                , {
                    "DailyLimitRemainingGUI", "Daily Limit Remaining: {0}"
                }
                , {
                    "InstantRequestToAccepted", "Your request to {0} was accepted as the player has auto-accept enabled."
                }
                , {
                    "InstantRequestFromAccepted", "The request from {0} was accepted as you have auto-accept enabled."
                }
                , {
                    "PlayerIsMounted", "You may not teleport whilst mounted"
                }
                , {
                    "TargetIsMounted", "You may not teleport to a player who is mounted"
                }
                , {
                    "NoLocationArguments", "You must specify a location name."
                }
                , {
                    "NoLocationsSet", "You do not have any locations set."
                }
                , {
                    "NoLocationName", "You do not have a location saved with the name {0}.Type /tpllist to view your saved locations."
                }
                , {
                    "LocationSaved", "You have saved your current position as a location with the name {0}."
                }
                , {
                    "LocationList", "Saved Locations; {0}"
                }
                ,
            }
            , this, "en");
            ReadData();
            foreach (string cmdAlias in ConfigFile.TPCommandAliases) cmd.AddChatCommand(cmdAlias, this, "tpCommand");
            timer.Once(TimeUntilMidnight(), () => ResetDailyUses());
            if (DebuggingMode) {
                foreach (BasePlayer player in BasePlayer.activePlayerList) ShowTeleportUI(player);
            }
        }
        void OnServerInitialized() {
            Instance = this;
            CooldownManager.Create();
            if (Economics == null && ConfigFile.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 && ConfigFile.UseServerRewardsPlugin) {
                Debug.LogError("[TeleportGUI] Error! ServerRewards is enabled in the config but is not installed! Please install ServerRewards or disable 'UseServerRewardsPlugin' in the config!");
            }
            if (!ConfigFile.UseEconomicsPlugin && !ConfigFile.UseServerRewardsPlugin && ConfigFile.PayAfterUsingDailyLimits) {
                Debug.LogError("[TeleportGUI] Error! PayAfterUsingDailyLimits is set in the config, but neither UseEconomicsPlugin or UseServerRewardsPlugin is set! Please fix this error before loading TeleportGUI again.Unloading...");
                Interface.Oxide.UnloadPlugin(this.Title);
                return;
            }
            OilRigs = UnityEngine.Object.FindObjectsOfType<MonumentInfo>().Where(x => x.gameObject.name.ToLower().Contains("oilrig")).Select(x => x.transform.position).ToList();
        }
        void OnPlayerDisconnected(BasePlayer player) {
            if (HasComponent<Teleporter>(player)) player.GetComponent<Teleporter>().CancelTeleport();
            if (HasComponent<PendingRequest>(player)) UnityEngine.Object.Destroy(player.GetComponent<PendingRequest>());
        }
        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 (!ConfigFile.CancelTeleportOnDamage) return;
            var teleporter = player.gameObject.GetComponent<Teleporter>();
            teleporter.CancelTeleport();
        }
        void Unload() {
            DestroyAllOfType<Teleporter>(false);
            DestroyAllOfType<PendingRequest>(false);
            DestroyAllOfType<CooldownManager>(true);
            foreach (BasePlayer player in BasePlayer.activePlayerList) CloseUI(player);
            GUIManager.Players.Clear();
            if (!Interface.Oxide.IsShuttingDown) SaveData();
            Instance = null;
        }
#endregion
#region Config
        ConfigData ConfigFile;
        class ConfigData {
            public bool PrefixEnabled = true;
            public string PrefixText = "<color=orange>TP: </color>";
            public int DefaultTimeUntilTeleport = 15;
            public Dictionary<string, int> TimeUntilTeleport = new Dictionary<string, int>() {
                {
                    "teleportgui.vip", 10
                }
                , {
                    "teleportgui.elite", 5
                }
                , {
                    "teleportgui.god", 3
                }
                , {
                    "teleportgui.none", 0
                }
            }
            ;
            public List<string> TPCommandAliases = new List<string>() {
            }
            ;
            public double RequestTimeoutTime = 30;
            public double DefaultCooldown = 180;
            public Dictionary<string, double> Cooldowns = new Dictionary<string, double>() {
                {
                    "teleportgui.vip", 60
                }
                , {
                    "teleportgui.elite", 30
                }
                , {
                    "teleportgui.god", 15
                }
                , {
                    "teleportgui.none", 0
                }
            }
            ;
            public int DefaultDailyLimit = 3;
            public Dictionary<string, int> DailyLimit = new Dictionary<string, int>() {
                {
                    "teleportgui.vip", 5
                }
                , {
                    "teleportgui.elite", 8
                }
                , {
                    "teleportgui.god", 15
                }
                , {
                    "teleportgui.none", 9999
                }
            }
            ;
            public bool AdminTPSilent = false;
            public bool AdminTPEnabled = false;
            public bool AllowTeleportWhilstBleeding = false;
            public bool AllowTeleportToBuildBlockedPlayer = false;
            public bool AllowTeleportFromBuildBlock = false;
            public bool AllowTeleportToRaidBlockedPlayer = true;
            public bool AllowTeleportFromCargoShip = false;
            public bool AllowTeleportFromHotAirBalloon = false;
            public bool AllowTeleportFromOilRig = false;
            public bool AllowTeleportToOilRig = false;
            public bool UseEconomicsPlugin = false;
            public double EconomicsPrice = 100;
            public bool UseServerRewardsPlugin = false;
            public int ServerRewardsPrice = 10;
            public bool PayAfterUsingDailyLimits = false;
            public bool BlockTPCrafting = true;
            public bool AllowSpecialCharacters = false;
            public bool CancelTeleportOnDamage = true;
            public bool CanTeleportIntoZone = true;
            public bool CanTeleportFromZone = true;
            public bool AllowAutoAcceptOnHereTPs = false;
            public bool HideAdminsInUI = false;
            public bool AllowTeleportFromMounted = false;
            public bool AllowTeleportToMounted = false;
            public ulong ChatIconID = 0UL;
        }
        protected override void LoadConfig() {
            base.LoadConfig();
            ConfigFile = Config.ReadObject<ConfigData>();
            Config.WriteObject(ConfigFile, true);
        }
        protected override void LoadDefaultConfig() => ConfigFile = new ConfigData();
        protected override void SaveConfig() => Config.WriteObject(ConfigFile, true);
#endregion
#region Commands
        [ChatCommand("tpsave")]
        void TPSaveCommand(BasePlayer player, string command, string[] args) {
            if (!HasPerm(player, permLocation)) {
                SendReply(player, GetMessage("NoPermission"));
                return;
            }
            if (args.Length == 0) {
                SendReply(player, GetMessage("NoLocationArguments"));
                return;
            }
            Hash<string, StoredData.Vector3Serialized> locations;
            if (!storedData.Locations.TryGetValue(player.userID, out locations)) locations = storedData.Locations[player.userID] = new Hash<string, StoredData.Vector3Serialized>();
            locations[args[0]] = new StoredData.Vector3Serialized(player.transform.position);
            SendReply(player, GetMessage("LocationSaved", args[0]));
        }
        [ChatCommand("tpl")]
        void TPLCommand(BasePlayer player, string command, string[] args) {
            if (!HasPerm(player, permLocation)) {
                SendReply(player, GetMessage("NoPermission"));
                return;
            }
            if (args.Length == 0) {
                SendReply(player, GetMessage("NoLocationArguments"));
                return;
            }
            Hash<string, StoredData.Vector3Serialized> locations;
            if (!storedData.Locations.TryGetValue(player.userID, out locations)) {
                SendReply(player, GetMessage("NoLocationsSet"));
                return;
            }
            StoredData.Vector3Serialized position;
            if (!locations.TryGetValue(args[0], out position)) {
                SendReply(player, GetMessage("NoLocationName", args[0]));
                return;
            }
            Teleport(player, position);
        }
        [ChatCommand("tpllist")]
        void TPLListCommand(BasePlayer player, string command, string[] args) {
            if (!HasPerm(player, permLocation)) {
                SendReply(player, GetMessage("NoPermission"));
                return;
            }
            Hash<string, StoredData.Vector3Serialized> locations;
            if (!storedData.Locations.TryGetValue(player.userID, out locations)) {
                SendReply(player, GetMessage("NoLocationsSet"));
                return;
            }
            SendReply(player, GetMessage("LocationList", locations.Keys.ToSentence()));
        }
        [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 == 1) {
                    List<BasePlayer> matches = FindByNameOrUIDMulti(args[0]);
                    if (matches.Count() == 0) {
                        SendReply(player, GetMessage("PlayerNotFound").Replace("{0}", args[0]));
                        return;
                    }
                    else if (matches.Count() > 1) {
                        string allNames = string.Join(", ", matches.Select(p => p.displayName).ToArray());
                        SendReply(player, GetMessage("MultiplePlayersFound").Replace("{0}", args[0]).Replace("{1}", allNames));
                        return;
                    }
                    BasePlayer targetPlayer = matches.First();
                    Teleport(player, targetPlayer.transform.position);
                    SendReply(player, Instance.GetMessage("YouTeleportedTo").Replace("{0}", targetPlayer.displayName));
                    return;
                }
                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 = string.Join(" ", args);
            List<BasePlayer> matches = FindByNameOrUIDMulti(name);
            if (matches.Count() == 0) {
                SendReply(player, GetMessage("PlayerNotFound").Replace("{0}", name));
                return;
            }
            else if (matches.Count() > 1) {
                string allNames = string.Join(", ", matches.Select(x => x.displayName).ToArray());
                SendReply(player, GetMessage("MultiplePlayersFound").Replace("{0}", name).Replace("{1}", allNames));
                return;
            }
            BasePlayer targetPlayer = matches.First();
            if (targetPlayer == player && !DebuggingMode) {
                SendReply(player, GetMessage("CantTeleportToSelf"));
                return;
            }
            TPR(player, targetPlayer, false);
            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("tprhere")]
        void TPRHereCommand(BasePlayer player, string command, string[] args) {
            if (!HasPerm(player, permHere)) {
                SendReply(player, GetMessage("NoPermission"));
                return;
            }
            if (args.Length < 1) {
                SendReply(player, GetMessage("SyntaxTPRHere"));
                return;
            }
            string targetName = string.Join(" ", args);
            List<BasePlayer> matches = FindByNameOrUIDMulti(targetName);
            if (matches.Count() == 0) {
                SendReply(player, GetMessage("PlayerNotFound").Replace("{0}", targetName));
                return;
            }
            if (matches.Count > 1) {
                string allNames = string.Join(", ", matches.Select(x => x.displayName).ToArray());
                SendReply(player, GetMessage("MultiplePlayersFound").Replace("{0}", targetName).Replace("{1}", allNames));
                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[] {
            }
            ;
            var guiSettings = GUIManager.Get(player);
#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;
                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));
                    Teleport(player, target);
                    return;
                }
                BasePlayer targetPlayer = BasePlayer.FindByID(userID);
                if (targetPlayer == null) {
                    SendReply(player, GetMessage("PlayerIDNotFound").Replace("{0}", userIDString));
                    return;
                }
                TPR(player, targetPlayer, false);
                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) {
                    SendR
// ... [Code preview truncated due to length. Full source in attached file] ...

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

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

Сверху