Crushed

Warp.cs

Nov 25th, 2017
561
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 41.51 KB | None | 0 0
  1. /*
  2. Warp System
  3.  
  4. Copyright (c) 2015-2016 <[email protected]>, <http://steamcommunity.com/profiles/76561197983103320/>
  5. Copyright (c) 2016-2018 <[email protected]>, <http://steamcommunity.com/id/pain45/>
  6.  
  7. -------------------------------------------------------------------------------------------------------------------
  8. This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
  9. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/4.0/deed.en_US
  10. -----------------------------------------------------------------------------------------------------------------
  11.  
  12. $Id$
  13. Version 1.9.13 by PaiN 2017-10-09 21:36 (UTC +03:00)
  14. */
  15.  
  16. using System;
  17. using System.Collections.Generic;
  18. using Oxide.Core;
  19. using Oxide.Core.Plugins;
  20. using UnityEngine;
  21.  
  22. namespace Oxide.Plugins
  23. {
  24.     [Info("Warp System", "PaiN", "1.9.14", ResourceId = 760)]
  25.     [Description("Original Developer: Dathus BR || Create warp points for players.")]
  26.     class WarpSystem : RustPlugin
  27.     {
  28.         [PluginReference]
  29.         Plugin Jail;
  30.        
  31.         [PluginReference]
  32.         Plugin NoEscape;
  33.  
  34.         private bool Changed;
  35.         private int cooldown;
  36.         private int warpbacktimer;
  37.         private bool enablecooldown;
  38.         private int backcmdauthlevel;
  39.         private bool WarpIfRunning;
  40.         private bool WarpIfWounded;
  41.         private bool WarpIfSwimming;
  42.         private bool WarpIfRaidBlocked;
  43.         private bool WarpIfBuildingBlocked;
  44.         private bool WarpIfDucking;
  45.         private string backtolastloc;
  46.         private string warplist;
  47.         private string therealreadyis;
  48.         private string warpadded;
  49.         private string youhavetowait;
  50.         private string cantwarpwhilerunning;
  51.         private string cantwarpwhileRaid;
  52.         private string cantwarpwhilewounded;
  53.         private string cantwarpwhilebuildingblocked;
  54.         private string cantwarpwhileducking;
  55.         private string cantwarpwhileswimming;
  56.         private string youhaveteleportedto;
  57.         private string teleportingto;
  58.         private string youhaveremoved;
  59.  
  60.         object GetConfig(string menu, string datavalue, object defaultValue)
  61.         {
  62.             var data = Config[menu] as Dictionary<string, object>;
  63.             if (data == null)
  64.             {
  65.                 data = new Dictionary<string, object>();
  66.                 Config[menu] = data;
  67.                 Changed = true;
  68.             }
  69.             object value;
  70.             if (!data.TryGetValue(datavalue, out value))
  71.             {
  72.                 value = defaultValue;
  73.                 data[datavalue] = value;
  74.                 Changed = true;
  75.             }
  76.             return value;
  77.         }
  78.  
  79.         double GetTimeStamp()
  80.         {
  81.             return (DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
  82.         }
  83.  
  84.         void LoadVariables()
  85.         {
  86.             warpbacktimer = Convert.ToInt32(GetConfig("Settings", "WarpBackTimer", 5));
  87.             cooldown = Convert.ToInt32(GetConfig("Settings", "Cooldown", 120));
  88.             enablecooldown = Convert.ToBoolean(GetConfig("Settings", "EnableCooldown", true));
  89.             backcmdauthlevel = Convert.ToInt32(GetConfig("Settings", "Warp_Back_Atleast_Required_Authlevel", 1));
  90.             WarpIfWounded = Convert.ToBoolean(GetConfig("Settings", "WarpIfWounded", true));
  91.             WarpIfSwimming = Convert.ToBoolean(GetConfig("Settings", "WarpIfSwimming", true));
  92.             WarpIfRunning = Convert.ToBoolean(GetConfig("Settings", "WarpIfRunning", true));
  93.             WarpIfRaidBlocked = Convert.ToBoolean(GetConfig("Settings", "WarpIfRaidBlocked", true));
  94.             WarpIfBuildingBlocked = Convert.ToBoolean(GetConfig("Settings", "WarpIfBuildingBlocked", true));
  95.             WarpIfDucking = Convert.ToBoolean(GetConfig("Settings", "WarpIfDucking", true));
  96.             backtolastloc = Convert.ToString(GetConfig("Messages", "TELEPORTED_TO_LAST_LOCATION", "You have teleported back to your last location!"));
  97.             warplist = Convert.ToString(GetConfig("Messages", "WARP_LIST", "Warp ID: <color=#91FFB5>{2}</color>\nWarp Name: <color=cyan>{0}</color> \nPermission:<color=orange> {1} </color> \nMaxUses Remaining: <color=lime>{3}</color>"));
  98.             therealreadyis = Convert.ToString(GetConfig("Messages", "WARP_EXISTS", "This warp already exists!"));
  99.             warpadded = Convert.ToString(GetConfig("Messages", "WARP_ADDED", "Warp added with Warp Name: <color=#91FFB5>{0}</color>"));
  100.             youhavetowait = Convert.ToString(GetConfig("Messages", "COOLDOWN_MESSAGE", "You have to wait <color=#91FFB5>{0}</color> second(s) before you can teleport again."));
  101.             cantwarpwhilerunning = Convert.ToString(GetConfig("Messages", "CANT_WARP_WHILE_RUNNING", "You can not warp while running!"));
  102.             cantwarpwhilewounded = Convert.ToString(GetConfig("Messages", "CANT_WARP_WHILE_WOUNDED", "You can not warp while you are wounded!"));
  103.             cantwarpwhilebuildingblocked = Convert.ToString(GetConfig("Messages", "CANT_WARP_WHILE_BUILDING_BLOCKED", "You can not warp while you are in a building blocked area!"));
  104.             cantwarpwhileducking = Convert.ToString(GetConfig("Messages", "CANT_WARP_WHILE_DUCKING", "You can not warp while you are ducking!"));
  105.             cantwarpwhileswimming = Convert.ToString(GetConfig("Messages", "CANT_WARP_WHILE_SWIMMING", "You can not warp while you are swimming!"));
  106.             cantwarpwhileRaid = Convert.ToString(GetConfig("Messages", "CANT_WARP_WHILE_RAID", "You can not warp while you are Raid-Blocked"));
  107.             youhaveteleportedto = Convert.ToString(GetConfig("Messages", "TELEPORTED_TO", "You have teleported to <color=#91FFB5>{0}</color>"));
  108.             teleportingto = Convert.ToString(GetConfig("Messages", "TELEPORTING_IN_TO", "Teleporting in <color=orange>{0}</color> second(s) to <color=#91FFB5>{1}</color>"));
  109.             youhaveremoved = Convert.ToString(GetConfig("Messages", "WARP_REMOVED", "You have removed the warp <color=#91FFB5>{0}</color>"));
  110.  
  111.             if (Changed)
  112.             {
  113.                 SaveConfig();
  114.                 Changed = false;
  115.  
  116.             }
  117.         }
  118.  
  119.         protected override void LoadDefaultConfig()
  120.         {
  121.             Puts("Creating a new configuration file!");
  122.             Config.Clear();
  123.             LoadVariables();
  124.         }
  125.  
  126.         class StoredData
  127.         {
  128.             public List<WarpInfo> WarpInfo = new List<WarpInfo> { };
  129.             public Dictionary<ulong, double> cantele = new Dictionary<ulong, double>();
  130.             public Dictionary<ulong, OldPosInfo> lastposition = new Dictionary<ulong, OldPosInfo>();
  131.             public Dictionary<ulong, Dictionary<string, int>> maxuses = new Dictionary<ulong, Dictionary<string, int>>();
  132.  
  133.         }
  134.  
  135.         class OldPosInfo
  136.         {
  137.             public float OldX;
  138.             public float OldY;
  139.             public float OldZ;
  140.  
  141.             public OldPosInfo(float x, float y, float z)
  142.             {
  143.                 OldX = x;
  144.                 OldY = y;
  145.                 OldZ = z;
  146.             }
  147.  
  148.             public OldPosInfo()
  149.             {
  150.             }
  151.         }
  152.         class WarpInfo
  153.         {
  154.             public string WarpName;
  155.             public int WarpId;
  156.             public float WarpX;
  157.             public float WarpY;
  158.             public float WarpZ;
  159.             public string WarpPermissionGroup;
  160.             public int WarpTimer;
  161.             public int WarpMaxUses;
  162.             public string WarpCreatorName;
  163.             public int RandomRange;
  164.  
  165.             public WarpInfo(string name, BasePlayer player, int timerp, string permissionp, int warpnum, int randomr, int maxusess)
  166.             {
  167.                 WarpName = name;
  168.                 WarpId = warpnum;
  169.                 WarpX = player.transform.position.x;
  170.                 WarpMaxUses = maxusess;
  171.                 WarpY = player.transform.position.y;
  172.                 WarpZ = player.transform.position.z;
  173.                 WarpCreatorName = player.displayName;
  174.                 WarpTimer = timerp;
  175.                 WarpPermissionGroup = permissionp;
  176.                 RandomRange = randomr;
  177.             }
  178.  
  179.             public WarpInfo()
  180.             {
  181.             }
  182.         }
  183.  
  184.         StoredData storedData;
  185.  
  186.         void Loaded()
  187.         {
  188.             storedData = Interface.GetMod().DataFileSystem.ReadObject<StoredData>("WarpSystem");
  189.             if (!permission.PermissionExists("warpsystem.admin")) permission.RegisterPermission("warpsystem.admin", this);
  190.             LoadVariables();
  191.             foreach (WarpInfo info in storedData.WarpInfo)
  192.             {
  193.                 if (!permission.GroupExists(info.WarpPermissionGroup)) permission.CreateGroup(info.WarpPermissionGroup, "", 0);
  194.                 cmd.AddChatCommand(info.WarpId.ToString(), this, "");
  195.                 cmd.AddChatCommand(info.WarpName, this, "");
  196.             }
  197.         }
  198.         [ConsoleCommand("warp.wipemaxuses")]
  199.         void cmdWarpMaxUses(ConsoleSystem.Arg arg)
  200.         {
  201.             if (arg.Connection != null && arg.Connection.authLevel < 1)
  202.             {
  203.                 arg.ReplyWith("You cant use that command!");
  204.                 return;
  205.             }
  206.             storedData.maxuses.Clear();
  207.             Interface.GetMod().DataFileSystem.WriteObject("WarpSystem", storedData);
  208.         }
  209.         [ConsoleCommand("warp.playerto")]
  210.         void cmdWarpPlayerr(ConsoleSystem.Arg arg)
  211.         {
  212.             BasePlayer target = BasePlayer.Find(arg.Args[0]);
  213.             if ((arg.Args == null) || (arg.Args != null && arg.Args.Length == 0))
  214.             {
  215.                 arg.ReplyWith("warp.playerto <PlayerName> <WarpName>");
  216.                 return;
  217.             }
  218.             if (arg.Connection != null && arg.Connection.authLevel < 1)
  219.             {
  220.                 arg.ReplyWith("You cant use that command!");
  221.                 return;
  222.             }
  223.             if (target == null)
  224.             {
  225.                 arg.ReplyWith("Player not found!");
  226.                 return;
  227.             }
  228.  
  229.             ulong steamID = target.userID;
  230.             double nextteletime;
  231.  
  232.  
  233.             if (enablecooldown == true)
  234.             {
  235.                 if (storedData.cantele.TryGetValue(steamID, out nextteletime))
  236.                 {
  237.                     if (GetTimeStamp() >= nextteletime)
  238.                     {
  239.                         storedData.cantele[steamID] = GetTimeStamp() + cooldown;
  240.                         Interface.GetMod().DataFileSystem.WriteObject("WarpSystem", storedData);
  241.                         goto Finish;
  242.                     }
  243.                     else
  244.                     {
  245.                         int nexttele = Convert.ToInt32(nextteletime - GetTimeStamp());
  246.                         SendReply(target, youhavetowait, nexttele.ToString().Replace("-", ""));
  247.                         return;
  248.                     }
  249.                 }
  250.                 else
  251.                 {
  252.                     storedData.cantele.Add(steamID, GetTimeStamp() + cooldown);
  253.                     Interface.GetMod().DataFileSystem.WriteObject("WarpSystem", storedData);
  254.                     goto Finish;
  255.                 }
  256.             }
  257.  
  258.             Finish:
  259.             foreach (WarpInfo info in storedData.WarpInfo)
  260.             {
  261.                 if (info.WarpName.ToLower() == arg.Args[1].ToLower() || info.WarpId.ToString().ToLower() == arg.Args[1].ToLower())
  262.                 {
  263.                     bool IsRaidBlocked = Convert.ToBoolean(NoEscape?.Call("IsRaidBlocked", target));
  264.                     SendReply(target, teleportingto, info.WarpTimer, info.WarpName);
  265.                     arg.ReplyWith($"Teleporting {target.displayName} to {info.WarpName} in {info.WarpTimer}");
  266.                     timer.Once(info.WarpTimer, () =>
  267.                     {
  268.                         if (WarpIfRunning == false && target.IsRunning())
  269.                         {
  270.                             SendReply(target, cantwarpwhilerunning);
  271.                             return;
  272.                         }
  273.                         if (WarpIfWounded == false && target.IsWounded())
  274.                         {
  275.                             SendReply(target, cantwarpwhilewounded);
  276.                             return;
  277.                         }
  278.                         if (WarpIfSwimming == false && target.IsSwimming())
  279.                         {
  280.                             SendReply(target, cantwarpwhileswimming);
  281.                             return;
  282.                         }
  283.                         if (WarpIfRaidBlocked == false && IsRaidBlocked)
  284.                         {                          
  285.                             SendReply(target, cantwarpwhileRaid);
  286.                             return;
  287.                         }
  288.                         if (WarpIfBuildingBlocked == false & !target.CanBuild())
  289.                         {
  290.                             SendReply(target, cantwarpwhilebuildingblocked);
  291.                             return;
  292.                         }
  293.                         if (WarpIfDucking == false && target.IsDucked())
  294.                         {
  295.                             SendReply(target, cantwarpwhileducking);
  296.                             return;
  297.                         }
  298.                         ForcePlayerPos(target, new Vector3(info.WarpX, info.WarpY, info.WarpZ));
  299.                         SendReply(target, youhaveteleportedto, info.WarpName);
  300.  
  301.                     });
  302.                 }
  303.             }
  304.         }
  305.  
  306.  
  307.         /*[ConsoleCommand("test.it")]
  308.         void cmdTestIT(ConsoleSystem.Arg arg)
  309.         {
  310.             arg.ReplyWith(new Random.Next(1,5).ToString());
  311.         }*/
  312.         int GetNewId()
  313.         {
  314.  
  315.             int id = 0;
  316.             foreach (WarpInfo info in storedData.WarpInfo)
  317.             {
  318.                 id = Math.Max(0, info.WarpId);
  319.             }
  320.             return id + 1;
  321.         }
  322.         int GetRandomId(BasePlayer player)
  323.         {
  324.             int randomid = 0;
  325.             foreach (WarpInfo info in storedData.WarpInfo)
  326.             {
  327.                 if (permission.UserHasGroup(player.userID.ToString(), info.WarpPermissionGroup) || info.WarpPermissionGroup == "all")
  328.                 {
  329.                     randomid = UnityEngine.Random.Range(0, Math.Max(0, info.WarpId));
  330.                 }
  331.             }
  332.             return randomid + 1;
  333.         }
  334.         [ChatCommand("warp")]
  335.         void cmdWarp(BasePlayer player, string cmdd, string[] args)
  336.         {
  337.             if (args.Length == 0)
  338.             {
  339.                 player.SendConsoleCommand("chat.say \"/warp help\" ");
  340.                 return;
  341.             }
  342.  
  343.             bool isprisoner = Convert.ToBoolean(Jail?.Call("IsPrisoner", player));
  344.             bool IsRaidBlocked = Convert.ToBoolean(NoEscape?.Call("IsRaidBlocked", player));
  345.  
  346.             ulong steamId = player.userID;
  347.             double nextteletime;
  348.             switch (args[0])
  349.             {
  350.                 case "limit":
  351.                     SendReply(player, "<color=#91FFB5>Current Warp Limits</color>");
  352.  
  353.                     if (storedData.cantele.TryGetValue(steamId, out nextteletime))
  354.                     {
  355.                         int nexttele = Convert.ToInt32(nextteletime - GetTimeStamp());
  356.                         if (nexttele <= 0)
  357.                         {
  358.                             nexttele = 0;
  359.                         }
  360.                         SendReply(player, $"You will be able to warp again in {nexttele} seconds");
  361.                     }
  362.                     SendReply(player, $"Warp Cooldown: <color=orage>{cooldown}</color>");
  363.                     SendReply(player, $"Warp Cooldown Enabled: <color=orage>{enablecooldown}</color>");
  364.                     SendReply(player, "<color=#91FFB5>*************</color>");
  365.                     break;
  366.                 case "back":
  367.                     if (isprisoner)
  368.                     {
  369.                         SendReply(player, "You cant teleport out of the jail!");
  370.                         return;
  371.                     }
  372.                     if (player.net.connection.authLevel >= backcmdauthlevel)
  373.                     {
  374.                         SendReply(player, "Teleporting to you last saved locations in {0} seconds.", warpbacktimer.ToString());
  375.                         timer.Once(warpbacktimer, () =>
  376.                         {
  377.                             if (WarpIfRunning == false && player.IsRunning())
  378.                             {
  379.                                 SendReply(player, cantwarpwhilerunning);
  380.                                 return;
  381.                             }
  382.                             if (WarpIfWounded == false && player.IsWounded())
  383.                             {
  384.                                 SendReply(player, cantwarpwhilewounded);
  385.                                 return;
  386.                             }
  387.                             if (WarpIfSwimming == false && player.IsSwimming())
  388.                             {
  389.                                 SendReply(player, cantwarpwhileswimming);
  390.                                 return;
  391.                             }
  392.                             if (WarpIfRaidBlocked == false && IsRaidBlocked)
  393.                             {                          
  394.                                 SendReply(player, cantwarpwhileRaid);
  395.                                 return;
  396.                             }
  397.                             if (WarpIfBuildingBlocked == false & !player.CanBuild())
  398.                             {
  399.                                 SendReply(player, cantwarpwhilebuildingblocked);
  400.                                 return;
  401.                             }
  402.                             if (WarpIfDucking == false && player.IsDucked())
  403.                             {
  404.                                 SendReply(player, cantwarpwhileducking);
  405.                                 return;
  406.                             }
  407.                             ForcePlayerPos(player, new Vector3(storedData.lastposition[steamId].OldX, storedData.lastposition[steamId].OldY, storedData.lastposition[steamId].OldZ));
  408.                             SendReply(player, backtolastloc);
  409.                             storedData.lastposition.Remove(steamId);
  410.                             Interface.GetMod().DataFileSystem.WriteObject("WarpSystem", storedData);
  411.                         });
  412.                     }
  413.                     break;
  414.  
  415.                 case "random":
  416.                     if (isprisoner)
  417.                     {
  418.                         SendReply(player, "You cant teleport out of the jail!");
  419.                         return;
  420.                     }
  421.                     player.SendConsoleCommand($"chat.say \"/warp to {GetRandomId(player)}\" ");
  422.                     break;
  423.  
  424.                 case "all":
  425.                     if (!permission.UserHasPermission(player.userID.ToString(), "warpsystem.admin"))
  426.                     {
  427.                         SendReply(player, "You do not have permission to use this command!");
  428.                         return;
  429.                     }
  430.                     if (args.Length == 2)
  431.                     {
  432.                         foreach (BasePlayer current in BasePlayer.activePlayerList)
  433.                         {
  434.                             foreach (WarpInfo info in storedData.WarpInfo)
  435.                             {
  436.                                 if (info.WarpName.ToLower() == args[1].ToLower() || info.WarpId.ToString() == args[1])
  437.                                 {
  438.                                     ForcePlayerPos(current, new Vector3(info.WarpX, info.WarpY, info.WarpZ));
  439.                                     SendReply(current, "You got teleported to <color=#91FFB5>" + info.WarpName + "</color> by <color=orange>" + player.displayName + "</color>");
  440.  
  441.                                 }
  442.                             }
  443.                         }
  444.                     }
  445.                     else if (args.Length == 3 && args[1] == "sleepers")
  446.                     {
  447.                         foreach (BasePlayer sleepers in BasePlayer.sleepingPlayerList)
  448.                         {
  449.                             foreach (WarpInfo info in storedData.WarpInfo)
  450.                             {
  451.                                 if (info.WarpName.ToLower() == args[2].ToLower() || info.WarpId.ToString() == args[2])
  452.                                 {
  453.                                     ForcePlayerPos(sleepers, new Vector3(info.WarpX, info.WarpY, info.WarpZ));
  454.                                     //SendReply(player, "You got teleported to <color=#91FFB5>" + info.WarpName + "</color> by <color=orange>" + player.displayName + "</color>");
  455.  
  456.                                 }
  457.                             }
  458.                         }
  459.                     }
  460.                     else
  461.                     {
  462.                         SendReply(player, "<color=#91FFB5>Teleport all online players</color>: \n /warp all <WarpName>");
  463.                         SendReply(player, "<color=#91FFB5>Teleport all sleepers</color>: \n /warp all sleepers <WarpName>");
  464.                         return;
  465.                     }
  466.                     break;
  467.                 case "wipe":
  468.                     if (!permission.UserHasPermission(player.userID.ToString(), "warpsystem.admin"))
  469.                     {
  470.                         SendReply(player, "You do not have permission to use this command!");
  471.                         return;
  472.                     }
  473.                     storedData.WarpInfo.Clear();
  474.                     storedData.cantele.Clear();
  475.                     Interface.GetMod().DataFileSystem.WriteObject("WarpSystem", storedData);
  476.                     SendReply(player, "You have wiped all the teleports!");
  477.                     break;
  478.  
  479.                 case "list":
  480.                     SendReply(player, "<color=#91FFB5>Current Warps</color>");
  481.                     string maxusesrem;
  482.                     foreach (WarpInfo info in storedData.WarpInfo)
  483.                     {
  484.                         if (permission.UserHasGroup(steamId.ToString(), info.WarpPermissionGroup) || info.WarpPermissionGroup == "all")
  485.                         {
  486.  
  487.                             if (info.WarpMaxUses == 0)
  488.                             {
  489.                                 maxusesrem = "<color=red>UNLIMITED</color>";
  490.                             }
  491.                             else if (!storedData.maxuses.ContainsKey(steamId))
  492.                             {
  493.                                 maxusesrem = info.WarpMaxUses.ToString();
  494.                             }
  495.                             else
  496.                                 maxusesrem = storedData.maxuses[steamId][info.WarpName].ToString();
  497.  
  498.                             SendReply(player, warplist, info.WarpName, info.WarpPermissionGroup, info.WarpId, maxusesrem);
  499.                             SendReply(player, "<color=#91FFB5>*************</color>");
  500.                         }
  501.  
  502.                     }
  503.                     SendReply(player, "<color=#91FFB5>*************</color>");
  504.                     break;
  505.  
  506.                 case "add":
  507.  
  508.                     if (!permission.UserHasPermission(player.userID.ToString(), "warpsystem.admin"))
  509.                     {
  510.                         SendReply(player, "You do not have permission to use this command!");
  511.                         return;
  512.                     }
  513.                     if (args.Length != 6)
  514.                     {
  515.                         SendReply(player, "/warp <add> <WarpName> <WarpTimer> <WarpRange> <WarpMaxUses> <WarpPermissionGroup>");
  516.                         return;
  517.                     }
  518.                     foreach (WarpInfo info in storedData.WarpInfo)
  519.                     {
  520.                         if (args[1].ToLower() == info.WarpName.ToLower())
  521.                         {
  522.                             SendReply(player, therealreadyis);
  523.                             return;
  524.                         }
  525.                     }
  526.                     string permissionp = args[5];
  527.                     string name = args[1];
  528.                     int warpnum;
  529.                     int timerp = Convert.ToInt32(args[2]);
  530.                     int randomr = Convert.ToInt32(args[3]);
  531.                     int maxusess = Convert.ToInt32(args[4]);
  532.                     if (storedData.WarpInfo == null)
  533.                     {
  534.                         warpnum = 1;
  535.                     }
  536.                     else
  537.                     {
  538.                         warpnum = GetNewId();
  539.                     }
  540.                     var data = new WarpInfo(name, player, timerp, permissionp, warpnum, randomr, maxusess);
  541.                     storedData.WarpInfo.Add(data);
  542.                     SendReply(player, warpadded, name);
  543.                     Interface.GetMod().DataFileSystem.WriteObject("WarpSystem", storedData);
  544.                     if (!permission.GroupExists(args[5])) permission.CreateGroup(args[5], "", 0);
  545.                     cmd.AddChatCommand(name, this, "");
  546.                     cmd.AddChatCommand(warpnum.ToString(), this, "");
  547.                     break;
  548.  
  549.                 case "to":
  550.                     if (args.Length != 2)
  551.                     {
  552.                         SendReply(player, "/warp to <WarpName> || /warplist");
  553.                         return;
  554.                     }
  555.                     if (isprisoner)
  556.                     {
  557.                         SendReply(player, "You cant teleport out of the jail!");
  558.                         return;
  559.                     }
  560.                     foreach (WarpInfo info in storedData.WarpInfo)
  561.                     {
  562.                         if (info.WarpName.ToLower() == args[1].ToLower() || info.WarpId.ToString() == args[1])
  563.                         {
  564.                             if (info.WarpPermissionGroup == "all" || permission.UserHasGroup(steamId.ToString(), info.WarpPermissionGroup))
  565.                             {
  566.                                 if (info.WarpMaxUses > 0)
  567.                                 {
  568.                                     if (!storedData.maxuses.ContainsKey(steamId))
  569.                                     {
  570.                                         storedData.maxuses.Add(
  571.                                         steamId,
  572.                                         new Dictionary<string, int>{
  573.                                             {info.WarpName, 1}
  574.                                         }
  575.                                     );
  576.                                     }
  577.                                     if (storedData.maxuses[steamId][info.WarpName] == 5)
  578.                                     {
  579.                                         SendReply(player, "You have reached the max uses for this Warp!");
  580.                                         return;
  581.                                     }
  582.                                     if (storedData.maxuses.ContainsKey(steamId))
  583.                                     {
  584.                                         storedData.maxuses[steamId][info.WarpName] = storedData.maxuses[steamId][info.WarpName] + 1;
  585.                                     }
  586.                                 }
  587.  
  588.                                 if (enablecooldown == true)
  589.                                 {
  590.                                     if (storedData.cantele.TryGetValue(steamId, out nextteletime))
  591.                                     {
  592.                                         if (GetTimeStamp() >= nextteletime)
  593.                                         {
  594.  
  595.                                             storedData.cantele[steamId] = GetTimeStamp() + cooldown;
  596.                                             Interface.GetMod().DataFileSystem.WriteObject("WarpSystem", storedData);
  597.                                             goto Finish;
  598.                                         }
  599.                                         else
  600.                                         {
  601.                                             int nexttele = Convert.ToInt32(GetTimeStamp() - nextteletime);
  602.                                             SendReply(player, youhavetowait, nexttele.ToString().Replace("-", ""));
  603.                                             return;
  604.                                         }
  605.                                     }
  606.                                     else
  607.                                     {
  608.                                         storedData.cantele.Add(steamId, GetTimeStamp() + cooldown);
  609.                                         Interface.GetMod().DataFileSystem.WriteObject("WarpSystem", storedData);
  610.                                         goto Finish;
  611.                                     }
  612.                                 }
  613.                                 Finish:
  614.                                 if (storedData.lastposition.ContainsKey(steamId) | !storedData.lastposition.ContainsKey(steamId))
  615.                                 {
  616.                                     storedData.lastposition.Remove(steamId);
  617.                                     Interface.GetMod().DataFileSystem.WriteObject("WarpSystem", storedData);
  618.                                     float x = player.transform.position.x;
  619.                                     float y = player.transform.position.y;
  620.                                     float z = player.transform.position.z;
  621.                                     var oldinfo = new OldPosInfo(x, y, z);
  622.                                     storedData.lastposition.Add(steamId, oldinfo);
  623.                                     Interface.GetMod().DataFileSystem.WriteObject("WarpSystem", storedData);
  624.  
  625.                                 }
  626.  
  627.                                 SendReply(player, teleportingto, info.WarpTimer, info.WarpName);
  628.                                 timer.Once(info.WarpTimer, () =>
  629.                                 {
  630.                                     if (WarpIfRunning == false && player.IsRunning())
  631.                                     {
  632.                                         SendReply(player, cantwarpwhilerunning);
  633.                                         return;
  634.                                     }
  635.                                     if (WarpIfWounded == false && player.IsWounded())
  636.                                     {
  637.                                         SendReply(player, cantwarpwhilewounded);
  638.                                         return;
  639.                                     }
  640.                                     if (WarpIfSwimming == false && player.IsSwimming())
  641.                                     {
  642.                                         SendReply(player, cantwarpwhileswimming);
  643.                                         return;
  644.                                     }
  645.                                     if (WarpIfRaidBlocked == false && IsRaidBlocked)
  646.                                     {                          
  647.                                         SendReply(player, cantwarpwhileRaid);
  648.                                         return;
  649.                                     }
  650.                                     if (WarpIfBuildingBlocked == false & !player.CanBuild())
  651.                                     {
  652.                                         SendReply(player, cantwarpwhilebuildingblocked);
  653.                                         return;
  654.                                     }
  655.                                     if (WarpIfDucking == false && player.IsDucked())
  656.                                     {
  657.                                         SendReply(player, cantwarpwhileducking);
  658.                                         return;
  659.                                     }
  660.                                     int posx = UnityEngine.Random.Range(Convert.ToInt32(info.WarpX), info.RandomRange);
  661.                                     int posz = UnityEngine.Random.Range(Convert.ToInt32(info.WarpZ), info.RandomRange);
  662.                                     if (info.RandomRange == 0)
  663.                                     {
  664.                                         ForcePlayerPos(player, new Vector3(info.WarpX, info.WarpY, info.WarpZ));
  665.                                     }
  666.                                     else
  667.                                         ForcePlayerPos(player, new Vector3(posx, info.WarpY, posz));
  668.                                     SendReply(player, youhaveteleportedto, info.WarpName);
  669.                                 });
  670.                             }
  671.                             else
  672.                             {
  673.                                 SendReply(player, "You are not allowed to use this warp!");
  674.                                 return;
  675.                             }
  676.                         }
  677.                     }
  678.                     break;
  679.                 case "help":
  680.                     if (permission.UserHasPermission(player.userID.ToString(), "warpsystem.admin"))
  681.                     {
  682.                         SendReply(player, "<color=#91FFB5>Available Commands</color>");
  683.                         SendReply(player, "<color=#91FFB5>-</color> /warp <add> <WarpName> <WarpTimer> <WarpRange> <WarpMaxUses> <WarpPermissionGroup>");
  684.                         SendReply(player, "<color=#91FFB5>-</color> /warp limit");
  685.                         SendReply(player, "<color=#91FFB5>-</color> /warp random");
  686.                         SendReply(player, "<color=#91FFB5>-</color> /warp remove <WarpName>");
  687.                         SendReply(player, "<color=#91FFB5>-</color> /warp wipe");
  688.                         SendReply(player, "<color=#91FFB5>-</color> /warp list");
  689.                         SendReply(player, "<color=#91FFB5>-</color> /warp to <WarpName> || /warp list");
  690.                         SendReply(player, "<color=#91FFB5>-</color> /<WarpName> => A shorter version of /warp to <WarpName> || /warp list");
  691.                         SendReply(player, "<color=#91FFB5>Teleport all online players</color>: \n<color=#91FFB5>-</color> /warp all <WarpName>");
  692.                         SendReply(player, "<color=#91FFB5>Teleport all sleepers</color>: \n<color=#91FFB5>-</color> /warp all sleepers <WarpName>");
  693.                     }
  694.                     else
  695.                     {
  696.                         SendReply(player, "<color=#91FFB5>Available Commands</color>");
  697.                         SendReply(player, "<color=#91FFB5>-</color> /warp list");
  698.                         SendReply(player, "<color=#91FFB5>-</color> /warp limit");
  699.                         SendReply(player, "<color=#91FFB5>-</color> /warp random");
  700.                         SendReply(player, "<color=#91FFB5>-</color> /warp to <WarpName> || /warp list");
  701.                         SendReply(player, "<color=#91FFB5>-</color> /<WarpName> => A shorter version of /warp to <WarpName> || /warp list");
  702.                     }
  703.                     break;
  704.                 case "remove":
  705.                     if (!permission.UserHasPermission(player.userID.ToString(), "warpsystem.admin"))
  706.                     {
  707.                         SendReply(player, "You do not have permission to use this command!");
  708.                         return;
  709.                     }
  710.                     if (args.Length != 2)
  711.                     {
  712.                         SendReply(player, "/warp remove <WarpName>");
  713.                         return;
  714.                     }
  715.                     foreach (WarpInfo info in storedData.WarpInfo)
  716.                     {
  717.                         if (info.WarpName == args[1])
  718.                         {
  719.                             storedData.WarpInfo.Remove(info);
  720.                             SendReply(player, youhaveremoved, info.WarpName);
  721.                             Interface.GetMod().DataFileSystem.WriteObject("WarpSystem", storedData);
  722.                             break;
  723.                         }
  724.                     }
  725.                     break;
  726.  
  727.             }
  728.         }
  729.  
  730.         /*void Unloaded()
  731.         {
  732.             storedData.cantele.Clear();
  733.             Interface.GetMod().DataFileSystem.WriteObject("WarpSystem", storedData);
  734.         }*/
  735.         void OnServerCommand(ConsoleSystem.Arg arg)
  736.         {
  737.             if (arg == null) return;
  738.             if (arg.Connection == null) return;
  739.             if (arg.Connection.player == null) return;
  740.             if (arg.cmd == null) return;
  741.             if (arg.cmd.Name == null) return;
  742.             BasePlayer player = (BasePlayer)arg.Connection.player;
  743.             ulong steamId = player.userID;
  744.             double nextteletime;
  745.             bool IsRaidBlocked = Convert.ToBoolean(NoEscape?.Call("IsRaidBlocked", player));
  746.             string cmd = arg.cmd.FullName;
  747.             string text = arg.GetString(0, "text");
  748.  
  749.  
  750.             if (cmd == "chat.say" && text.StartsWith("/"))
  751.             {
  752.                 foreach (WarpInfo info in storedData.WarpInfo)
  753.                 {
  754.                     if (text == "/" + info.WarpName || text == "/" + info.WarpId)
  755.                     {
  756.                         if (info.WarpPermissionGroup == "all" || permission.UserHasGroup(steamId.ToString(), info.WarpPermissionGroup))
  757.                         {
  758.  
  759.                             if (enablecooldown == true)
  760.                             {
  761.                                 if (storedData.cantele.TryGetValue(steamId, out nextteletime))
  762.                                 {
  763.                                     if (GetTimeStamp() > nextteletime)
  764.                                     {
  765.  
  766.                                         storedData.cantele[steamId] = GetTimeStamp() + cooldown;
  767.                                         Interface.GetMod().DataFileSystem.WriteObject("WarpSystem", storedData);
  768.                                         goto Finish;
  769.                                     }
  770.                                     else
  771.                                     {
  772.                                         int nexttele = Convert.ToInt32(GetTimeStamp() - nextteletime);
  773.                                         SendReply(player, youhavetowait, nexttele.ToString().Replace("-", ""));
  774.                                         return;
  775.                                     }
  776.                                 }
  777.                                 else
  778.                                 {
  779.                                     storedData.cantele.Add(steamId, GetTimeStamp() + cooldown);
  780.                                     Interface.GetMod().DataFileSystem.WriteObject("WarpSystem", storedData);
  781.                                     goto Finish;
  782.                                 }
  783.                             }
  784.                             Finish:
  785.                             if (storedData.lastposition.ContainsKey(steamId) | !storedData.lastposition.ContainsKey(steamId))
  786.                             {
  787.                                 storedData.lastposition.Remove(steamId);
  788.                                 Interface.GetMod().DataFileSystem.WriteObject("WarpSystem", storedData);
  789.                                 float x = player.transform.position.x;
  790.                                 float y = player.transform.position.y;
  791.                                 float z = player.transform.position.z;
  792.                                 var oldinfo = new OldPosInfo(x, y, z);
  793.                                 storedData.lastposition.Add(steamId, oldinfo);
  794.                                 Interface.GetMod().DataFileSystem.WriteObject("WarpSystem", storedData);
  795.  
  796.                             }
  797.  
  798.                             SendReply(player, teleportingto, info.WarpTimer, info.WarpName);
  799.                             timer.Once(info.WarpTimer, () =>
  800.                             {
  801.                                 if (WarpIfRunning == false && player.IsRunning())
  802.                                 {
  803.                                     SendReply(player, cantwarpwhilerunning);
  804.                                     return;
  805.                                 }
  806.                                 if (WarpIfWounded == false && player.IsWounded())
  807.                                 {
  808.                                     SendReply(player, cantwarpwhilewounded);
  809.                                     return;
  810.                                 }
  811.                                 if (WarpIfSwimming == false && player.IsSwimming())
  812.                                 {
  813.                                     SendReply(player, cantwarpwhileswimming);
  814.                                     return;
  815.                                 }
  816.                                 if (WarpIfRaidBlocked == false && IsRaidBlocked)
  817.                                 {                          
  818.                                     SendReply(player, cantwarpwhileRaid);
  819.                                     return;
  820.                                 }
  821.                                 if (WarpIfBuildingBlocked == false & !player.CanBuild())
  822.                                 {
  823.                                     SendReply(player, cantwarpwhilebuildingblocked);
  824.                                     return;
  825.                                 }
  826.                                 if (WarpIfDucking == false && player.IsDucked())
  827.                                 {
  828.                                     SendReply(player, cantwarpwhileducking);
  829.                                     return;
  830.                                 }
  831.                                 ForcePlayerPos(player, new Vector3(info.WarpX, info.WarpY, info.WarpZ));
  832.                                 SendReply(player, youhaveteleportedto, info.WarpName);
  833.                             });
  834.                         }
  835.                         else
  836.                         {
  837.                             SendReply(player, "You are not allowed to use this warp!");
  838.                             return;
  839.                         }
  840.                     }
  841.                 }
  842.             }
  843.  
  844.         }
  845.         void ForcePlayerPos(BasePlayer player, Vector3 xyz)
  846.         {
  847.             player.SetPlayerFlag(BasePlayer.PlayerFlags.Sleeping, true);
  848.             if (!BasePlayer.sleepingPlayerList.Contains(player)) BasePlayer.sleepingPlayerList.Add(player);
  849.  
  850.             player.CancelInvoke("InventoryUpdate");
  851.             player.inventory.crafting.CancelAll(true);
  852.  
  853.             player.MovePosition(xyz);
  854.             player.ClientRPCPlayer(null, player, "ForcePositionTo", xyz);
  855.             player.SetPlayerFlag(BasePlayer.PlayerFlags.ReceivingSnapshot, true);
  856.             player.UpdateNetworkGroup();
  857.  
  858.             player.SendNetworkUpdateImmediate(false);
  859.             player.ClientRPCPlayer(null, player, "StartLoading");
  860.             player.SendFullSnapshot();
  861.         }
  862.     }
  863. }
Add Comment
Please, Sign In to add comment