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

FREE NTeleportation : 1.9.6 1.9.6

Нет прав для скачивания
C#:
//#define TPDEBUG
using Facepunch;
using Network;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Oxide.Core;
using Oxide.Core.Configuration;
using Oxide.Core.Libraries.Covalence;
using Oxide.Core.Plugins;
using Oxide.Game.Rust;
using Oxide.Game.Rust.Cui;
using Oxide.Plugins.NTeleportationExtensionMethods;
using Rust;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Reflection;
using UnityEngine;
namespace Oxide.Plugins {
    [Info("NTeleportation", "nivex", "1.9.6")]
    [Description("Multiple teleportation systems for admin and players")]
    class NTeleportation : RustPlugin {
        [PluginReference]
        private Plugin Clans, Economics, IQEconomic, ServerRewards, Friends, CompoundTeleport, ZoneManager, NoEscape, RaidBlock, PopupNotifications, BlockUsers;
        private Dictionary<string, BasePlayer> _codeToPlayer = new();
        private Dictionary<string, string> _playerToCode = new();
        private bool newSave;
        private const string NewLine = "\n";
        private const string TPA = "tpa";
        private readonly string[] emptyArg = Array.Empty<string>();
        private const string PermAdmin = "nteleportation.admin";
        private const string PermRestrictions = "nteleportation.norestrictions";
        private const string ConfigDefaultPermVip = "nteleportation.vip";
        private const string PermHome = "nteleportation.home";
        private const string PermWipeHomes = "nteleportation.wipehomes";
        private const string PermCraftHome = "nteleportation.crafthome";
        private const string PermCaveHome = "nteleportation.cavehome";
        private const string PermDeleteHome = "nteleportation.deletehome";
        private const string PermHomeHomes = "nteleportation.homehomes";
        private const string PermImportHomes = "nteleportation.importhomes";
        private const string PermRadiusHome = "nteleportation.radiushome";
        private const string PermCraftTpR = "nteleportation.crafttpr";
        private const string PermCaveTpR = "nteleportation.cavetpr";
        private const string PermTpR = "nteleportation.tpr";
        private const string PermTpA = "nteleportation.tpa";
        private const string PermTp = "nteleportation.tp";
        private const string PermDisallowTpToMe = "nteleportation.disallowtptome";
        private const string PermTpT = "nteleportation.tpt";
        private const string PermTpB = "nteleportation.tpb";
        private const string PermTpN = "nteleportation.tpn";
        private const string PermTpL = "nteleportation.tpl";
        private const string PermTpConsole = "nteleportation.tpconsole";
        private const string PermTpRemove = "nteleportation.tpremove";
        private const string PermTpSave = "nteleportation.tpsave";
        private const string PermExempt = "nteleportation.exemptfrominterruptcountdown";
        private const string PermFoundationCheck = "nteleportation.bypassfoundationcheck";
        private const string PermTpMarker = "nteleportation.tpmarker";
        private DynamicConfigFile dataConvert;
        private DynamicConfigFile dataDisabled;
        private DynamicConfigFile dataAdmin;
        private DynamicConfigFile dataHome;
        private DynamicConfigFile dataTPR;
        private DynamicConfigFile dataTPT;
        private Dictionary<ulong, AdminData> _Admin;
        private Dictionary<ulong, HomeData> _Home;
        private Dictionary<ulong, TeleportData> _TPR;
        private Dictionary<string, List<string>> TPT = new();
        private bool changedAdmin;
        private bool changedHome;
        private bool changedTPR;
        private bool changedTPT;
        private float boundary;
        private readonly Dictionary<ulong, float> TeleportCooldowns = new();
        private readonly Dictionary<ulong, BasePlayer> PlayersRequests = new();
        private readonly Dictionary<int, string> ReverseBlockedItems = new();
        private readonly Dictionary<ulong, Vector3> teleporting = new();
        private SortedDictionary<string, Vector3> caves = new();
        private readonly List<TeleportTimer> TeleportTimers = new();
        private readonly List<PendingRequest> PendingRequests = new();
        private List<PrefabInfo> monuments = new();
        private bool outpostEnabled;
        private bool banditEnabled;
        private bool deepseaEnabled;
        private class PrefabInfo {
            public Quaternion rotation;
            public Vector2 positionXZ;
            public Vector3 position;
            public Vector3 extents;
            public string name;
            public string prefab;
            public bool sphere;
            public PrefabInfo() {
            }
            public PrefabInfo(Vector3 position, Quaternion rotation, Vector3 extents, float extra, string name, string prefab, bool sphere) {
                this.sphere = sphere;
                this.position = position;
                this.rotation = rotation;
                this.name = name;
                this.prefab = prefab;
                this.extents = extents + new Vector3(extra, extra, extra);
                positionXZ = position.XZ2D();
            }
            public bool IsInBounds(Vector3 a) {
                if (sphere) {
                    if (a.y > position.y + (extents.y * 1.75f)) {
                        return false;
                    }
                    return Vector3Ex.Distance2D(a, position) <= extents.Max();
                }
                Vector3 v = Quaternion.Inverse(rotation) * (a - position);
                return v.x <= extents.x && v.x > -extents.x && v.y <= extents.y && v.y > -extents.y && v.z <= extents.z && v.z > -extents.z;
            }
            public string Formatted() => sphere ? $"radius: {extents.Max()}" : $"extents: {extents}";
        }
#region Configuration
        private static Configuration config;
        public class InterruptSettings {
            [JsonProperty(PropertyName = "Interrupt Teleport At Specific Monuments", ObjectCreationHandling = ObjectCreationHandling.Replace)]
            public List<string> Monuments = new List<string>();
            [JsonProperty(PropertyName = "Above Water")]
            public bool AboveWater = true;
            [JsonProperty(PropertyName = "Under Water")]
            public bool UnderWater;
            [JsonProperty(PropertyName = "Balloon")]
            public bool Balloon = true;
            [JsonProperty(PropertyName = "Boats")]
            public bool Boats;
            [JsonProperty(PropertyName = "Cargo Ship")]
            public bool Cargo = true;
            [JsonProperty(PropertyName = "Cold")]
            public bool Cold = false;
            [JsonProperty(PropertyName = "Excavator")]
            public bool Excavator = false;
            [JsonProperty(PropertyName = "Hot")]
            public bool Hot = false;
            [JsonProperty(PropertyName = "Hostile")]
            public bool Hostile = false;
            [JsonProperty(PropertyName = "Hostile Includes Towns")]
            public bool IncludeHostileTown = true;
            [JsonProperty(PropertyName = "Hurt")]
            public bool Hurt = true;
            [JsonProperty(PropertyName = "Junkpiles")]
            public bool Junkpiles;
            [JsonProperty(PropertyName = "Lift")]
            public bool Lift = true;
            [JsonProperty(PropertyName = "Monument")]
            public bool Monument = false;
            [JsonProperty(PropertyName = "Ignore Monument Marker Prefab")]
            public bool BypassMonumentMarker = false;
            [JsonProperty(PropertyName = "Mounted")]
            public bool Mounted = true;
            [JsonProperty(PropertyName = "Oil Rig")]
            public bool Oilrig = false;
            [JsonProperty(PropertyName = "Safe Zone")]
            public bool Safe = true;
            [JsonProperty(PropertyName = "Swimming")]
            public bool Swimming = false;
            [JsonProperty(PropertyName = "Fall")]
            public bool Fall = true;
            internal bool OnEntityTakeDamage => Hurt || Cold || Hot || Fall;
        }
        private void OnPlayerSleep(BasePlayer player) {
            DelayedTeleportHome(player);
        }
        private readonly List<(Vector3 position, float sqrDistance)> safeZones = new();
        private readonly List<ApartmentRoom> _rooms = new();
        private readonly List<ApartmentBuilding> _apartmentBuildings = new();
        private ApartmentBuilding GetApartmentBuilding() {
            if (_apartmentBuildings.Count == 0) {
                foreach (var triggerSafeZone in TriggerSafeZone.allSafeZones) {
                    if (triggerSafeZone.Apartment == null) continue;
                    _apartmentBuildings.Add(triggerSafeZone.Apartment);
                }
            }
            return _apartmentBuildings.Count > 0 ? _apartmentBuildings[0] : null;
        }
        private bool TryGetApartmentRoom(BasePlayer player, out ApartmentRoom room) {
            room = null;
            if (player == null || player.IsDestroyed) return false;
            if (_rooms.Count == 0) {
                foreach (var triggerSafeZone in TriggerSafeZone.allSafeZones) {
                    if (triggerSafeZone?.triggerCollider == null) continue;
                    if (triggerSafeZone.Apartment?.rooms == null) continue;
                    _apartmentBuildings.Add(triggerSafeZone.Apartment);
                    _rooms.AddRange(triggerSafeZone.Apartment.rooms);
                }
            }
            foreach (var _room in _rooms) {
                if (_room == null || _room.IsDestroyed || _room.owners == null) continue;
                if (!_room.IsCurrentlyRented() || !_room.IsInsideRoom(player)) continue;
                room = _room;
                return true;
            }
            return false;
        }
        private bool IsInsideApartmentRoom(BasePlayer player) {
            if (!TryGetApartmentRoom(player, out var room)) {
                return false;
            }
            if (room.owners.Contains(player.userID)) {
                return true;
            }
            foreach (var owner in room.owners) {
                if (IsAlly(player, owner, config.Home.UseTeams, config.Home.UseClans, config.Home.UseFriends)) {
                    return true;
                }
            }
            return false;
        }
        private bool IsInApartmentComplex(Vector3 v) => apartments != null && apartments.IsInBounds(v);
        private bool IsSafeZone(Vector3 a, float extra = 0f)  //
        {
            if (safeZones.Count == 0) {
                foreach (var triggerSafeZone in TriggerSafeZone.allSafeZones) {
                    float radius = (triggerSafeZone.triggerCollider == null ? 25f : ColliderEx.GetRadius(triggerSafeZone.triggerCollider, triggerSafeZone.transform.localScale)) + extra;
                    Vector3 center = triggerSafeZone.triggerCollider?.bounds.center ?? triggerSafeZone.transform.position;
                    safeZones.Add((center, radius * radius));
                }
            }
            foreach (var zone in safeZones) {
                if ((zone.position - a).sqrMagnitude <= zone.sqrDistance) {
                    return true;
                }
            }
            return false;
        }
        public bool IsAuthed(BasePlayer player, BuildingPrivlidge priv) => (priv.OwnerID == player.userID && config.Home.UsableIntoBuildingBlocked) || config.Home.UsableIntoBuildingBlocked || priv.IsAuthed(player);
        private HashSet<ulong> delayedTeleports = new();
        public void DelayedTeleportHome(BasePlayer player) {
            if (player == null || player.IsDead() || CanBuild(player, false)) {
                return;
            }
            ulong userid = player.userID;
            if (!delayedTeleports.Add(userid)) {
                return;
            }
            ServerMgr.Instance.Invoke(() => {
                if (player.IsKilled() || player.IsDead() || player.IsConnected) {
                    delayedTeleports.Remove(userid);
                    return;
                }
                if (IsInsideApartmentRoom(player)) {
                    delayedTeleports.Remove(userid);
                    return;
                }
                bool inSafeZone = IsSafeZone(player.transform.position);
                if (inSafeZone && config.Settings.TeleportHomeSafeZone <= 0f) {
                    delayedTeleports.Remove(userid);
                    return;
                }
                if (!inSafeZone && config.Settings.TeleportHome <= 0f) {
                    delayedTeleports.Remove(userid);
                    return;
                }
                float time = inSafeZone ? config.Settings.TeleportHomeSafeZone : config.Settings.TeleportHome;
                ServerMgr.Instance.Invoke(() => {
                    if (!delayedTeleports.Remove(userid) || player.IsKilled() || player.IsConnected || inSafeZone && !IsSafeZone(player.transform.position)) {
                        return;
                    }
                    TeleportHome(player, true);
                }
                , time);
            }
            , 0.2f);
        }
        private object OnPlayerRespawn(BasePlayer player) {
            if (player == null) return null;
            var settings = GetSettings(outpostCommand);
            if (settings == null || settings.Location == Vector3.zero) return null;
            if (Interface.Oxide.CallHook("CanTeleport", player, settings.Location) != null) return null;
            RemoveHostility(player);
            return new BasePlayer.SpawnPoint {
                pos = settings.Location, rot = Quaternion.identity
            }
            ;
        }
        private static void RemoveHostility(BasePlayer player) {
            if (player.State.unHostileTimestamp > TimeEx.currentTimestamp) {
                player.State.unHostileTimestamp = TimeEx.currentTimestamp;
                player.DirtyPlayerState();
                player.ClientRPC(RpcTarget.Player("SetHostileLength", player), 0f);
            }
            if (player.unHostileTime > Time.realtimeSinceStartup) {
                player.unHostileTime = Time.realtimeSinceStartup;
            }
        }
        public class MonumentMarkerDi {
            [JsonProperty("width")]
            public float x;
            [JsonProperty("height")]
            public float y;
            [JsonProperty("depth")]
            public float z;
            [JsonProperty("radius")]
            public float radius = 0f;
            [JsonProperty("enabled")]
            public bool enabled;
            public bool GetRadiusOrSize(out float x, out float y, out float z, out float r) {
                if (enabled) {
                    if (this.x > 0f && this.y > 0f && this.z > 0f) {
                        r = 0f;
                        x = this.x;
                        y = this.y;
                        z = this.z;
                        return true;
                    }
                    if (radius > 0f) {
                        x = y = z = 0f;
                        r = radius;
                        return true;
                    }
                }
                x = y = z = r = 0f;
                return false;
            }
        }
        public class PluginSettings {
            [JsonProperty(PropertyName = "Delay Saving Data On Server Save")]
            public double SaveDelay = 4.0;
            [JsonProperty("TPB")]
            public TPBSettings TPB = new();
            [JsonProperty(PropertyName = "Interrupt TP")]
            public InterruptSettings Interrupt = new();
            [JsonProperty(PropertyName = "Auto Wake Up After Teleport")]
            public bool AutoWakeUp;
            [JsonProperty(PropertyName = "Seconds Until Teleporting Home Offline Players Within SafeZones")]
            public float TeleportHomeSafeZone;
            [JsonProperty(PropertyName = "Seconds Until Teleporting Home Offline Players")]
            public float TeleportHome;
            [JsonProperty(PropertyName = "Respawn Players At Outpost")]
            public bool RespawnOutpost;
            [JsonProperty(PropertyName = "Block Teleport (NoEscape)")]
            public bool BlockNoEscape;
            [JsonProperty(PropertyName = "Block Teleport (RaidBlock)")]
            public bool RaidBlock;
            [JsonProperty(PropertyName = "Block Teleport (ZoneManager)")]
            public bool BlockZoneFlag;
            [JsonProperty(PropertyName = "Block Map Marker Teleport (AbandonedBases)")]
            public bool BlockAbandoned;
            [JsonProperty(PropertyName = "Block Map Marker Teleport (RaidableBases)")]
            public bool BlockRaidable;
            [JsonProperty(PropertyName = "Automatically Destroy Map Teleport Markers")]
            public bool DestroyMarker;
            [JsonProperty(PropertyName = "Chat Name")]
            public string ChatName = "<color=red>Teleportation</color> \n\n";
            [JsonProperty(PropertyName = "Chat Steam64ID")]
            public ulong ChatID = 76561199056025689;
            [JsonProperty(PropertyName = "Check Boundaries On Teleport X Y Z")]
            public bool CheckBoundaries = true;
            [JsonProperty(PropertyName = "Check Boundaries Min Height")]
            public float BoundaryMin = -100f;
            [JsonProperty(PropertyName = "Check Boundaries Max Height")]
            public float BoundaryMax = 2000f;
            [JsonProperty(PropertyName = "Check If Inside Rock")]
            public bool Rock = true;
            [JsonProperty(PropertyName = "Height To Prevent Teleporting To/From (0 = disabled)")]
            public float ForcedBoundary;
            [JsonProperty(PropertyName = "Data File Directory (Blank = Default)")]
            public string DataFileFolder = string.Empty;
            [JsonProperty(PropertyName = "Draw Sphere On Set Home")]
            public bool DrawHomeSphere = true;
            [JsonProperty(PropertyName = "Homes Enabled")]
            public bool HomesEnabled = true;
            [JsonProperty(PropertyName = "TPR Enabled")]
            public bool TPREnabled = true;
            [JsonProperty(PropertyName = "Strict Foundation Check")]
            public bool StrictFoundationCheck = false;
            [JsonProperty(PropertyName = "Minimum Temp")]
            public float MinimumTemp = 0f;
            [JsonProperty(PropertyName = "Maximum Temp")]
            public float MaximumTemp = 40f;
            [JsonProperty(PropertyName = "Blocked Items", ObjectCreationHandling = ObjectCreationHandling.Replace)]
            public Dictionary<string, string> BlockedItems = new(StringComparer.OrdinalIgnoreCase);
            //{
            //    ["explosive.timed"] = "You cannot teleport with C4!",
            //    ["gunpowder"] = "You cannot teleport with gun powder!",
            //    ["explosives"] = "You cannot teleport with explosives!",
            //};
            [JsonProperty(PropertyName = "Blocked Town Prefabs", ObjectCreationHandling = ObjectCreationHandling.Replace)]
            public List<string> BlockedPrefabs = new();
            [JsonProperty(PropertyName = "Bypass CMD")]
            public string BypassCMD = "pay";
            [JsonProperty(PropertyName = "Use Economics")]
            public bool UseEconomics = false;
            [JsonProperty(PropertyName = "Use Server Rewards")]
            public bool UseServerRewards = false;
            [JsonProperty(PropertyName = "Custom monument marker dimensions", ObjectCreationHandling = ObjectCreationHandling.Replace)]
            public Dictionary<string, MonumentMarkerDi> Dimensions = new(StringComparer.OrdinalIgnoreCase) {
                ["Data Center 1"]
                = new() {
                    x = 0f, y = 0f, z = 0f, radius = 0f, enabled = false
                }
                , ["Data Center 2"] = new() {
                    x = 0f, y = 0f, z = 0f, radius = 0f, enabled = false
                }
                , ["Data Center 3"] = new() {
                    x = 0f, y = 0f, z = 0f, radius = 0f, enabled = false
                }
                ,
            }
            ;
            [JsonProperty(PropertyName = "Additional monuments to exclude (experimental)", ObjectCreationHandling = ObjectCreationHandling.Replace)]
            public List<string> MonumentsToExclude = new() {
                "lake", "canyon", "oasis", "jungle swamp", "jungle ruin"
            }
            ;
            [JsonProperty(PropertyName = "Wipe On Upgrade Or Change")]
            public bool WipeOnUpgradeOrChange = true;
            [JsonProperty(PropertyName = "Auto Generate DeepSea Location")]
            public bool AutoGenDeepSea = true;
            [JsonProperty(PropertyName = "Auto Generate Outpost Location")]
            public bool AutoGenOutpost = true;
            [JsonProperty(PropertyName = "Outpost Map Prefab", ObjectCreationHandling = ObjectCreationHandling.Replace)]
            public List<string> Outpost = new() {
                "outpost", "compound"
            }
            ;
            [JsonProperty(PropertyName = "Auto Generate Bandit Location")]
            public bool AutoGenBandit = true;
            [JsonProperty(PropertyName = "Bandit Map Prefab", ObjectCreationHandling = ObjectCreationHandling.Replace)]
            public List<string> Bandit = new() {
                "bandit_town"
            }
            ;
            [JsonProperty(PropertyName = "Show Time As Seconds Instead")]
            public bool UseSeconds = false;
            [JsonProperty(PropertyName = "Use Quick Teleport")]
            public bool Quick = true;
            [JsonProperty(PropertyName = "Chat Command Color")]
            public string ChatCommandColor = "#FFFF00";
            [JsonProperty(PropertyName = "Chat Command Argument Color")]
            public string ChatCommandArgumentColor = "#FFA500";
            [JsonProperty("Enable Popup Support")]
            public bool UsePopup = false;
            [JsonProperty("Send Messages To Player")]
            public bool SendMessages = true;
            [JsonProperty("Block All Teleporting From Inside Authorized Base")]
            public bool BlockAuthorizedTeleporting = false;
            [JsonProperty("Global Teleport Cooldown")]
            public float Global = 0f;
            [JsonProperty("Global VIP Teleport Cooldown")]
            public float GlobalVIP = 0f;
            [JsonProperty("Play Sounds Before Teleport")]
            public bool PlaySoundsBeforeTeleport = true;
            [JsonProperty("Sound Effects Before Teleport", ObjectCreationHandling = ObjectCreationHandling.Replace)]
            public List<string> DisappearEffects = new() {
                "assets/prefabs/missions/portal/proceduraldungeon/effects/disappear.prefab"
            }
            ;
            [JsonProperty("Play Sounds After Teleport")]
            public bool PlaySoundsAfterTeleport = true;
            [JsonProperty("Sound Effects After Teleport", ObjectCreationHandling = ObjectCreationHandling.Replace)]
            public List<string> ReappearEffects = new() {
                "assets/prefabs/missions/portal/proceduraldungeon/effects/appear.prefab"
            }
            ;
        }
        public class TPBSettings {
            [JsonProperty(PropertyName = "Block TPB To Specific Monuments", ObjectCreationHandling = ObjectCreationHandling.Replace)]
            public List<string> BlockedMonuments = new();
            [JsonProperty(PropertyName = "VIP Countdowns", ObjectCreationHandling = ObjectCreationHandling.Replace)]
            public Dictionary<string, int> Countdowns = new() {
                {
                    ConfigDefaultPermVip, 0
                }
            }
            ;
            [JsonProperty("Countdown")]
            public int Countdown = 0;
            [JsonProperty("Available After X Seconds")]
            public int Time = 0;
        }
        public class AdminSettings {
            [JsonProperty(PropertyName = "Announce Teleport To Target")]
            public bool AnnounceTeleportToTarget = false;
            [JsonProperty(PropertyName = "Usable By Admins")]
            public bool UseableByAdmins = true;
            [JsonProperty(PropertyName = "Usable By Moderators")]
            public bool UseableByModerators = true;
            [JsonProperty(PropertyName = "Location Radius")]
            public int LocationRadius = 25;
            [JsonProperty(PropertyName = "Teleport Near Default Distance")]
            public int TeleportNearDefaultDistance = 30;
            [JsonProperty(PropertyName = "Extra Distance To Block Monument Teleporting")]
            public int ExtraMonumentDistance;
        }
        public class HomesSettings {
            [JsonProperty(PropertyName = "Homes Limit")]
            public int HomesLimit = 2;
            [JsonProperty(PropertyName = "VIP Homes Limits", ObjectCreationHandling = ObjectCreationHandling.Replace)]
            public Dictionary<string, int> VIPHomesLimits = new() {
                {
                    ConfigDefaultPermVip, 5
                }
            }
            ;
            [JsonProperty(PropertyName = "Allow Sethome At Specific Monuments", ObjectCreationHandling = ObjectCreationHandling.Replace)]
            public List<string> AllowedMonuments = new() {
                "HQM Quarry", "Stone Quarry", "Sulfur Quarry", "Ice Lake", "Wild Swamp"
            }
            ;
            [JsonProperty(PropertyName = "Allow Sethome At All Monuments")]
            public bool AllowAtAllMonuments = false;
            [JsonProperty(PropertyName = "Allow Sethome On Tugboats")]
            public bool AllowTugboats = true;
            [JsonProperty(PropertyName = "Allow Sethome On Player-made Boats")]
            public bool AllowPlayerBoats = true;
            [JsonProperty(PropertyName = "Allow TPB")]
            public bool AllowTPB = true;
            [JsonProperty(PropertyName = "Cooldown")]
            public int Cooldown = 600;
            [JsonProperty(PropertyName = "Countdown")]
            public int Countdown = 15;
            [JsonProperty(PropertyName = "Daily Limit")]
            public int DailyLimit = 5;
            [JsonProperty(PropertyName = "VIP Daily Limits", ObjectCreationHandling = ObjectCreationHandling.Replace)]
            public Dictionary<string, int> VIPDailyLimits = new() {
                {
                    ConfigDefaultPermVip, 5
                }
            }
            ;
            [JsonProperty(PropertyName = "VIP Cooldowns", ObjectCreationHandling = ObjectCreationHandling.Replace)]
            public Dictionary<string, int> VIPCooldowns = new() {
                {
                    ConfigDefaultPermVip, 5
                }
            }
            ;
            [JsonProperty(PropertyName = "VIP Countdowns", ObjectCreationHandling = ObjectCreationHandling.Replace)]
            public Dictionary<string, int> VIPCountdowns = new() {
                {
                    ConfigDefaultPermVip, 5
                }
            }
            ;
            [JsonProperty(PropertyName = "Location Radius")]
            public int LocationRadius = 25;
            [JsonProperty(PropertyName = "Force On Top Of Foundation")]
            public bool ForceOnTopOfFoundation = true;
            [JsonProperty(PropertyName = "Check Foundation For Owner")]
            public bool CheckFoundationForOwner = true;
            [JsonProperty(PropertyName = "Use Friends")]
            public bool UseFriends = true;
            [JsonProperty(PropertyName = "Use Clans")]
            public bool UseClans = true;
            [JsonProperty(PropertyName = "Use Teams")]
            public bool UseTeams = true;
            [JsonProperty(PropertyName = "Usable Out Of Building Blocked")]
            public bool UsableOutOfBuildingBlocked;
            [JsonProperty(PropertyName = "Usable Into Building Blocked")]
            public bool UsableIntoBuildingBlocked;
            [JsonProperty(PropertyName = "Usable From Safe Zone Only")]
            public bool UsableFromSafeZoneOnly;
            [JsonProperty(PropertyName = "Bypass Cooldown From Within Safe Zone")]
            public bool BypassCooldownFromWithinSafeZone;
            [JsonProperty(PropertyName = "Allow Cupboard Owner When Building Blocked")]
            public bool CupOwnerAllowOnBuildingBlocked = true;
            [JsonProperty(PropertyName = "Allow Cupboard Ally When Building Blocked")]
            public bool CupAllyAllowOnBuildingBlocked;
            [JsonProperty(PropertyName = "Allow Cupboard Non-Ally When Building Blocked")]
            public bool CupNonAllyAllowOnBuildingBlocked;
            [JsonProperty(PropertyName = "Block For No Cupboard")]
            public bool BlockForNoCupboard;
            [JsonProperty(PropertyName = "Allow Iceberg")]
            public bool AllowIceberg = false;
            [JsonProperty(PropertyName = "Allow Cave")]
            public bool AllowCave;
            [JsonProperty(PropertyName = "Allow Crafting")]
            public bool AllowCraft = false;
            [JsonProperty(PropertyName = "Allow Above Foundation")]
            public bool AllowAboveFoundation = true;
            [JsonProperty(PropertyName = "Allow Deep Sea")]
            public bool DeepSea = true;
            [JsonProperty(PropertyName = "Allow Apartment Complex")]
            public bool ApartmentComplex = true;
            [JsonProperty(PropertyName = "Check If Home Is Valid On Listhomes")]
            public bool CheckValidOnList = false;
            [JsonProperty(PropertyName = "Pay")]
            public int Pay = 0;
            [JsonProperty(PropertyName = "Bypass")]
            public int Bypass = 0;
            [JsonProperty(PropertyName = "Hours Before Useable After Wipe")]
            public double Hours = 0;
            [JsonProperty(PropertyName = "Remove Hostility")]
            public bool RemoveHostility;
        }
        public class TPTSettings {
            [JsonProperty(PropertyName = "Use Friends")]
            public bool UseFriends;
            [JsonProperty(PropertyName = "Use Clans")]
            public bool UseClans;
            [JsonProperty(PropertyName = "Use Teams")]
            public bool UseTeams;
            [JsonProperty(PropertyName = "Allow Cave")]
            public bool AllowCave;
            [JsonProperty(PropertyName = "Enabled Color")]
            public string EnabledColor = "green";
            [JsonProperty(PropertyName = "Disabled Color")]
            public string DisabledColor = "red";
        }
        // Added `TPR => Play Sounds To Request Target` (false)
        // Added `TPR => Play Sounds When Target Accepts` (false)
        public class DiscordSettings {
            [JsonProperty(PropertyName = "Webhook URL")]
            public string Webhook = "https://support.discordapp.com/hc/en-us/articles/228383668-Intro-to-Webhooks";
            [JsonProperty(PropertyName = "Log When TPA To Non-Ally Players More Than X Times")]
            public int TPA = 3;
        }
        public class TPRSettings {
            [JsonProperty(PropertyName = "Discord")]
            public DiscordSettings Discord = new();
            [JsonProperty("Play Sounds To Request Target")]
            public bool PlaySoundsToRequestTarget;
            [JsonProperty("Teleport Request Sound Effects", ObjectCreationHandling = ObjectCreationHandling.Replace)]
            public List<string> TeleportRequestEffects = new() {
                "assets/prefabs/missions/portal/proceduraldungeon/effects/disappear.prefab"
            }
            ;
            [JsonProperty("Play Sounds When Target Accepts")]
            public bool PlaySoundsWhenTargetAccepts;
            [JsonProperty("Teleport Accept Sound Effects", ObjectCreationHandling = ObjectCreationHandling.Replace)]
            public List<string> TeleportAcceptEffects = new() {
                "assets/prefabs/missions/portal/proceduraldungeon/effects/appear.prefab"
            }
            ;
            [JsonProperty(PropertyName = "Require Player To Be Friend, Clan Mate, Or Team Mate")]
            public bool UseClans_Friends_Teams;
            [JsonProperty(PropertyName = "Require nteleportation.tpa to accept TPR requests")]
            public bool RequireTPAPermission;
            [JsonProperty(PropertyName = "Allow Cave")]
            public bool AllowCave;
            [JsonProperty(PropertyName = "Allow TPB")]
            public bool AllowTPB = true;
            [JsonProperty(PropertyName = "Allow Deep Sea")]
            public bool DeepSea = true;
            [JsonProperty(PropertyName = "Use Blocked Users")]
            public bool UseBlockedUsers;
            [JsonProperty(PropertyName = "Cooldown")]
            public int Cooldown = 600;
            [JsonProperty(PropertyName = "Countdown")]
            public int Countdown = 15;
            [JsonProperty(PropertyName = "Daily Limit")]
            public int DailyLimit = 5;
            [JsonProperty(PropertyName = "VIP Daily Limits", ObjectCreationHandling = ObjectCreationHandling.Replace)]
            public Dictionary<string, int> VIPDailyLimits = new() {
                {
                    ConfigDefaultPermVip, 5
                }
            }
            ;
            [JsonProperty(PropertyName = "VIP Cooldowns", ObjectCreationHandling = ObjectCreationHandling.Replace)]
            public Dictionary<string, int> VIPCooldowns = new() {
                {
                    ConfigDefaultPermVip, 5
                }
            }
            ;
            [JsonProperty(PropertyName = "VIP Countdowns", ObjectCreationHandling = ObjectCreationHandling.Replace)]
            public Dictionary<string, int> VIPCountdowns = new() {
                {
                    ConfigDefaultPermVip, 5
                }
            }
            ;
            [JsonProperty(PropertyName = "Enable Request UI")]
            public bool UI;
            [JsonProperty(PropertyName = "Request Duration")]
            public int RequestDuration = 30;
            [JsonProperty(PropertyName = "Block TPA On Ceiling")]
            public bool BlockTPAOnCeiling = true;
            [JsonProperty(PropertyName = "Usable Out Of Building Blocked")]
            public bool UsableOutOfBuildingBlocked;
            [JsonProperty(PropertyName = "Usable Into Building Blocked")]
            public bool UsableIntoBuildingBlocked;
            [JsonProperty(PropertyName = "Allow Cupboard Owner When Building Blocked")]
            public bool CupOwnerAllowOnBuildingBlocked = true;
            [JsonProperty(PropertyName = "Allow Cupboard Ally When Building Blocked")]
            public bool CupAllyAllowOnBuildingBlocked;
            [JsonProperty(PropertyName = "Allow Cupboard Non-Ally When Building Blocked")]
            public bool CupNonAllyAllowOnBuildingBlocked;
            [JsonProperty(PropertyName = "Block For No Cupboard")]
            public bool BlockForNoCupboard;
            [JsonProperty(PropertyName = "Allow Crafting")]
            public bool AllowCraft;
            [JsonProperty(PropertyName = "Pay")]
            public int Pay = 0;
            [JsonProperty(PropertyName = "Bypass")]
            public int Bypass = 0;
            [JsonProperty(PropertyName = "Hours Before Useable After Wipe")]
            public double Hours = 0;
            [JsonProperty(PropertyName = "Remove Hostility")]
            public bool RemoveHostility;
        }
        public class TownSettings {
            [JsonProperty(PropertyName = "Command Enabled")]
            public bool Enabled = true;
            [JsonProperty(PropertyName = "Set Position From Monument Marker Name")]
            public string MonumentMarkerName = "";
            [JsonProperty(PropertyName = "Set Position From Monument Marker Name Offset")]
            public string MonumentMarkerNameOffset = "0 0 0";
            [JsonProperty(PropertyName = "Allow TPB")]
            public bool AllowTPB = true;
            [JsonProperty(PropertyName = "Allow Cave")]
            public bool AllowCave;
            [JsonProperty(PropertyName = "Allow Deep Sea", NullValueHandling = NullValueHandling.Ignore)]
            public bool? _DeepSea = true;
            internal bool DeepSea => _DeepSea.HasValue ? _DeepSea.Value : true;
            [JsonProperty(PropertyName = "Cooldown")]
            public int Cooldown = 600;
            [JsonProperty(PropertyName = "Countdown")]
            public int Countdown = 15;
            [JsonProperty(PropertyName = "Daily Limit")]
            public int DailyLimit = 5;
            [JsonProperty(PropertyName = "VIP Daily Limits", ObjectCreationHandling = ObjectCreationHandling.Replace)]
            public Dictionary<string, int> VIPDailyLimits = new() {
                {
                    ConfigDefaultPermVip, 5
                }
            }
            ;
            [JsonProperty(PropertyName = "VIP Cooldowns", ObjectCreationHandling = ObjectCreationHandling.Replace)]
            public Dictionary<string, int> VIPCooldowns = new() {
                {
                    ConfigDefaultPermVip, 5
                }
            }
            ;
            [JsonProperty(PropertyName = "VIP Countdowns", ObjectCreationHandling = ObjectCreationHandling.Replace)]
            public Dictionary<string, int> VIPCountdowns = new() {
                {
                    ConfigDefaultPermVip, 5
                }
            }
            ;
            [JsonProperty(PropertyName = "Location")]
            public Vector3 Location = Vector3.zero;
            [JsonProperty(PropertyName = "Locations", ObjectCreationHandling = ObjectCreationHandling.Replace)]
            public List<Vector3> Locations = new List<Vector3>();
            [JsonProperty(PropertyName = "Teleport To Random Location")]
            public bool Random = true;
            [JsonProperty(PropertyName = "Usable Out Of Building Blocked")]
            public bool UsableOutOfBuildingBlocked = false;
            [JsonProperty(PropertyName = "Allow Crafting")]
            public bool AllowCraft = false;
            [JsonProperty(PropertyName = "Pay")]
            public int Pay = 0;
            [JsonProperty(PropertyName = "Bypass")]
            public int Bypass = 0;
            [JsonProperty(PropertyName = "Hours Before Useable After Wipe")]
            public double Hours = 0;
            [JsonProperty(PropertyName = "Remove Hostility")]
            public bool RemoveHostility;
            public bool CanCraft(BasePlayer player, string command) {
                return AllowCraft || player.IPlayer.HasPermission($"nteleportation.craft{command.ToLower()}");
            }
            public bool CanCave(BasePlayer player, string command) {
                return AllowCave || player.IPlayer.HasPermission($"nteleportation.cave{command.ToLower()}");
            }
            [JsonIgnore]
            public StoredData Teleports = new StoredData();
            [JsonIgnore]
            public string Command;
        }
        private class Configuration {
            [JsonProperty(PropertyName = "Settings")]
            public PluginSettings Settings = new();
            [JsonProperty(PropertyName = "Admin")]
            public AdminSettings Admin = new();
            [JsonProperty(PropertyName = "Home")]
            public HomesSettings Home = new();
            [JsonProperty(PropertyName = "TPT")]
            public TPTSettings TPT = new();
            [JsonProperty(PropertyName = "TPR")]
            public TPRSettings TPR = new();
            [JsonProperty(PropertyName = "Dynamic Commands", ObjectCreationHandling = ObjectCreationHandling.Replace)]
            public Dictionary<string, TownSettings> DynamicCommands = DefaultCommands;
        }
        private void CheckConfig() {
            if (config.Settings.AutoGenDeepSea && !config.DynamicCommands.ContainsKey("DeepSea")) {
                config.DynamicCommands.Add("DeepSea", new() {
                    _DeepSea = null
                }
                );
            }
        }
        private static Dictionary<string, TownSettings> DefaultCommands = new(StringComparer.OrdinalIgnoreCase) {
            ["Town"]
            = new() {
                Random = false
            }
            , ["Island"] = new() {
                AllowTPB = false
            }
            , ["Outpost"] = new() {
                _DeepSea = true
            }
            , ["Bandit"] = new() {
                _DeepSea = true
            }
            , ["DeepSea"] = new() {
                _DeepSea = null
            }
            ,
        }
        ;
        private string banditCommand = "bandit";
        private string outpostCommand = "outpost";
        private string deepseaCommand = "deepsea";
        public void InitializeDynamicCommands() {
            foreach (var entry in config.DynamicCommands) {
                if (!entry.Value.Enabled) {
                    continue;
                }
                else if (entry.Key.Equals(banditCommand, StringComparison.OrdinalIgnoreCase)) {
                    if (CompoundTeleport == null || Convert.ToBoolean(CompoundTeleport?.Call("umodversion"))) {
                        banditEnabled = true;
                    }
                    else continue;
                }
                else if (entry.Key.Equals(outpostCommand, StringComparison.OrdinalIgnoreCase)) {
                    if (CompoundTeleport == null || Convert.ToBoolean(CompoundTeleport?.Call("umodversion"))) {
                        outpostEnabled = true;
                    }
                    else continue;
                }
                else if (entry.Key.Equals(deepseaCommand, StringComparison.OrdinalIgnoreCase)) {
                    deepseaEnabled = true;
                }
                entry.Value.Command = entry.Key;
                RegisterCommand(entry.Key, nameof(CommandCustom));
            }
            _tpid.Add(banditCommand);
            _tpid.Add(deepseaCommand);
            _tpid.Add(outpostCommand);
            RegisterCommand("ntp", nameof(CommandDynamic));
        }
        private float deepSeaMinX, deepSeaMaxX, deepSeaMinY, deepSeaMaxY, deepSeaMinZ, deepSeaMaxZ;
        private void InitDeepSea() {
            var b = DeepSeaManager.DeepSeaBounds;
            var min = b.center - b.extents;
            var max = b.center + b.extents;
            deepSeaMinX = min.x;
            deepSeaMaxX = max.x;
            deepSeaMinY = min.y;
            deepSeaMaxY = max.y;
            deepSeaMinZ = min.z;
            deepSeaMaxZ = max.z;
            Subscribe(nameof(OnDeepSeaOpened));
        }
        private bool IsInDeepSea(Vector3 worldPos) {
            if (deepSeaMinX != 0f && worldPos.x >= deepSeaMinX && worldPos.x <= deepSeaMaxX && worldPos.y >= deepSeaMinY && worldPos.y <= deepSeaMaxY && worldPos.z >= deepSeaMinZ && worldPos.z <= deepSeaMaxZ) {
                return true;
            }
            return false;
        }
        private bool IsDeepSeaOpen() {
            DeepSeaManager dsm = DeepSeaManager.ServerInstance;
            if (dsm == null || !dsm.IsOpen()) return false;
            return true;
        }
        private bool GetFloatingCitySpawnPoint(out Vector3 v, out Quaternion rot, out float radius) {
            rot = Quaternion.identity;
            v = Vector3.zero;
            radius = 0f;
            if (DeepSeaManager.ServerFloatingCities.Count == 0) return false;
            DeepSeaManager dsm = PointEntity<DeepSeaManager>.ServerInstance;
            if (dsm == null) return false;
            using var cities = Pool.Get<PooledList<DeepSeaFloatingCity>>();
            foreach (var x in DeepSeaManager.ServerFloatingCities) {
                if (x != null && !x.IsDestroyed && x.OwnerID == 0) {
                    cities.Add(x);
                }
            }
            if (cities.Count == 0) {
                return false;
            }
            DeepSeaFloatingCity city = cities.GetRandom();
            OBB obb = city.WorldSpaceBounds();
            v = obb.position;
            radius = obb.extents.Max();
            rot = city.transform.rotation;
            return true;
        }
        protected override void LoadConfig() {
            base.LoadConfig();
            canSaveConfig = false;
            try {
                Config.Settings.Converters = new JsonConverter[] {
                    new UnityVector3Converter()
                }
                ;
                config = Config.ReadObject<Configuration>();
                if (config == null) LoadDefaultConfig();
                var sea = GetSettings("deepsea");
                if (sea != null) sea._DeepSea = null;
                canSaveConfig = true;
                CheckConfig();
                SaveConfig();
            }
            catch (JsonException ex) {
                Puts(ex.ToString());
                LoadDefaultConfig();
            }
            config.Settings.ReappearEffects.RemoveAll(string.IsNullOrWhiteSpace);
            config.Settings.DisappearEffects.RemoveAll(string.IsNullOrWhiteSpace);
            config.TPR.TeleportRequestEffects.RemoveAll(string.IsNullOrWhiteSpace);
            config.TPR.TeleportAcceptEffects.RemoveAll(string.IsNullOrWhiteSpace);
            config.Settings.TPB.BlockedMonuments.RemoveAll(string.IsNullOrWhiteSpace);
        }
        private bool canSaveConfig = true;
        protected override void SaveConfig() {
            if (canSaveConfig) {
                Config.WriteObject(config);
            }
        }
        protected override void LoadDefaultConfig() {
            config = new();
            Puts("Loaded default configuration.");
        }
#endregion
        private class DisabledData {
            [JsonProperty("List of disabled commands")]
            public List<string> DisabledCommands = new();
            public DisabledData() {
            }
        }
        private DisabledData DisabledCommandData = new();
        private class AdminData {
            [JsonProperty("t")]
            public bool Town;
            [JsonProperty("u")]
            public ulong UserID;
            [JsonProperty("d")]
            public string Home;
            [JsonProperty("pl")]
            public Vector3 PreviousLocation;
            [JsonProperty("b")]
            public bool BuildingBlocked;
            [JsonProperty("c")]
            public bool AllowCrafting;
            [JsonProperty("cv")]
            public bool AllowCave;
            [JsonProperty("ds")]
            public bool DeepSea;
            [JsonProperty(PropertyName = "rh")]
            public bool RemoveHostility;
            [JsonProperty("l")]
            public Dictionary<string, Vector3> Locations = new(StringComparer.OrdinalIgnoreCase);
        }
        private class HomeData {
            public class Entry {
                internal bool
// ... [Code preview truncated due to length. Full source in attached file] ...

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