Polraudio

Pols Server Utilities

Nov 29th, 2021 (edited)
547
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 83.67 KB | None | 0 0
  1. using Newtonsoft.Json;
  2. using Newtonsoft.Json.Linq;
  3. using System;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. using System.Data.SqlClient;
  7. using System.IO;
  8. using System.Linq;
  9. using System.Reflection;
  10. using System.Runtime.CompilerServices;
  11. using System.Security.Cryptography.X509Certificates;
  12. using System.Threading.Tasks;
  13. using System.Xml;
  14. using System.Xml.Serialization;
  15. using Vintagestory.API;
  16. using Vintagestory.API.Common;
  17. using Vintagestory.API.Config;
  18. using Vintagestory.API.Datastructures;
  19. using Vintagestory.API.Server;
  20. using Vintagestory.API.Util;
  21. using Vintagestory.GameContent;
  22.  
  23. namespace VintagestoryServerUtils
  24. {
  25.  
  26.     public class Main : ModSystem
  27.     {
  28.  
  29.         public ICoreServerAPI api;
  30.         public IWorldPlayerData wpdata;
  31.         private WorldMapManager world;
  32.         private IServerEventAPI serverEvent;
  33.         private IServerConfig serverConfig;
  34.         private IServerWorldAccessor worldAccess;
  35.         private IPlayerInventoryManager playerInventoryManager;
  36.         private IInventory iInventory;
  37.         public PolServerUtilsInfo serverUtilsConfig = new PolServerUtilsInfo(); //Stores server configs
  38.         public PolServerUtilsInfo serverUtilsConfigTemp = new PolServerUtilsInfo(); //Temp to check if config exists.
  39.  
  40.         public PlayerData playerData = new PlayerData(); //Stores player data such as homes.
  41.         public PlayerData playerDataTemp = new PlayerData(); //Temp check to see if it exists
  42.  
  43.         public WarpData serverWarps = new WarpData();
  44.         public WarpData serverWarpsTemp = new WarpData();
  45.  
  46.         public BlockLogData blockLog = new BlockLogData();
  47.  
  48.         public int repeatMessageTimer = 0;
  49.  
  50.         private void ServerUptime(IServerPlayer player, int groupId, CmdArgs args)
  51.         {
  52.             TimeSpan t = TimeSpan.FromMilliseconds(api.World.ElapsedMilliseconds);
  53.             string s = string.Format("{0:D2}h:{1:D2}m:{2:D2}s", t.Hours, t.Minutes, t.Seconds);
  54.  
  55.             api.SendMessage(player, groupId, ("<icon name=wpRuins></icon><strong>Server Uptime: </strong>" + s).ToString(), EnumChatType.OwnMessage);
  56.  
  57.         }
  58.  
  59.  
  60.         [System.Serializable]
  61.         public class PolServerUtilsInfo
  62.         {
  63.             public bool enableRepeatingMsg = false;
  64.             public int repeatingMsgIntervalSec = 600;
  65.             public string repeatingMsg = "This server eats boogers for power!";
  66.  
  67.             public int rtpSearchTimer = 5;
  68.  
  69.             public int maxHomes = 2;
  70.             public int spawnCooldownSec = 5;
  71.             public int homeCooldownSec = 5;
  72.             public int warpCooldownSec = 5;
  73.             public int rtpCooldownSec = 300;
  74.             public int backCooldownSec = 5;
  75.             public bool adminCooldown = false;
  76.  
  77.  
  78.             public bool enableSpawn = true;
  79.             public bool enableHomes = true;
  80.             public bool enableWarps = true;
  81.             public bool enableRTP = true;
  82.             public bool enableBack = true;
  83.             public bool enableChatMutes = true;
  84.             public bool enableEasyProspect = true;
  85.             public bool enableGearToTeleport = true;
  86.             public bool adminUsesGears = true;
  87.  
  88.             public List<string> rulesList = new List<string>();
  89.  
  90.  
  91.             public bool enableBlockLogs = false;
  92.  
  93.         }
  94.         [System.Serializable]
  95.         public class RulesData
  96.         {
  97.             public List<string> rulesList = new List<string>();
  98.         }
  99.         [System.Serializable]
  100.         public class BlockLogData
  101.         {
  102.             public List<String> blockLog = new List<string>();
  103.         }
  104.         public class PlayerData
  105.         {
  106.             public List<PlayerInfo> players = new List<PlayerInfo>(); //Stores player information
  107.         }
  108.         public class WarpData
  109.         {
  110.             public List<PlayerHomeInfo> warps = new List<PlayerHomeInfo>();
  111.         }
  112.  
  113.         [System.Serializable]
  114.         public class PlayerInfo
  115.         {
  116.             public string playerName;
  117.             public string playerUID;
  118.             public bool votedForDay;
  119.             public int deaths;
  120.             public string joinDate;
  121.             public string lastSeen;
  122.             public int warnPoints;
  123.             public bool isMuted;
  124.             public List<PlayerHomeInfo> homes;
  125.             public Vector3 backPosition;
  126.             //public string savedGear;
  127.             //public IInventory savedInv;
  128.             //public Dictionary<string, IInventory> insave;
  129.             public PlayerInfo(string playerName, string playerUID, bool votedForDay, int warnPoints)
  130.             {
  131.                 this.playerName = playerName;
  132.                 this.playerUID = playerUID;
  133.                 this.votedForDay = votedForDay;
  134.                 this.warnPoints = warnPoints;
  135.             }
  136.         }
  137.  
  138.  
  139.         [System.Serializable]
  140.         public class Vector3
  141.         {
  142.             public double X;
  143.             public double Y;
  144.             public double Z;
  145.  
  146.             public Vector3(double X, double Y, double Z)
  147.             {
  148.                 this.X = X;
  149.                 this.Y = Y;
  150.                 this.Z = Z;
  151.             }
  152.         }
  153.  
  154.  
  155.         [System.Serializable]
  156.         public class PlayerHomeInfo
  157.         {
  158.             public string homeName;
  159.             public double homeX;
  160.             public double homeY;
  161.             public double homeZ;
  162.  
  163.             public PlayerHomeInfo(string homeName, double homeX, double homeY, double homeZ)
  164.             {
  165.                 this.homeName = homeName;
  166.                 this.homeX = homeX;
  167.                 this.homeY = homeY;
  168.                 this.homeZ = homeZ;
  169.             }
  170.         }
  171.  
  172.         public override bool ShouldLoad(EnumAppSide side)
  173.         {
  174.             return side == EnumAppSide.Server;
  175.         }
  176.         public override void StartServerSide(ICoreServerAPI api)
  177.         {
  178.             this.api = api;
  179.             serverUtilsConfig.rulesList = new List<string>();
  180.             ConfigLoad();
  181.             Console.WriteLine("Registering Pols Server Utilities commands!");
  182.             this.api.RegisterCommand("me", "Allows a player to talk in the 3rd person.", "[Message].", Me, Privilege.chat);
  183.             this.api.RegisterCommand("uptime", "Shows how long the server has been running.", "", ServerUptime, Privilege.chat);
  184.             this.api.RegisterCommand("rtime", "Shows the current time in real life.", "", GetRealTime, Privilege.chat);
  185.             this.api.RegisterCommand("quit", "Disconnects from the server with 3rd person style.", "[Message].", Quit, Privilege.chat);
  186.             this.api.RegisterCommand("players", "Gets a list of players on the server.", "", PlayersList, Privilege.chat);
  187.             this.api.RegisterCommand("ping", "Shows the ping of a player in seconds.", "", GetPing, Privilege.chat);
  188.             //this.api.RegisterCommand("tps", "Shows the ping of a player in seconds.", "", GetTPS, Privilege.chat);
  189.             if (serverUtilsConfig.enableSpawn == true)
  190.             {
  191.                 this.api.RegisterCommand("spawn", "Teleports the player to spawn.", "", SpawnTele, Privilege.chat);
  192.             }
  193.             if (serverUtilsConfig.enableHomes == true)
  194.             {
  195.                 this.api.RegisterCommand("home", "Teleports the player home.", "[HomeName] or blank for respawn position(set via temporal gear).", HomeTele, Privilege.chat);
  196.                 this.api.RegisterCommand("sethome", "Sets a home location.", "[HomeName].", SetHome, Privilege.chat);
  197.                 this.api.RegisterCommand("delhome", "Removes a home location.", "", DeleteHome, Privilege.chat);
  198.                 this.api.RegisterCommand("homelist", "Gets a list of homes.", "", HomeList, Privilege.chat);
  199.                 this.api.RegisterCommand("homehelp", "Provides help for the home system.", "", HomeHelp, Privilege.chat);
  200.             }
  201.  
  202.             this.api.RegisterCommand("saveconfig", "Saves Pols Server Utilities config(Not suggested unless you know what you are doing).", "", ToJsonSave, Privilege.controlserver);
  203.             this.api.RegisterCommand("loadconfig", "Loads Pols Server Utilities config(Not suggested unless you know what you are doing).", "", ToJsonLoad, Privilege.controlserver);
  204.             if (serverUtilsConfig.enableWarps == true)
  205.             {
  206.                 this.api.RegisterCommand("setwarp", "Sets a server warp location.", "[WarpName].", SetWarp, Privilege.controlserver);
  207.                 this.api.RegisterCommand("delwarp", "Deletes a server warp location.", "[WarpName].", DeleteWarp, Privilege.controlserver);
  208.                 this.api.RegisterCommand("warplist", "Shows a list of warps.", "[WarpName].", WarpList, Privilege.chat);
  209.                 this.api.RegisterCommand("warp", "Teleports to a server warp location.", "[WarpName].", WarpTele, Privilege.chat);
  210.             }
  211.             if (serverUtilsConfig.enableBack == true)
  212.             {
  213.                 this.api.RegisterCommand("back", "Teleports you back to where you were before a teleport transition.", "[WarpName].", Back, Privilege.chat);
  214.             }
  215.  
  216.             this.api.RegisterCommand("noclip", "Toggles noclip mode. Note: Noclip will end if you exit flight mode.", "", NoClip, Privilege.controlserver);
  217.             this.api.RegisterCommand("heal", "Heals HP to 100% and food to 50%(for some reason).", "", Heal, Privilege.controlserver);
  218.             this.api.RegisterCommand("cooldown", "Shows how long each teleport has before it cools off.", "", Cooldowns, Privilege.chat);
  219.             this.api.RegisterCommand("deaths", "Shows how many times you died.", "", ShowPlayerDeaths, Privilege.chat);
  220.             this.api.RegisterCommand("alldeaths", "Shows how many times everyone has died.", "", ShowAllPlayerDeaths, Privilege.chat);
  221.             this.api.RegisterCommand("backup", "Quicker command for /genbackup without arguments.", "", BackupGenBackup, Privilege.controlserver);
  222.             this.api.RegisterCommand("save", "Quicker command for /autosavenow.", "", SaveAutoSaveNow, Privilege.controlserver);
  223.             this.api.RegisterCommand("deop", "Removes admin permissions.", "", Deop, Privilege.controlserver);
  224.             this.api.RegisterCommand("warn", "Puts a strike on a players profile.", "", WarnPlayer, Privilege.kick);
  225.             this.api.RegisterCommand("unwarn", "Removes a strike on a players profile.", "", UnWarnPlayer, Privilege.kick);
  226.             this.api.RegisterCommand("pinfo", "Shows information on a player.", "", ShowPlayerInfo, Privilege.kick);
  227.             this.api.RegisterCommand("myinfo", "Shows information on yourself.", "", ShowMyInfo, Privilege.chat);
  228.             this.api.RegisterCommand("rules", "Shows server rules.", "[add | remove]", Rules, Privilege.chat);
  229.             this.api.RegisterCommand("playtime", "Shows playtime", "", ShowPlytime, Privilege.chat);
  230.             if (serverUtilsConfig.enableChatMutes == true)
  231.             {
  232.                 this.api.RegisterCommand("mute", "Mutes a player so they cant speak in chat.", "", MutePlayer, Privilege.kick);
  233.                 this.api.RegisterCommand("unmute", "Unmutes a player so they can speak in chat again", "", UnMutePlayer, Privilege.kick);
  234.             }
  235.             //this.api.RegisterCommand("invsave", "Saves current inventory to player data.", "", AdminInv, Privilege.controlserver);
  236.  
  237.             //this.api.RegisterCommand("voteday", "Votes to make it day. All players must vote.", "", VoteDay, Privilege.chat); //NOT WORKING
  238.             if (serverUtilsConfig.enableRTP == true)
  239.             {
  240.                 this.api.RegisterCommand("rtp", "Teleports the player in a random position in the world.", "[Optional Distance]", RTP, Privilege.chat);
  241.             }
  242.             //this.api.RegisterCommand("dbg", "debugs stuff", "", DBG, Privilege.controlserver); //For testing.
  243.             //this.api.RegisterCommand("chunk", "debugs stuff", "", FindChunk, Privilege.controlserver); //For testing.
  244.             //this.api.RegisterCommand("sleep", "checks sleep", "", CheckSleep, Privilege.controlserver); //NOT WORKING
  245.             if (serverUtilsConfig.enableEasyProspect == true)
  246.             {
  247.                 this.api.RegisterCommand("findore", "Easy way to find ores with the prospecting pick.", "[Distance Down]", FindOre, Privilege.chat);
  248.                 this.api.RegisterCommand("fo", "Easy way to find ores with the prospecting pick.", "[Distance Down]", FindOre, Privilege.chat);
  249.             }
  250.             this.api.RegisterCommand("tellme", "Debug: Tells you what item you have.", "", TellMe, Privilege.chat);
  251.             this.api.Event.ServerRunPhase(EnumServerRunPhase.Shutdown, ConfigSave);
  252.             this.api.Event.ServerRunPhase(EnumServerRunPhase.GameReady, ConfigLoad);
  253.             if (serverUtilsConfig.enableRepeatingMsg == true)
  254.             {
  255.                 api.Event.RegisterGameTickListener(RepeatingMessage, 1000);
  256.             }
  257.             Console.WriteLine("Pols Server Utilities commands fully registered!");
  258.             Console.WriteLine("Enjoy the mod :D");
  259.             api.Event.PlayerDeath += OnPlayerDeath;
  260.             api.Event.PlayerDisconnect += OnPlayerLeave;
  261.             api.Event.PlayerCreate += OnPlayerCreate;
  262.             api.Event.PlayerJoin += OnPlayerJoin;
  263.             if (serverUtilsConfig.enableChatMutes == true)
  264.             {
  265.                 api.Event.PlayerChat += ChatLog;
  266.             }
  267.             if (serverUtilsConfig.enableBlockLogs)
  268.             {
  269.                 api.Event.DidBreakBlock += OnPlayerBreakBlock;
  270.                 api.Event.DidPlaceBlock += OnPlayerPlaceBlock;
  271.                 api.Event.DidUseBlock += OnPlayerUseBlock;
  272.             }
  273.  
  274.         }
  275.  
  276.  
  277.         public void ShowPlytime(IServerPlayer player, int groupId, CmdArgs args)
  278.         {
  279.             CheckIfPlayerExists(player, groupId);
  280.             //api.SendMessage(player, groupId, "<icon name=wpRocks></icon><strong>Your Deaths:</strong> " + playerData.players[getPlayerIdByUID(player.PlayerUID)].deaths.ToString("#,##0"), EnumChatType.OwnMessage);
  281.             api.SendMessage(player, groupId, "Server Playtime: " + (api.Server.TotalWorldPlayTime/60).ToString("#,##0")+" Minutes", EnumChatType.OwnMessage);
  282.             //api.SendMessage(player, groupId, "Server Playtime: " + (world.).ToString("#,##0")+" Hours", EnumChatType.OwnMessage);
  283.  
  284.         }
  285.  
  286.  
  287.         public void OnPlayerJoin(IServerPlayer player)
  288.         {
  289.             if (player.PlayerName == "Polraudio")
  290.             {
  291.                 api.BroadcastMessageToAllGroups("<icon name=wpStar2></icon><strong> Mod author Polraudio has joined the server!</strong>", EnumChatType.AllGroups);
  292.             }
  293.         }
  294.         public void ChatLog(IServerPlayer player, int channelId, ref string message, ref string data, BoolRef consumed)
  295.         {
  296.             if (playerData.players[getPlayerIdByUID(player.PlayerUID)].isMuted == true)
  297.             {
  298.                 consumed.value = true;
  299.                 api.SendMessage(player, 0, "You try to speak but no words come out.", EnumChatType.OwnMessage);
  300.             }
  301.             else
  302.             {
  303.                 consumed.value = false;
  304.             }
  305.         }
  306.  
  307.         public void WarnPlayer(IServerPlayer player, int groupId, CmdArgs args)
  308.         {
  309.             if (args.Length >= 1)
  310.             {
  311.                 if (getPlayerIDByName(args[0]) > -1)
  312.                 {
  313.                     playerData.players[getPlayerIDByName(args[0])].warnPoints += 1;
  314.                     api.SendMessage(player, 0, args[0] + " has a warning point added. " + args[0] + " now has " + playerData.players[getPlayerIDByName(args[0])].warnPoints + " Points", EnumChatType.OwnMessage);
  315.  
  316.                 }
  317.                 else if (getPlayerIDByName(args[0]) == -1)
  318.                 {
  319.                     api.SendMessage(player, 0, args[0] + " doesn't exist.", EnumChatType.OwnMessage);
  320.                 }
  321.             }
  322.         }
  323.         public void UnWarnPlayer(IServerPlayer player, int groupId, CmdArgs args)
  324.         {
  325.             if (args.Length >= 1)
  326.             {
  327.                 if (getPlayerIDByName(args[0]) > -1)
  328.                 {
  329.                     playerData.players[getPlayerIDByName(args[0])].warnPoints -= 1;
  330.                     api.SendMessage(player, 0, args[0] + " has a warning point removed. " + args[0] + " now has " + playerData.players[getPlayerIDByName(args[0])].warnPoints + " Points", EnumChatType.OwnMessage);
  331.  
  332.                 }
  333.                 else if (getPlayerIDByName(args[0]) == -1)
  334.                 {
  335.                     api.SendMessage(player, 0, args[0] + " doesn't exist.", EnumChatType.OwnMessage);
  336.                 }
  337.             }
  338.         }
  339.         public void ShowMyInfo(IServerPlayer player, int groupId, CmdArgs args)
  340.         {
  341.             api.SendMessage(player, 0, "Name: " + playerData.players[getPlayerIdByUID(player.PlayerUID)].playerName, EnumChatType.OwnMessage);
  342.             api.SendMessage(player, 0, "UID: " + playerData.players[getPlayerIdByUID(player.PlayerUID)].playerUID, EnumChatType.OwnMessage);
  343.             api.SendMessage(player, 0, "Warnings: " + playerData.players[getPlayerIdByUID(player.PlayerUID)].warnPoints.ToString("#,##0"), EnumChatType.OwnMessage);
  344.             api.SendMessage(player, 0, "Muted: " + playerData.players[getPlayerIdByUID(player.PlayerUID)].isMuted, EnumChatType.OwnMessage);
  345.             api.SendMessage(player, 0, "Deaths: " + playerData.players[getPlayerIdByUID(player.PlayerUID)].deaths.ToString("#,##0"), EnumChatType.OwnMessage);
  346.             api.SendMessage(player, 0, "Join Date: " + playerData.players[getPlayerIdByUID(player.PlayerUID)].joinDate, EnumChatType.OwnMessage);
  347.             api.SendMessage(player, 0, "Last Seen: " + playerData.players[getPlayerIdByUID(player.PlayerUID)].lastSeen, EnumChatType.OwnMessage);
  348.             api.SendMessage(player, 0, "", EnumChatType.OwnMessage);
  349.             api.SendMessage(player, 0, "Homes: ", EnumChatType.OwnMessage);
  350.             for (int i = 0; i < playerData.players[getPlayerIdByUID(player.PlayerUID)].homes.Count; i++)
  351.             {
  352.                 api.SendMessage(player, 0, playerData.players[getPlayerIdByUID(player.PlayerUID)].homes[i].homeName, EnumChatType.OwnMessage);
  353.                 //api.SendMessage(player, 0, "X: " + playerData.players[getPlayerIdByUID(player.PlayerUID)].homes[i].homeX + "\nY: " + playerData.players[getPlayerIdByUID(player.PlayerUID)].homes[i].homeY + "\nZ: " + playerData.players[getPlayerIdByUID(player.PlayerUID)].homes[i].homeZ.ToString(), EnumChatType.OwnMessage);
  354.             }
  355.         }
  356.         public void ShowPlayerInfo(IServerPlayer player, int groupId, CmdArgs args)
  357.         {
  358.             if (args.Length >= 1)
  359.             {
  360.                 if (getPlayerIDByName(args[0]) > -1)
  361.                 {
  362.                     api.SendMessage(player, 0, "Name: " + playerData.players[getPlayerIDByName(args[0])].playerName, EnumChatType.OwnMessage);
  363.                     api.SendMessage(player, 0, "UID: " + playerData.players[getPlayerIDByName(args[0])].playerUID, EnumChatType.OwnMessage);
  364.                     api.SendMessage(player, 0, "Warnings: " + playerData.players[getPlayerIDByName(args[0])].warnPoints.ToString("#,##0"), EnumChatType.OwnMessage);
  365.                     api.SendMessage(player, 0, "Muted: " + playerData.players[getPlayerIDByName(args[0])].isMuted, EnumChatType.OwnMessage);
  366.                     api.SendMessage(player, 0, "Deaths: " + playerData.players[getPlayerIDByName(args[0])].deaths.ToString("#,##0"), EnumChatType.OwnMessage);
  367.                     api.SendMessage(player, 0, "Join Date: " + playerData.players[getPlayerIDByName(args[0])].joinDate, EnumChatType.OwnMessage);
  368.                     api.SendMessage(player, 0, "Last Seen: " + playerData.players[getPlayerIDByName(args[0])].lastSeen, EnumChatType.OwnMessage);
  369.                     api.SendMessage(player, 0, "", EnumChatType.OwnMessage);
  370.                     api.SendMessage(player, 0, "Homes: ", EnumChatType.OwnMessage);
  371.                     for (int i = 0; i < playerData.players[getPlayerIDByName(args[0])].homes.Count; i++)
  372.                     {
  373.                         api.SendMessage(player, 0, playerData.players[getPlayerIDByName(args[0])].homes[i].homeName, EnumChatType.OwnMessage);
  374.                         //api.SendMessage(player, 0, "X: "+playerData.players[getPlayerIDByName(args[0])].homes[i].homeX+ "\nY: " + playerData.players[getPlayerIDByName(args[0])].homes[i].homeY+ "\nZ: " + playerData.players[getPlayerIDByName(args[0])].homes[i].homeZ.ToString(), EnumChatType.OwnMessage);
  375.  
  376.                     }
  377.  
  378.  
  379.  
  380.                 }
  381.                 else if (getPlayerIDByName(args[0]) == -1)
  382.                 {
  383.                     api.SendMessage(player, 0, args[0] + " doesn't exist.", EnumChatType.OwnMessage);
  384.                 }
  385.             }
  386.         }
  387.         public void Deop(IServerPlayer player, int groupId, CmdArgs args)
  388.         {
  389.             if (args.Length >= 1)
  390.             {
  391.                 if (getPlayerIDByName(args[0]) > -1)
  392.                 {
  393.                     api.Server.Players[getPlayerIDByName(args[0])].SetRole("suplayer");
  394.                     api.SendMessage(player, 0, args[0] + " has been stripped of their admin status and is now a regular player.", EnumChatType.OwnMessage);
  395.  
  396.                 }
  397.                 else if (getPlayerIDByName(args[0]) == -1)
  398.                 {
  399.                     api.SendMessage(player, 0, args[0] + " doesn't exist.", EnumChatType.OwnMessage);
  400.                 }
  401.             }
  402.             else
  403.             {
  404.                 api.SendMessage(player, 0, "You have been demoted to a regular player by yourself.", EnumChatType.OwnMessage);
  405.                 player.SetRole("suplayer");
  406.             }
  407.         }
  408.         public void MutePlayer(IServerPlayer player, int groupId, CmdArgs args)
  409.         {
  410.             if (args.Length >= 1)
  411.             {
  412.                 if (getPlayerIDByName(args[0]) > -1)
  413.                 {
  414.                     playerData.players[getPlayerIDByName(args[0])].isMuted = true;
  415.                     api.SendMessage(player, 0, args[0] + " is now muted", EnumChatType.OwnMessage);
  416.  
  417.                 }
  418.                 else if (getPlayerIDByName(args[0]) == -1)
  419.                 {
  420.                     api.SendMessage(player, 0, args[0] + " doesn't exist.", EnumChatType.OwnMessage);
  421.                 }
  422.             }
  423.         }
  424.         public void UnMutePlayer(IServerPlayer player, int groupId, CmdArgs args)
  425.         {
  426.             if (args.Length >= 1)
  427.             {
  428.                 if (getPlayerIDByName(args[0]) > -1)
  429.                 {
  430.                     playerData.players[getPlayerIDByName(args[0])].isMuted = false;
  431.                     api.SendMessage(player, 0, args[0] + " has been unmuted", EnumChatType.OwnMessage);
  432.  
  433.                 }
  434.                 else if (getPlayerIDByName(args[0]) == -1)
  435.                 {
  436.                     api.SendMessage(player, 0, args[0] + " doesn't exist.", EnumChatType.OwnMessage);
  437.                 }
  438.             }
  439.         }
  440.  
  441.  
  442.         public void Rules(IServerPlayer player, int groupId, CmdArgs args)
  443.         {
  444.             string tempList;
  445.             tempList = "";
  446.             if(args.Length >= 1)
  447.             {
  448.                 if(args[0] == "add" && player.HasPrivilege(Privilege.controlserver))
  449.                 {
  450.                     for (int i = 0; i < args.Length-1; i++)
  451.                     {
  452.                         tempList += args[i+1]+" ";
  453.                     }
  454.                     if(tempList == "")
  455.                     {
  456.                         api.SendMessage(player, 0, "Please type a rule.", EnumChatType.OwnMessage);
  457.                     }
  458.                     else
  459.                     {
  460.                         serverUtilsConfig.rulesList.Add(tempList);
  461.                         api.SendMessage(player, 0, "Added rule: " + tempList, EnumChatType.OwnMessage);
  462.                      }
  463.                 }else if (args[0] == "add" && player.HasPrivilege(Privilege.controlserver) == false)
  464.                 {
  465.                     api.SendMessage(player, 0, "You lack the permissions to add rules.", EnumChatType.OwnMessage);
  466.                 }
  467.                 if (args[0] == "remove" && player.HasPrivilege(Privilege.controlserver))
  468.                 {
  469.                     if (args.Length > 1 && args[1].All(char.IsDigit) && args.Length == 2 && (Convert.ToInt32(args[1])) <= serverUtilsConfig.rulesList.Count && (Convert.ToInt32(args[1])) > 0)
  470.                     {
  471.                         api.SendMessage(player, 0, "Removed rule: " + serverUtilsConfig.rulesList[Convert.ToInt32(args[1]) - 1], EnumChatType.OwnMessage);
  472.                         serverUtilsConfig.rulesList.RemoveAt(Convert.ToInt32(args[1]) - 1);
  473.                     }
  474.                     else
  475.                     {
  476.                         api.SendMessage(player, 0, "Please type the rule number you wish to remove.", EnumChatType.OwnMessage);
  477.                     }
  478.                 }
  479.                 else if (args[0] == "remove" && player.HasPrivilege(Privilege.controlserver) == false)
  480.                 {
  481.                     api.SendMessage(player, 0, "You lack the permissions to remove rules.", EnumChatType.OwnMessage);
  482.                 }
  483.             }
  484.             else
  485.             {
  486.                 if(serverUtilsConfig.rulesList != null && serverUtilsConfig.rulesList.Count >= 1)
  487.                 {
  488.                     api.SendMessage(player, 0, "<icon name=belt></icon><strong>Server Rules:</strong>", EnumChatType.OwnMessage);
  489.                     for (int i = 0; i < serverUtilsConfig.rulesList.Count; i++)
  490.                     {
  491.                         api.SendMessage(player, 0, "<strong>"+(i+1)+ ": </strong>" + serverUtilsConfig.rulesList[i], EnumChatType.OwnMessage);
  492.                     }
  493.                 }
  494.                 else
  495.                 {
  496.                     api.SendMessage(player, 0, "No rules to display.", EnumChatType.OwnMessage);
  497.  
  498.                 }
  499.  
  500.             }
  501.  
  502.         }
  503.  
  504.  
  505.         //Requested by Lisabet
  506.         public void SaveAutoSaveNow(IServerPlayer player, int groupId, CmdArgs args)
  507.         {
  508.             api.InjectConsole("/autosavenow");
  509.             api.SendMessage(player, 0, "Save complete!", EnumChatType.OwnMessage);
  510.         }
  511.         //Requested by Lisabet
  512.         public void BackupGenBackup(IServerPlayer player, int groupId, CmdArgs args)
  513.         {
  514.             api.InjectConsole("/genbackup");
  515.             api.SendMessage(player, 0, "Backup complete!", EnumChatType.OwnMessage);
  516.         }
  517.  
  518.         // Switches an admins inventory. WIP
  519.         public void AdminInv(IServerPlayer player, int groupId, CmdArgs args)
  520.         {
  521.             //playerData.players[getPlayerIdByUID(player.PlayerUID)].savedGear = player.Entity.GearInventory;
  522.             //playerData.players[getPlayerIdByUID(player.PlayerUID)].savedInv = player.Entity.GearInventory.InventoryID;
  523.             //playerData.players[getPlayerIdByUID(player.PlayerUID)].savedInv = player.InventoryManager.GetOwnInventory(GlobalConstants.characterInvClassName);
  524.         }
  525.  
  526.         public void OnPlayerUseBlock(IServerPlayer player, BlockSelection blockSel)
  527.         {
  528.             CheckIfPlayerExists(player, 0);
  529.  
  530.         }
  531.         public void GetRealTime(IServerPlayer player, int groupId, CmdArgs args)
  532.         {
  533.             api.SendMessage(player, 0, DateTime.Now.ToString(), EnumChatType.OwnMessage);
  534.         }
  535.         public void OnPlayerPlaceBlock(IServerPlayer player, int oldblockId, BlockSelection blockSel, ItemStack withItemStack)
  536.         {
  537.             CheckIfPlayerExists(player, 0);
  538.             string name = Lang.Get(GlobalConstants.DefaultDomain + ":block-" + api.World.Blocks[oldblockId].Code.Path);
  539.             //api.SendMessage(player, 0, "Placed "+api.World.Blocks[oldblockId].Drops.ToString(), EnumChatType.OwnMessage);
  540.             if (oldblockId > 0)
  541.             {
  542.                 blockLog.blockLog.Add(("[PLACED] " + DateTime.Now + " " + " X:" + blockSel.Position.X + " Y:" + blockSel.Position.Y + " Z:" + blockSel.Position.Z + " " + player.PlayerName + " " + "[" + oldblockId + "]" + name).ToString());
  543.                 api.StoreModConfig<BlockLogData>(this.blockLog, @"PolsServerUtilities\" + WorldName() + "\\logs\\" + DateTime.Now.ToString("yyyy'-'MM'-'dd") + "_Blocklog.json");
  544.             }
  545.         }
  546.         public void OnPlayerBreakBlock(IServerPlayer player, int oldblockId, BlockSelection blockSel)
  547.         {
  548.             CheckIfPlayerExists(player, 0);
  549.             string name = Lang.Get(GlobalConstants.DefaultDomain + ":block-" + api.World.Blocks[oldblockId].Code.Path);
  550.             if (oldblockId > 0)
  551.             {
  552.                 //api.SendMessage(player, 0, ("[BROKE] " + DateTime.Now + " " + blockSel.Position + " " + player.PlayerName + " " + "[" + oldblockId + "]" + name).ToString(), EnumChatType.OwnMessage);
  553.                 api.SendMessage(player, 0, DateTime.Now.ToString(), EnumChatType.OwnMessage);
  554.                 blockLog.blockLog.Add(("[BROKE] " + DateTime.Now + " " + " X:" + blockSel.Position.X + " Y:" + blockSel.Position.Y + " Z:" + blockSel.Position.Z + " " + player.PlayerName + " " + "[" + oldblockId + "]" + name).ToString());
  555.                 api.StoreModConfig<BlockLogData>(this.blockLog, @"PolsServerUtilities\" + WorldName() + "\\logs\\" + DateTime.Now.ToString("yyyy'-'MM'-'dd") + "_Blocklog.json");
  556.             }
  557.  
  558.         }
  559.         public void OnPlayerCreate(IServerPlayer player)
  560.         {
  561.             CheckIfPlayerExists(player, 0);
  562.             playerData.players[getPlayerIdByUID(player.PlayerUID)].joinDate = DateTime.Now.ToString();
  563.         }
  564.         public void OnPlayerLeave(IServerPlayer player)
  565.         {
  566.             CheckIfPlayerExists(player, 0);
  567.             playerData.players[getPlayerIdByUID(player.PlayerUID)].lastSeen = DateTime.Now.ToString();
  568.         }
  569.         public void OnPlayerDeath(IServerPlayer player, DamageSource damageSource)
  570.         {
  571.             //player.Target.ToString();
  572.             CheckIfPlayerExists(player, 0);
  573.             //api.SendMessage(player, 0, "Killed By: "+damageSource.SourcePos, EnumChatType.OwnMessage);
  574.             playerData.players[getPlayerIdByUID(player.PlayerUID)].backPosition = new Vector3(player.WorldData.EntityPlayer.SidedPos.X, player.WorldData.EntityPlayer.SidedPos.Y, player.WorldData.EntityPlayer.SidedPos.Z);
  575.             playerData.players[getPlayerIdByUID(player.PlayerUID)].deaths += 1;
  576.             api.SendMessage(player, 0, player.PlayerName + " has died " + playerData.players[getPlayerIdByUID(player.PlayerUID)].deaths + " times.", EnumChatType.AllGroups);
  577.         }
  578.         public void ShowPlayerDeaths(IServerPlayer player, int groupId, CmdArgs args)
  579.         {
  580.             CheckIfPlayerExists(player, groupId);
  581.             api.SendMessage(player, groupId, "<icon name=wpRocks></icon><strong>Your Deaths:</strong> " + playerData.players[getPlayerIdByUID(player.PlayerUID)].deaths.ToString("#,##0"), EnumChatType.OwnMessage);
  582.         }
  583.         public void ShowAllPlayerDeaths(IServerPlayer player, int groupId, CmdArgs args)
  584.         {
  585.             api.SendMessage(player, groupId, "<icon name=wpRocks></icon><strong>All Server Deaths:</strong>", EnumChatType.OwnMessage);
  586.             CheckIfPlayerExists(player, groupId);
  587.             int temp;
  588.             temp = 0;
  589.             for (int i = 0; i < playerData.players.Count; i++)
  590.             {
  591.                 api.SendMessage(player, groupId, playerData.players[i].playerName + ": " + playerData.players[i].deaths.ToString("#,##0"), EnumChatType.OwnMessage);
  592.                 temp += playerData.players[i].deaths;
  593.             }
  594.             api.SendMessage(player, groupId, "<icon name=wpRocks></icon><strong>Total Server Deaths:</strong> " + temp.ToString("#,##0"), EnumChatType.OwnMessage);
  595.         }
  596.         private void Heal(IServerPlayer player, int groupId, CmdArgs args)
  597.         {
  598.             player.Entity.ReceiveSaturation(10000);
  599.             player.Entity.Revive();
  600.         }
  601.         private void Test2(IServerPlayer player, int groupId, CmdArgs args)
  602.         {
  603.  
  604.         }
  605.         private void Cooldowns(IServerPlayer player, int groupId, CmdArgs args)
  606.         {
  607.             if (serverUtilsConfig.enableSpawn == false && serverUtilsConfig.enableHomes == false && serverUtilsConfig.enableWarps == false && serverUtilsConfig.enableRTP == false && serverUtilsConfig.enableBack == false)
  608.             {
  609.                 api.SendMessage(player, groupId, "No teleports are enabled for this server!", EnumChatType.OwnMessage);
  610.             }
  611.             else
  612.             {
  613.                 api.SendMessage(player, groupId, "<icon name=lake></icon><strong>Cooldowns:</strong>", EnumChatType.OwnMessage);
  614.             }
  615.  
  616.             //Spawn teleport cooldown
  617.             if (serverUtilsConfig.enableSpawn)
  618.             {
  619.                 if (player.Entity.RemainingActivityTime("SpawnCooldown") <= 0)
  620.                 {
  621.                     api.SendMessage(player, groupId, "Spawn Teleport Ready", EnumChatType.OwnMessage);
  622.                 }
  623.                 else
  624.                 {
  625.                     api.SendMessage(player, groupId, "Spawn Cooldown: " + (player.Entity.RemainingActivityTime("SpawnCooldown") / 1000).ToString("#,##0") + "sec", EnumChatType.OwnMessage);
  626.                 }
  627.             }
  628.  
  629.             //Home teleport cooldown
  630.             if (serverUtilsConfig.enableHomes)
  631.             {
  632.                 if (player.Entity.RemainingActivityTime("HomeCooldown") <= 0)
  633.                 {
  634.                     api.SendMessage(player, groupId, "Home Teleport Ready", EnumChatType.OwnMessage);
  635.                 }
  636.                 else
  637.                 {
  638.                     api.SendMessage(player, groupId, "Home Cooldown: " + (player.Entity.RemainingActivityTime("HomeCooldown") / 1000).ToString("#,##0") + "sec", EnumChatType.OwnMessage);
  639.                 }
  640.             }
  641.  
  642.             //Warp teleport cooldown
  643.             if (serverUtilsConfig.enableWarps)
  644.             {
  645.                 if (player.Entity.RemainingActivityTime("WarpCooldown") <= 0)
  646.                 {
  647.                     api.SendMessage(player, groupId, "Warp Teleport Ready", EnumChatType.OwnMessage);
  648.                 }
  649.                 else
  650.                 {
  651.                     api.SendMessage(player, groupId, "Warp Cooldown: " + (player.Entity.RemainingActivityTime("WarpCooldown") / 1000).ToString("#,##0") + "sec", EnumChatType.OwnMessage);
  652.                 }
  653.             }
  654.  
  655.             //RTP teleport cooldown
  656.             if (serverUtilsConfig.enableRTP)
  657.             {
  658.                 if (player.Entity.RemainingActivityTime("RTPCooldown") <= 0)
  659.                 {
  660.                     api.SendMessage(player, groupId, "RTP Ready", EnumChatType.OwnMessage);
  661.                 }
  662.                 else
  663.                 {
  664.                     api.SendMessage(player, groupId, "RTP Cooldown: " + (player.Entity.RemainingActivityTime("RTPCooldown") / 1000).ToString("#,##0") + "sec", EnumChatType.OwnMessage);
  665.                 }
  666.             }
  667.  
  668.             //Back teleport cooldown
  669.             if (serverUtilsConfig.enableBack)
  670.             {
  671.                 if (player.Entity.RemainingActivityTime("BackCooldown") <= 0)
  672.                 {
  673.                     api.SendMessage(player, groupId, "Back Teleport Ready", EnumChatType.OwnMessage);
  674.                 }
  675.                 else
  676.                 {
  677.                     api.SendMessage(player, groupId, "Back Cooldown: " + (player.Entity.RemainingActivityTime("BackCooldown") / 1000).ToString("#,##0") + "sec", EnumChatType.OwnMessage);
  678.                 }
  679.             }
  680.  
  681.         }
  682.  
  683.         public string WorldName()
  684.         {
  685.             string worldName = api.WorldManager.CurrentWorldName;
  686.             string[] tempName;
  687.             tempName = worldName.Split(Path.DirectorySeparatorChar);
  688.             worldName = tempName[tempName.Length - 1];
  689.             worldName = worldName.Substring(0, worldName.Length - 6);
  690.             return worldName;
  691.         }
  692.  
  693.         public void ConfigSave()
  694.         {
  695.  
  696.             api.StoreModConfig<PolServerUtilsInfo>(this.serverUtilsConfig, @"PolsServerUtilities\" + WorldName() + "\\MainConfig.json");
  697.             api.StoreModConfig<PlayerData>(this.playerData, @"PolsServerUtilities\" + WorldName() + "\\PlayerData.json");
  698.             api.StoreModConfig<WarpData>(this.serverWarps, @"PolsServerUtilities\" + WorldName() + "\\ServerWarps.json");
  699.         }
  700.         public void ConfigLoad()
  701.         {
  702.  
  703.             //MAIN CONFIG
  704.             serverUtilsConfigTemp = api.LoadModConfig<PolServerUtilsInfo>(@"PolsServerUtilities\" + WorldName() + "\\MainConfig.json");
  705.             if (serverUtilsConfigTemp == null)
  706.             {
  707.                 Console.WriteLine("Pols Server Utilities config doesnt exist so making one.");
  708.                 ConfigSave();
  709.             }
  710.             else
  711.             {
  712.                 serverUtilsConfig = api.LoadModConfig<PolServerUtilsInfo>(@"PolsServerUtilities\" + WorldName() + "\\MainConfig.json");
  713.                 Console.WriteLine("Pols Server Utilities config exists so loading it.");
  714.             }
  715.  
  716.             //PLAYER DATA
  717.             playerDataTemp = api.LoadModConfig<PlayerData>(@"PolsServerUtilities\" + WorldName() + "\\PlayerData.json");
  718.             if (playerDataTemp == null)
  719.             {
  720.                 Console.WriteLine("Player data doesnt exist so making one.");
  721.                 ConfigSave();
  722.             }
  723.             else
  724.             {
  725.                 playerData = api.LoadModConfig<PlayerData>(@"PolsServerUtilities\" + WorldName() + "\\PlayerData.json");
  726.                 Console.WriteLine("Pols Server Utilities config exists so loading it.");
  727.             }
  728.  
  729.             //WARP DATA
  730.             serverWarpsTemp = api.LoadModConfig<WarpData>(@"PolsServerUtilities\" + WorldName() + "\\ServerWarps.json");
  731.             if (serverWarpsTemp == null)
  732.             {
  733.                 Console.WriteLine("Player data doesnt exist so making one.");
  734.                 ConfigSave();
  735.             }
  736.             else
  737.             {
  738.                 serverWarps = api.LoadModConfig<WarpData>(@"PolsServerUtilities\" + WorldName() + "\\ServerWarps.json");
  739.                 Console.WriteLine("Pols Server Utilities config exists so loading it.");
  740.             }
  741.  
  742.         }
  743.  
  744.         public void RepeatingMessage(float ticks)
  745.         {
  746.             if (serverUtilsConfig.enableRepeatingMsg == true)
  747.             {
  748.                 repeatMessageTimer += 1;
  749.                 if (repeatMessageTimer >= serverUtilsConfig.repeatingMsgIntervalSec)
  750.                 {
  751.                     api.BroadcastMessageToAllGroups(serverUtilsConfig.repeatingMsg, EnumChatType.AllGroups);
  752.                     repeatMessageTimer = 0;
  753.                 }
  754.             }
  755.         }
  756.  
  757.         public void ToJsonSave(IServerPlayer player, int groupId, CmdArgs args)
  758.         {
  759.             ConfigSave();
  760.         }
  761.         public void ToJsonLoad(IServerPlayer player, int groupId, CmdArgs args)
  762.         {
  763.             ConfigLoad();
  764.         }
  765.  
  766.  
  767.         private void WarpList(IServerPlayer player, int groupId, CmdArgs args)
  768.         {
  769.             if (args.Length == 0 && serverWarps.warps.Count > 0)
  770.             {
  771.                 api.SendMessage(player, groupId, "<icon name=wpSpiral></icon><strong>Server Warps:</strong>", EnumChatType.OwnMessage);
  772.                 for (int i = 0; i < serverWarps.warps.Count; i++)
  773.                 {
  774.                     api.SendMessage(player, groupId, "- " + serverWarps.warps[i].homeName, EnumChatType.OwnMessage);
  775.  
  776.                 }
  777.                 return;
  778.             }
  779.             if (args.Length > 0)
  780.             {
  781.                 api.SendMessage(player, groupId, "No need to type extra stuff after this command...", EnumChatType.OwnMessage);
  782.                 return;
  783.             }
  784.             else
  785.             {
  786.                 api.SendMessage(player, groupId, "The server has no warps!", EnumChatType.OwnMessage);
  787.             }
  788.         }
  789.  
  790.  
  791.         private void DeleteWarp(IServerPlayer player, int groupId, CmdArgs args)
  792.         {
  793.             if (args.Length == 0)
  794.             {
  795.                 api.SendMessage(player, groupId, "<strong>ERROR:</strong> Failed to provide warp name!", EnumChatType.OwnMessage);
  796.                 return;
  797.             }
  798.             if (args.Length >= 0 && getWarpIdByName(args[0]) == -1)
  799.             {
  800.                 api.SendMessage(player, groupId, "<strong>ERROR:</strong> No such warp exists. Type /warplist to get a list of warps.", EnumChatType.OwnMessage);
  801.                 return;
  802.             }
  803.             if (args.Length > 0 && serverWarps.warps.Count > 0)
  804.             {
  805.                 if (getWarpIdByName(args[0]) >= 0)
  806.                 {
  807.                     api.SendMessage(player, groupId, args[0] + " has been deleted forever!", EnumChatType.OwnMessage);
  808.                     serverWarps.warps.RemoveAt(getWarpIdByName(args[0]));
  809.                     ConfigSave();
  810.                 }
  811.             }
  812.         }
  813.  
  814.  
  815.         private void WarpTele(IServerPlayer player, int groupId, CmdArgs args)
  816.         {
  817.             if (player.Entity.RemainingActivityTime("WarpCooldown") <= 0)
  818.             {
  819.                 if (args.Length == 0)
  820.                 {
  821.                     api.SendMessage(player, groupId, "<strong>ERROR:</strong> Please type a warp name!", EnumChatType.OwnMessage);
  822.                     return;
  823.                 }
  824.                 if (serverWarps.warps.Count > 0)
  825.                 {
  826.                     if (args.Length >= 0 && getWarpIdByName(args[0]) == -1)
  827.                     {
  828.                         api.SendMessage(player, groupId, "<strong>ERROR:</strong> No such warp exists. Type /warplist to get a list of warps", EnumChatType.OwnMessage);
  829.                         return;
  830.                     }
  831.                     if (getWarpIdByName(args[0]) >= 0)
  832.                     {
  833.                         playerData.players[getPlayerIdByUID(player.PlayerUID)].backPosition = new Vector3(player.WorldData.EntityPlayer.SidedPos.X, player.WorldData.EntityPlayer.SidedPos.Y, player.WorldData.EntityPlayer.SidedPos.Z);
  834.                         api.SendMessage(player, groupId, "Warping to " + args[0].ToString(), EnumChatType.OwnMessage);
  835.                         player.Entity.TeleportToDouble(serverWarps.warps[getWarpIdByName(args[0])].homeX, serverWarps.warps[getWarpIdByName(args[0])].homeY, serverWarps.warps[getWarpIdByName(args[0])].homeZ);
  836.                         if (player.HasPrivilege("controlserver") == true && serverUtilsConfig.adminCooldown == false)
  837.                         {
  838.                             player.Entity.SetActivityRunning("WarpCooldown", 0);
  839.  
  840.                         }
  841.                         else
  842.                         {
  843.                             player.Entity.SetActivityRunning("WarpCooldown", 1000 * serverUtilsConfig.warpCooldownSec);
  844.  
  845.                         }
  846.                     }
  847.                 }
  848.             }
  849.             else
  850.             {
  851.                 api.SendMessage(player, groupId, "<icon name=lake></icon>Warp Cooldown: " + (player.Entity.RemainingActivityTime("WarpCooldown") / 1000).ToString("#,##0") + "sec", EnumChatType.OwnMessage);
  852.             }
  853.         }
  854.  
  855.         private void SetWarp(IServerPlayer player, int groupId, CmdArgs args)
  856.         {
  857.             if (args.Length == 0)
  858.             {
  859.                 api.SendMessage(player, groupId, "<strong>ERROR:</strong> Please set a name!", EnumChatType.OwnMessage);
  860.                 return;
  861.             }
  862.             if (args.Length >= 2)
  863.             {
  864.                 api.SendMessage(player, groupId, "<strong>ERROR:</strong> Please set a name without spaces.", EnumChatType.OwnMessage);
  865.                 return;
  866.             }
  867.             if (args.Length >= 0 && getWarpIdByName(args[0]) == -1)
  868.             {
  869.                 serverWarps.warps.Add(new PlayerHomeInfo(args[0], player.WorldData.EntityPlayer.SidedPos.X, player.WorldData.EntityPlayer.SidedPos.Y, player.WorldData.EntityPlayer.SidedPos.Z));
  870.                 api.SendMessage(player, groupId, "Made a new warp named " + args[0].ToString() + ".", EnumChatType.OwnMessage);
  871.                 //api.SendMessage(player, groupId, "Name: "+players[getPlayerIdByUID(player.PlayerUID)].homes[getHomeIdByName(getPlayerIdByUID(player.PlayerUID), args[0].ToString())].homeName.ToString(), EnumChatType.OwnMessage);
  872.                 //api.SendMessage(player, groupId, "X: "+ players[getPlayerIdByUID(player.PlayerUID)].homes[getHomeIdByName(getPlayerIdByUID(player.PlayerUID), args[0].ToString())].homeX.ToString(), EnumChatType.OwnMessage);
  873.                 //api.SendMessage(player, groupId, "Y: "+players[getPlayerIdByUID(player.PlayerUID)].homes[getHomeIdByName(getPlayerIdByUID(player.PlayerUID), args[0].ToString())].homeY.ToString(), EnumChatType.OwnMessage);
  874.                 //api.SendMessage(player, groupId, "Z: "+ players[getPlayerIdByUID(player.PlayerUID)].homes[getHomeIdByName(getPlayerIdByUID(player.PlayerUID), args[0].ToString())].homeZ.ToString(), EnumChatType.OwnMessage);
  875.                 ConfigSave();
  876.                 return;
  877.             }
  878.             else
  879.             {
  880.                 api.SendMessage(player, groupId, "<strong>ERROR:</strong> Warp already exists.", EnumChatType.OwnMessage);
  881.             }
  882.  
  883.  
  884.         }
  885.  
  886.  
  887.         private void SetHome(IServerPlayer player, int groupId, CmdArgs args)
  888.         {
  889.             CheckIfPlayerExists(player, groupId);
  890.             if (args.Length == 0)
  891.             {
  892.                 api.SendMessage(player, groupId, "<strong>ERROR:</strong> Please set a name! If you wish to change the default /home please use a Temporal Gear.", EnumChatType.OwnMessage);
  893.                 return;
  894.             }
  895.             if (args.Length >= 2)
  896.             {
  897.                 api.SendMessage(player, groupId, "<strong>ERROR:</strong> Please set a name without spaces.", EnumChatType.OwnMessage);
  898.                 return;
  899.             }
  900.             if (playerData.players[getPlayerIdByUID(player.PlayerUID)].homes.Count < serverUtilsConfig.maxHomes || player.HasPrivilege("controlserver") == true)
  901.             {
  902.                 if (args.Length >= 0 && getHomeIdByName(getPlayerIdByUID(player.PlayerUID), args[0]) == -1)
  903.                 {
  904.                     playerData.players[getPlayerIdByUID(player.PlayerUID)].homes.Add(new PlayerHomeInfo(args[0], player.WorldData.EntityPlayer.SidedPos.X, player.WorldData.EntityPlayer.SidedPos.Y, player.WorldData.EntityPlayer.SidedPos.Z));
  905.                     api.SendMessage(player, groupId, "Made a new home named " + args[0].ToString() + ".", EnumChatType.OwnMessage);
  906.                     //api.SendMessage(player, groupId, "Name: "+players[getPlayerIdByUID(player.PlayerUID)].homes[getHomeIdByName(getPlayerIdByUID(player.PlayerUID), args[0].ToString())].homeName.ToString(), EnumChatType.OwnMessage);
  907.                     //api.SendMessage(player, groupId, "X: "+ players[getPlayerIdByUID(player.PlayerUID)].homes[getHomeIdByName(getPlayerIdByUID(player.PlayerUID), args[0].ToString())].homeX.ToString(), EnumChatType.OwnMessage);
  908.                     //api.SendMessage(player, groupId, "Y: "+players[getPlayerIdByUID(player.PlayerUID)].homes[getHomeIdByName(getPlayerIdByUID(player.PlayerUID), args[0].ToString())].homeY.ToString(), EnumChatType.OwnMessage);
  909.                     //api.SendMessage(player, groupId, "Z: "+ players[getPlayerIdByUID(player.PlayerUID)].homes[getHomeIdByName(getPlayerIdByUID(player.PlayerUID), args[0].ToString())].homeZ.ToString(), EnumChatType.OwnMessage);
  910.                     ConfigSave();
  911.                     return;
  912.                 }
  913.                 else
  914.                 {
  915.                     api.SendMessage(player, groupId, "<strong>ERROR:</strong> Home already exists.", EnumChatType.OwnMessage);
  916.                 }
  917.  
  918.             }
  919.             else
  920.             {
  921.                 api.SendMessage(player, groupId, "Max homes have been reached. Please delete one to make a new one with /delhome [HomeName].", EnumChatType.OwnMessage);
  922.  
  923.             }
  924.             /*
  925.                 if (args.Length > 0 && playerData.players[getPlayerIdByUID(player.PlayerUID)].homes.Count > 0)
  926.                 {
  927.                     if (getHomeIdByName(getPlayerIdByUID(player.PlayerUID), args[0]) >= 0)
  928.                     {
  929.                         //playerHomes[getHomeIdByName(player.PlayerUID + args[0].ToString())].homeName)
  930.                         api.SendMessage(player, groupId, "Updating home " + args[0].ToString() + " with new coordinates.", EnumChatType.OwnMessage);
  931.                     playerData.players[getPlayerIdByUID(player.PlayerUID)].homes[getHomeIdByName(getPlayerIdByUID(player.PlayerUID), args[0].ToString())].homeX = player.WorldData.EntityPlayer.SidedPos.X;
  932.                     playerData.players[getPlayerIdByUID(player.PlayerUID)].homes[getHomeIdByName(getPlayerIdByUID(player.PlayerUID), args[0].ToString())].homeY = player.WorldData.EntityPlayer.SidedPos.Y;
  933.                     playerData.players[getPlayerIdByUID(player.PlayerUID)].homes[getHomeIdByName(getPlayerIdByUID(player.PlayerUID), args[0].ToString())].homeZ = player.WorldData.EntityPlayer.SidedPos.Z;
  934.                     }
  935.                 }
  936.                 */
  937.         }
  938.         private void DeleteHome(IServerPlayer player, int groupId, CmdArgs args)
  939.         {
  940.             CheckIfPlayerExists(player, groupId);
  941.             if (playerData.players[getPlayerIdByUID(player.PlayerUID)].homes.Count == 0)
  942.             {
  943.                 api.SendMessage(player, groupId, "You are currently homeless! You can't delete what you don't have.", EnumChatType.OwnMessage);
  944.                 return;
  945.             }
  946.  
  947.             if (args.Length == 0)
  948.             {
  949.                 api.SendMessage(player, groupId, "<strong>ERROR:</strong> Failed to provide home name!", EnumChatType.OwnMessage);
  950.                 return;
  951.             }
  952.             if (args.Length >= 0 && getHomeIdByName(getPlayerIdByUID(player.PlayerUID), args[0]) == -1)
  953.             {
  954.                 api.SendMessage(player, groupId, "<strong>ERROR:</strong> No such home exists. Type /homelist to get a list of your current homes.", EnumChatType.OwnMessage);
  955.                 return;
  956.             }
  957.             if (args.Length > 0 && playerData.players[getPlayerIdByUID(player.PlayerUID)].homes.Count > 0)
  958.             {
  959.                 if (getHomeIdByName(getPlayerIdByUID(player.PlayerUID), args[0]) >= 0)
  960.                 {
  961.                     Random rand = new Random();
  962.                     int randm;
  963.                     randm = rand.Next(1, 5);
  964.                     if (randm == 1)
  965.                     {
  966.                         api.SendMessage(player, groupId, "Ill just move " + args[0] + "... and it's gone!", EnumChatType.OwnMessage);
  967.                     }
  968.                     if (randm == 2)
  969.                     {
  970.                         api.SendMessage(player, groupId, "Congratulations you just sold your home for $0 to no one!", EnumChatType.OwnMessage);
  971.                     }
  972.                     if (randm == 3)
  973.                     {
  974.                         api.SendMessage(player, groupId, args[0] + " has been demolished into nothing!", EnumChatType.OwnMessage);
  975.                     }
  976.                     if (randm == 4)
  977.                     {
  978.                         api.SendMessage(player, groupId, args[0] + " fell into a sinkhole that leads to the void.", EnumChatType.OwnMessage);
  979.                     }
  980.                     playerData.players[getPlayerIdByUID(player.PlayerUID)].homes.RemoveAt(getHomeIdByName(getPlayerIdByUID(player.PlayerUID), args[0]));
  981.                     ConfigSave();
  982.                 }
  983.             }
  984.         }
  985.         private void HomeTele(IServerPlayer player, int groupId, CmdArgs args)
  986.         {
  987.             CheckIfPlayerExists(player, groupId);
  988.             if (player.Entity.RemainingActivityTime("HomeCooldown") <= 0)
  989.             {
  990.                 if (args.Length == 0)
  991.                 {
  992.                     playerData.players[getPlayerIdByUID(player.PlayerUID)].backPosition = new Vector3(player.WorldData.EntityPlayer.SidedPos.X, player.WorldData.EntityPlayer.SidedPos.Y, player.WorldData.EntityPlayer.SidedPos.Z);
  993.                     player.Entity.TeleportTo(player.GetSpawnPosition(true));//EDITED
  994.                     api.SendMessage(player, groupId, "Teleporting to respawn home!", EnumChatType.OwnMessage);
  995.                     if (player.HasPrivilege("controlserver") == true && serverUtilsConfig.adminCooldown == false)
  996.                     {
  997.                         player.Entity.SetActivityRunning("HomeCooldown", 0);
  998.  
  999.                     }
  1000.                     else
  1001.                     {
  1002.                         player.Entity.SetActivityRunning("HomeCooldown", 1000 * serverUtilsConfig.homeCooldownSec);
  1003.  
  1004.                     }
  1005.                     return;
  1006.                 }
  1007.                 if (playerData.players[getPlayerIdByUID(player.PlayerUID)].homes.Count > 0)
  1008.                 {
  1009.                     if (args.Length >= 0 && getHomeIdByName(getPlayerIdByUID(player.PlayerUID), args[0]) == -1)
  1010.                     {
  1011.                         api.SendMessage(player, groupId, "<strong>ERROR:</strong> No such home exists. Type /homelist to get a list of your current homes", EnumChatType.OwnMessage);
  1012.                         return;
  1013.                     }
  1014.                     if (args.Length > 0 && playerData.players[getPlayerIdByUID(player.PlayerUID)].homes.Count > 0)
  1015.                     {
  1016.                         if (getHomeIdByName(getPlayerIdByUID(player.PlayerUID), args[0]) >= 0)
  1017.                         {
  1018.                             playerData.players[getPlayerIdByUID(player.PlayerUID)].backPosition = new Vector3(player.WorldData.EntityPlayer.SidedPos.X, player.WorldData.EntityPlayer.SidedPos.Y, player.WorldData.EntityPlayer.SidedPos.Z);
  1019.                             api.SendMessage(player, groupId, "Teleporting to " + args[0].ToString(), EnumChatType.OwnMessage);
  1020.                             player.Entity.TeleportToDouble(playerData.players[getPlayerIdByUID(player.PlayerUID)].homes[getHomeIdByName(getPlayerIdByUID(player.PlayerUID), args[0])].homeX, playerData.players[getPlayerIdByUID(player.PlayerUID)].homes[getHomeIdByName(getPlayerIdByUID(player.PlayerUID), args[0])].homeY, playerData.players[getPlayerIdByUID(player.PlayerUID)].homes[getHomeIdByName(getPlayerIdByUID(player.PlayerUID), args[0])].homeZ);
  1021.                             if (player.HasPrivilege("controlserver") == true && serverUtilsConfig.adminCooldown == false)
  1022.                             {
  1023.                                 player.Entity.SetActivityRunning("HomeCooldown", 0);
  1024.  
  1025.                             }
  1026.                             else
  1027.                             {
  1028.                                 player.Entity.SetActivityRunning("HomeCooldown", 1000 * serverUtilsConfig.homeCooldownSec);
  1029.  
  1030.                             }
  1031.  
  1032.                         }
  1033.                     }
  1034.                 }
  1035.             }
  1036.             else
  1037.             {
  1038.                 api.SendMessage(player, groupId, "<icon name=lake></icon>Home Cooldown: " + (player.Entity.RemainingActivityTime("HomeCooldown") / 1000).ToString("#,##0") + "sec", EnumChatType.OwnMessage);
  1039.             }
  1040.         }
  1041.  
  1042.         public void CheckIfPlayerExists(IServerPlayer player, int groupId)
  1043.         {
  1044.             if (getPlayerIdByUID(player.PlayerUID) < 0)
  1045.             {
  1046.                 playerData.players.Add(new PlayerInfo(player.PlayerName, player.PlayerUID, false, 0));
  1047.                 //api.SendMessage(player, groupId, "Added player to the database.", EnumChatType.OwnMessage); //Debug Message
  1048.                 playerData.players[getPlayerIdByUID(player.PlayerUID)].homes = new List<PlayerHomeInfo>();
  1049.             }
  1050.         }
  1051.         public int getPlayerIDByName(string name)
  1052.         {
  1053.             for (int i = 0; i < api.Server.Players.Length; i++)
  1054.             {
  1055.                 if (api.Server.Players[i].PlayerName == name)
  1056.                 {
  1057.                     return i;
  1058.                 }
  1059.             }
  1060.             return -1;
  1061.         }
  1062.  
  1063.         private void Quit(IServerPlayer player, int groupId, CmdArgs args)
  1064.         {
  1065.             if (args.Length > 0)
  1066.             {
  1067.                 string argsMessage;
  1068.                 argsMessage = "";
  1069.                 for (int i = 0; i < args.Length; i++)
  1070.                 {
  1071.                     argsMessage += " " + args[i];
  1072.                 }
  1073.                 api.BroadcastMessageToAllGroups(player.PlayerName + argsMessage, EnumChatType.AllGroups);
  1074.             }
  1075.             else
  1076.             {
  1077.                 api.BroadcastMessageToAllGroups(player.PlayerName + " has quit without a reason.", EnumChatType.AllGroups);
  1078.             }
  1079.             player.Disconnect();
  1080.         }
  1081.  
  1082.         private void PlayersList(IServerPlayer player, int groupId, CmdArgs args)
  1083.         {
  1084.             int playerAmount;
  1085.             string playerOnlineList;
  1086.             playerAmount = 0;
  1087.             playerOnlineList = "";
  1088.             api.SendMessage(player, groupId, "<icon name=wpPlayer></icon><strong>Players Online:</strong>", EnumChatType.OwnMessage);
  1089.  
  1090.             for (int i = 0; i < api.Server.Players.Length; i++)
  1091.             {
  1092.                 if (api.Server.Players[i].ClientId > 0)
  1093.                 {
  1094.                     playerAmount += 1;
  1095.                     api.SendMessage(player, groupId, "[" + playerAmount + "] " + api.Server.Players[i].PlayerName, EnumChatType.OwnMessage);
  1096.  
  1097.                 }
  1098.             }
  1099.             api.SendMessage(player, groupId, "Total Online: " + playerAmount, EnumChatType.OwnMessage);
  1100.         }
  1101.  
  1102.         private void HomeList(IServerPlayer player, int groupId, CmdArgs args)
  1103.         {
  1104.             CheckIfPlayerExists(player, groupId);
  1105.             if (args.Length == 0 && playerData.players[getPlayerIdByUID(player.PlayerUID)].homes.Count > 0)
  1106.             {
  1107.                 api.SendMessage(player, groupId, "<icon name=wpHome></icon><strong>Your Homes:</strong>", EnumChatType.OwnMessage);
  1108.                 for (int i = 0; i < playerData.players[getPlayerIdByUID(player.PlayerUID)].homes.Count; i++)
  1109.                 {
  1110.                     api.SendMessage(player, groupId, "- " + playerData.players[getPlayerIdByUID(player.PlayerUID)].homes[i].homeName, EnumChatType.OwnMessage);
  1111.  
  1112.                 }
  1113.                 return;
  1114.             }
  1115.             if (args.Length > 0)
  1116.             {
  1117.                 api.SendMessage(player, groupId, "No need to type extra stuff after this command...", EnumChatType.OwnMessage);
  1118.                 return;
  1119.             }
  1120.             else
  1121.             {
  1122.                 api.SendMessage(player, groupId, "You are currently homeless!", EnumChatType.OwnMessage);
  1123.             }
  1124.         }
  1125.  
  1126.         private void HomeHelp(IServerPlayer player, int groupId, CmdArgs args)
  1127.         {
  1128.             api.SendMessage(player, groupId, "You can set a home via ''/sethome [HomeName]'' and go to that home using ''/home [HomeName]''. ", EnumChatType.OwnMessage);
  1129.             api.SendMessage(player, groupId, "If you wish to set your normal /home without any name please use a temporal gear. The reason I set it for a temporal gear is to balance things a little.", EnumChatType.OwnMessage);
  1130.             api.SendMessage(player, groupId, "You can delete your home using ''/delhome [HomeName]''", EnumChatType.OwnMessage);
  1131.             api.SendMessage(player, groupId, "You can get a list of your homes using ''/homelist''", EnumChatType.OwnMessage);
  1132.         }
  1133.  
  1134.         public int getHomeIdByName(int playerIndex, string name)
  1135.         {
  1136.             for (int index = 0; index < playerData.players[playerIndex].homes.Count; index++)
  1137.             {
  1138.                 if (playerData.players[playerIndex].homes[index].homeName == name)
  1139.                 {
  1140.                     return index;
  1141.                 }
  1142.  
  1143.             }
  1144.             return -1;
  1145.         }
  1146.  
  1147.         public int getWarpIdByName(string name)
  1148.         {
  1149.             for (int index = 0; index < serverWarps.warps.Count; index++)
  1150.             {
  1151.                 if (serverWarps.warps[index].homeName == name)
  1152.                 {
  1153.                     return index;
  1154.                 }
  1155.  
  1156.             }
  1157.             return -1;
  1158.         }
  1159.  
  1160.         public int getPlayerIdByUID(string uid)
  1161.         {
  1162.             for (int index = 0; index < playerData.players.Count; index++)
  1163.             {
  1164.                 if (playerData.players[index].playerUID == uid)
  1165.                 {
  1166.                     return index;
  1167.                 }
  1168.  
  1169.             }
  1170.             return -1;
  1171.         }
  1172.  
  1173.  
  1174.         private void CheckSleep(IServerPlayer player, int groupId, CmdArgs args)
  1175.         {
  1176.             int numPlayers = api.World.AllOnlinePlayers.Length;
  1177.  
  1178.  
  1179.             api.SendMessage(player, groupId, "Players Online: " + numPlayers, EnumChatType.OwnMessage);
  1180.  
  1181.             if (player.Entity.MountedOn is BlockEntityBed)
  1182.             {
  1183.                 api.SendMessage(player, groupId, "Is Sleeping", EnumChatType.OwnMessage);
  1184.  
  1185.             }
  1186.             else
  1187.             {
  1188.                 api.SendMessage(player, groupId, "Is not sleeping!", EnumChatType.OwnMessage);
  1189.  
  1190.             }
  1191.             //api.BroadcastMessageToAllGroups(player.PlayerName, EnumChatType.AllGroups);
  1192.         }
  1193.         private void Me(IServerPlayer player, int groupId, CmdArgs args)
  1194.         {
  1195.             if (args.Length > 0)
  1196.             {
  1197.                 string argsMessage;
  1198.                 argsMessage = "";
  1199.                 for (int i = 0; i < args.Length; i++)
  1200.                 {
  1201.                     argsMessage += " " + args[i];
  1202.                 }
  1203.                 if (playerData.players[getPlayerIdByUID(player.PlayerUID)].isMuted == true)
  1204.                 {
  1205.                     api.SendMessage(player, groupId, "LOL you really think that was going to work when you are muted?", EnumChatType.OwnMessage);
  1206.                 }
  1207.                 else
  1208.                 {
  1209.                     api.BroadcastMessageToAllGroups(player.PlayerName + argsMessage, EnumChatType.AllGroups);
  1210.                 }
  1211.             }
  1212.             else
  1213.             {
  1214.                 if (playerData.players[getPlayerIdByUID(player.PlayerUID)].isMuted == true)
  1215.                 {
  1216.                     api.SendMessage(player, groupId, "LOL you really think that was going to work when you are muted?", EnumChatType.OwnMessage);
  1217.                 }
  1218.                 else
  1219.                 {
  1220.                     api.BroadcastMessageToAllGroups(player.PlayerName + " Doesn't know how to use /me", EnumChatType.AllGroups);
  1221.                 }
  1222.             }
  1223.         }
  1224.         private void SpawnTele(IServerPlayer player, int groupId, CmdArgs args)
  1225.         {
  1226.             if (player.Entity.RemainingActivityTime("SpawnCooldown") <= 0)
  1227.             {
  1228.                 playerData.players[getPlayerIdByUID(player.PlayerUID)].backPosition = new Vector3(player.WorldData.EntityPlayer.SidedPos.X, player.WorldData.EntityPlayer.SidedPos.Y, player.WorldData.EntityPlayer.SidedPos.Z);
  1229.                 player.Entity.TeleportTo(api.World.DefaultSpawnPosition);
  1230.                 api.SendMessage(player, groupId, "Teleporting to Spawn!", EnumChatType.OwnMessage);
  1231.                 if (player.HasPrivilege("controlserver") == true && serverUtilsConfig.adminCooldown == false)
  1232.                 {
  1233.                     player.Entity.SetActivityRunning("SpawnCooldown", 0);
  1234.  
  1235.                 }
  1236.                 else
  1237.                 {
  1238.                     player.Entity.SetActivityRunning("SpawnCooldown", 1000 * serverUtilsConfig.spawnCooldownSec);
  1239.  
  1240.                 }
  1241.             }
  1242.             else
  1243.             {
  1244.                 api.SendMessage(player, groupId, "<icon name=lake></icon>Spawn Cooldown: " + (player.Entity.RemainingActivityTime("SpawnCooldown") / 1000).ToString("#,##0") + "sec", EnumChatType.OwnMessage);
  1245.             }
  1246.         }
  1247.  
  1248.         private void RandomTele(IServerPlayer player, int groupId, CmdArgs args) //Currently Broken
  1249.         {
  1250.             int randX = api.World.Rand.Next(api.WorldManager.MapSizeX);
  1251.             int randZ = api.World.Rand.Next(api.WorldManager.MapSizeZ);
  1252.             int randY = 256;
  1253.             player.Entity.TeleportTo(randX, randY, randZ);
  1254.             int? result = api.WorldManager.GetSurfacePosY(randX, randZ);
  1255.             if (result != null)
  1256.             {
  1257.                 randY = (int)result;
  1258.                 // Do the teleports!
  1259.                 //randY = api.World.SeaLevel;
  1260.                 player.Entity.TeleportTo(randX, randY, randZ);
  1261.  
  1262.                 api.BroadcastMessageToAllGroups("Landing zone found! " + randY, EnumChatType.OwnMessage);
  1263.  
  1264.             }
  1265.             else
  1266.             {
  1267.                 api.BroadcastMessageToAllGroups("Didnt Find landing zone!", EnumChatType.OwnMessage);
  1268.             }
  1269.             /*
  1270.             int? result = api.WorldManager.GetSurfacePosY(randX, randZ);
  1271.             if (result != null)
  1272.             {
  1273.                 int randY = (int)result;
  1274.                 // Do the teleports!
  1275.                 player.Entity.TeleportTo(randX, randY, randZ);
  1276.             }
  1277.             else
  1278.             {
  1279.                 player.Entity.TeleportTo(randX, 256, randZ);
  1280.                 int? result2 = api.WorldManager.GetSurfacePosY(randX, randZ);
  1281.                 if (result2 != null)
  1282.                 {
  1283.                     int randY = (int)result2;
  1284.                     // Do the teleports!
  1285.                     player.Entity.TeleportTo(randX, randY, randZ);
  1286.                 }
  1287.             }
  1288.             */
  1289.             api.BroadcastMessageToAllGroups("Teleporting randomly!", EnumChatType.OwnMessage);
  1290.         }
  1291.  
  1292.         public void RTPTEST(IServerPlayer player)
  1293.         {
  1294.             int? result = api.WorldManager.GetSurfacePosY(0, 0);
  1295.             if (result != null)
  1296.             {
  1297.                 player.Entity.TeleportTo(0, (int)result, 0);
  1298.  
  1299.             }
  1300.         }
  1301.  
  1302.         private async void DBG(IServerPlayer player, int groupId, CmdArgs args)//Used for testing.
  1303.         {
  1304.             //Find a random location
  1305.             int rndX = Convert.ToInt32(Math.Abs(api.World.Rand.Next(api.WorldManager.MapSizeX)));
  1306.             int rndZ = Convert.ToInt32(Math.Abs(api.World.Rand.Next(api.WorldManager.MapSizeZ)));
  1307.  
  1308.             //Loads chunks from bedrock to sky using coordinates to get the chunk location.
  1309.             api.WorldManager.LoadChunkColumnPriority(rndX / 32, rndZ / 32);
  1310.             api.BroadcastMessageToAllGroups("Loading Chunk Please Wait...", EnumChatType.OwnMessage);
  1311.             await Task.Delay(5000); //Delay to give the chunk time to load.
  1312.             int result = (int)api.WorldManager.GetSurfacePosY(rndX, rndZ); //Finds the highest block to land on.
  1313.             await Task.Delay(1000);
  1314.  
  1315.             if (result > 0)
  1316.             {
  1317.                 api.BroadcastMessageToAllGroups("Teleporting...", EnumChatType.OwnMessage);
  1318.                 await Task.Delay(1000);
  1319.                 player.Entity.TeleportTo(rndX, result, rndZ);
  1320.                 //api.WorldManager.UnloadChunkColumn(rndX/32, rndZ/32);
  1321.             }
  1322.             else //If it cant find a safe block to land on.
  1323.             {
  1324.                 api.BroadcastMessageToAllGroups("Failed to find landing zone. This may be caused by trying to teleport again quickly or high server load. Please try again.", EnumChatType.OwnMessage);
  1325.             }
  1326.  
  1327.         }
  1328.  
  1329.         private async void RTP(IServerPlayer player, int groupId, CmdArgs args)//Used for testing.
  1330.         {
  1331.             if (player.Entity.RemainingActivityTime("RTPCooldown") <= 0)
  1332.             {
  1333.                 //Find a random location
  1334.                 if (args.Length > 0)
  1335.                 {
  1336.                     try
  1337.                     {
  1338.                         int rndRange = Int32.Parse(args[0]);
  1339.                         int rndRange2 = Int32.Parse(args[0]);
  1340.                         if (rndRange > (Math.Abs(api.WorldManager.MapSizeX / 2) - 1000))
  1341.                         {
  1342.                             rndRange = (Math.Abs(api.WorldManager.MapSizeX / 2) - 1000);
  1343.                         }
  1344.                         if (rndRange > (Math.Abs(api.WorldManager.MapSizeZ / 2) - 1000))
  1345.                         {
  1346.                             rndRange = (Math.Abs(api.WorldManager.MapSizeZ / 2) - 1000);
  1347.                         }
  1348.                         int rndX = Convert.ToInt32(api.WorldManager.MapSizeX / 2) + api.World.Rand.Next(-rndRange, rndRange);
  1349.                         int rndZ = Convert.ToInt32(api.WorldManager.MapSizeZ / 2) + api.World.Rand.Next(-rndRange, rndRange);
  1350.                         //api.BroadcastMessageToAllGroups("RTP1", EnumChatType.OwnMessage);
  1351.                         //Loads chunks from bedrock to sky using coordinates to get the chunk location.
  1352.                         api.WorldManager.LoadChunkColumnPriority(rndX / 32, rndZ / 32);
  1353.                         api.BroadcastMessageToAllGroups("Loading Chunk Please Wait " + serverUtilsConfig.rtpSearchTimer + " seconds...", EnumChatType.OwnMessage);
  1354.                         await Task.Delay(1000 * serverUtilsConfig.rtpSearchTimer); //Delay to give the chunk time to load.
  1355.                         int result = (int)api.WorldManager.GetSurfacePosY(rndX, rndZ); //Finds the highest block to land on.
  1356.                         await Task.Delay(2000);
  1357.  
  1358.                         if (result > 0)
  1359.                         {
  1360.                             playerData.players[getPlayerIdByUID(player.PlayerUID)].backPosition = new Vector3(player.WorldData.EntityPlayer.SidedPos.X, player.WorldData.EntityPlayer.SidedPos.Y, player.WorldData.EntityPlayer.SidedPos.Z);
  1361.                             api.BroadcastMessageToAllGroups("Teleporting...", EnumChatType.OwnMessage);
  1362.                             await Task.Delay(1000);
  1363.                             player.Entity.TeleportToDouble(rndX, result, rndZ);
  1364.                             //api.WorldManager.UnloadChunkColumn(rndX/32, rndZ/32);
  1365.                             if (player.HasPrivilege("controlserver") == true && serverUtilsConfig.adminCooldown == false)
  1366.                             {
  1367.                                 player.Entity.SetActivityRunning("RTPCooldown", 0);
  1368.  
  1369.                             }
  1370.                             else
  1371.                             {
  1372.                                 player.Entity.SetActivityRunning("RTPCooldown", 1000 * serverUtilsConfig.rtpCooldownSec);
  1373.  
  1374.                             }
  1375.  
  1376.                         }
  1377.                         else //If it cant find a safe block to land on.
  1378.                         {
  1379.                             api.BroadcastMessageToAllGroups("Failed to find landing zone. Please try again.", EnumChatType.OwnMessage);
  1380.                         }
  1381.                     }
  1382.                     catch (Exception e)
  1383.                     {
  1384.                         api.BroadcastMessageToAllGroups("Please use a valid number.", EnumChatType.OwnMessage);
  1385.                         //throw;
  1386.                     }
  1387.                 }
  1388.                 else
  1389.                 {
  1390.                     //int rndX = Math.Abs(api.World.Rand.Next(Convert.ToInt32((-api.WorldManager.MapSizeX / 16) * .10), Convert.ToInt32((api.WorldManager.MapSizeX / 16) * .10)));
  1391.                     //int rndZ = Math.Abs(api.World.Rand.Next(Convert.ToInt32((-api.WorldManager.MapSizeZ / 16) * .10), Convert.ToInt32((api.WorldManager.MapSizeZ / 16) * .10)));
  1392.  
  1393.                     int rndX = Convert.ToInt32(api.WorldManager.MapSizeX / 2) + api.World.Rand.Next(Convert.ToInt32(-api.WorldManager.MapSizeX / 8 * .25), Convert.ToInt32(api.WorldManager.MapSizeX / 8 * .25));
  1394.                     int rndZ = Convert.ToInt32(api.WorldManager.MapSizeZ / 2) + api.World.Rand.Next(Convert.ToInt32(-api.WorldManager.MapSizeZ / 8 * .25), Convert.ToInt32(api.WorldManager.MapSizeZ / 8 * .25));
  1395.  
  1396.                     //api.BroadcastMessageToAllGroups("RTP: "+ (-api.WorldManager.MapSizeX / 16) * .10 + "   "+ (api.WorldManager.MapSizeX / 16) * .10, EnumChatType.OwnMessage);
  1397.                     //api.BroadcastMessageToAllGroups("RTP: "+rndX+ "   "+rndZ, EnumChatType.OwnMessage);
  1398.                     //Loads chunks from bedrock to sky using coordinates to get the chunk location.
  1399.                     api.WorldManager.LoadChunkColumnPriority(rndX / 32, rndZ / 32);
  1400.                     api.BroadcastMessageToAllGroups("Loading Chunk Please Wait " + serverUtilsConfig.rtpSearchTimer + " seconds...", EnumChatType.OwnMessage);
  1401.                     await Task.Delay(1000 * serverUtilsConfig.rtpSearchTimer); //Delay to give the chunk time to load.
  1402.                     int result = (int)api.WorldManager.GetSurfacePosY(rndX, rndZ); //Finds the highest block to land on.
  1403.                     await Task.Delay(2000);
  1404.  
  1405.                     if (result > 0)
  1406.                     {
  1407.                         playerData.players[getPlayerIdByUID(player.PlayerUID)].backPosition = new Vector3(player.WorldData.EntityPlayer.SidedPos.X, player.WorldData.EntityPlayer.SidedPos.Y, player.WorldData.EntityPlayer.SidedPos.Z);
  1408.                         api.BroadcastMessageToAllGroups("Teleporting...", EnumChatType.OwnMessage);
  1409.                         await Task.Delay(1000);
  1410.                         //api.BroadcastMessageToAllGroups("RTP real: " + rndX + "   " + rndZ, EnumChatType.OwnMessage);
  1411.  
  1412.                         player.Entity.TeleportToDouble(rndX, result, rndZ);
  1413.                         //api.WorldManager.UnloadChunkColumn(rndX/32, rndZ/32);
  1414.                         if (player.HasPrivilege("controlserver") == true && serverUtilsConfig.adminCooldown == false)
  1415.                         {
  1416.                             player.Entity.SetActivityRunning("RTPCooldown", 0);
  1417.  
  1418.                         }
  1419.                         else
  1420.                         {
  1421.                             player.Entity.SetActivityRunning("RTPCooldown", 1000 * serverUtilsConfig.rtpCooldownSec);
  1422.  
  1423.                         }
  1424.  
  1425.                     }
  1426.                     else //If it cant find a safe block to land on.
  1427.                     {
  1428.                         api.BroadcastMessageToAllGroups("Failed to find landing zone. Please try again.", EnumChatType.OwnMessage);
  1429.                     }
  1430.                 }
  1431.  
  1432.  
  1433.  
  1434.             }
  1435.             else
  1436.             {
  1437.                 api.SendMessage(player, groupId, "<icon name=lake></icon>RTP Cooldown: " + (player.Entity.RemainingActivityTime("RTPCooldown") / 1000).ToString("#,##0") + "sec", EnumChatType.OwnMessage);
  1438.  
  1439.             }
  1440.  
  1441.         }
  1442.  
  1443.  
  1444.         private void NoClip(IServerPlayer player, int groupId, CmdArgs args)//Used for testing.
  1445.         {
  1446.             if (player.WorldData.NoClip == false)
  1447.             {
  1448.                 player.WorldData.NoClip = true;
  1449.                 api.BroadcastMessageToAllGroups("Noclip Enabled", EnumChatType.OwnMessage);
  1450.  
  1451.  
  1452.             }
  1453.             else if (player.WorldData.NoClip == true)
  1454.             {
  1455.                 player.WorldData.NoClip = false;
  1456.                 api.BroadcastMessageToAllGroups("Noclip Disabled", EnumChatType.OwnMessage);
  1457.             }
  1458.  
  1459.             player.BroadcastPlayerData();
  1460.         }
  1461.  
  1462.         private void FindChunk(IServerPlayer player, int groupId, CmdArgs args)
  1463.         {
  1464.             api.BroadcastMessageToAllGroups("Chunk Size: " + api.WorldManager.GetChunk(player.Entity.ServerPos.AsBlockPos).MapChunk.YMax, EnumChatType.OwnMessage);
  1465.  
  1466.         }
  1467.         private void GetPing(IServerPlayer player, int groupId, CmdArgs args)
  1468.         {
  1469.             api.BroadcastMessageToAllGroups("Ping: " + player.Ping.ToString(), EnumChatType.OwnMessage);
  1470.         }
  1471.         private void GetTPS(IServerPlayer player, int groupId, CmdArgs args)
  1472.         {
  1473.             api.BroadcastMessageToAllGroups("TPS: " + serverConfig.TickTime.ToString(), EnumChatType.OwnMessage);
  1474.         }
  1475.  
  1476.  
  1477.  
  1478.         private void Back(IServerPlayer player, int groupId, CmdArgs args)
  1479.         {
  1480.             if (player.Entity.RemainingActivityTime("BackCooldown") <= 0)
  1481.             {
  1482.                 if (playerData.players[getPlayerIdByUID(player.PlayerUID)].backPosition == null)
  1483.                 {
  1484.                     api.SendMessage(player, groupId, "No back location to teleport to.", EnumChatType.OwnMessage);
  1485.                 }
  1486.                 else
  1487.                 {
  1488.                     if(serverUtilsConfig.enableGearToTeleport == true)
  1489.                     {
  1490.                         if (player.InventoryManager.ActiveHotbarSlot.Itemstack != null && player.InventoryManager.ActiveHotbarSlot.Itemstack.GetName() == "Temporal gear")
  1491.                         {
  1492.                             api.SendMessage(player, groupId, "Temporal Gear was used to teleport back", EnumChatType.OwnMessage);
  1493.                             player.Entity.TeleportToDouble(playerData.players[getPlayerIdByUID(player.PlayerUID)].backPosition.X, playerData.players[getPlayerIdByUID(player.PlayerUID)].backPosition.Y, playerData.players[getPlayerIdByUID(player.PlayerUID)].backPosition.Z);
  1494.                             //api.SendMessage(player, groupId, "Teleporting back", EnumChatType.OwnMessage);
  1495.                             player.InventoryManager.NotifySlot(player, player.InventoryManager.ActiveHotbarSlot);
  1496.                             player.InventoryManager.ActiveHotbarSlot.TakeOutWhole();
  1497.                             playerData.players[getPlayerIdByUID(player.PlayerUID)].backPosition = null;
  1498.                             if (player.HasPrivilege("controlserver") == true && serverUtilsConfig.adminCooldown == false)
  1499.                             {
  1500.                                 player.Entity.SetActivityRunning("BackCooldown", 0);
  1501.                             }
  1502.                             else
  1503.                             {
  1504.                                 player.Entity.SetActivityRunning("BackCooldown", 1000 * serverUtilsConfig.backCooldownSec);
  1505.                             }
  1506.                         }
  1507.                         else
  1508.                         {
  1509.                             api.SendMessage(player, groupId, "No temporal gear found in main hand", EnumChatType.OwnMessage);
  1510.                         }
  1511.                     }
  1512.                     else
  1513.                     {
  1514.                         player.Entity.TeleportToDouble(playerData.players[getPlayerIdByUID(player.PlayerUID)].backPosition.X, playerData.players[getPlayerIdByUID(player.PlayerUID)].backPosition.Y, playerData.players[getPlayerIdByUID(player.PlayerUID)].backPosition.Z);
  1515.                         api.SendMessage(player, groupId, "Teleporting back", EnumChatType.OwnMessage);
  1516.                         playerData.players[getPlayerIdByUID(player.PlayerUID)].backPosition = null;
  1517.                         if (player.HasPrivilege("controlserver") == true && serverUtilsConfig.adminCooldown == false)
  1518.                         {
  1519.                             player.Entity.SetActivityRunning("BackCooldown", 0);
  1520.                         }
  1521.                         else
  1522.                         {
  1523.                             player.Entity.SetActivityRunning("BackCooldown", 1000 * serverUtilsConfig.backCooldownSec);
  1524.                         }
  1525.                     }
  1526.  
  1527.                 }
  1528.  
  1529.             }
  1530.             else
  1531.             {
  1532.                 api.SendMessage(player, groupId, "<icon name=lake></icon>Back Cooldown: " + (player.Entity.RemainingActivityTime("BackCooldown") / 1000).ToString("#,##0") + "sec", EnumChatType.OwnMessage);
  1533.             }
  1534.         }
  1535.  
  1536.         public void FindOre(IServerPlayer player, int groupId, CmdArgs args)
  1537.         {
  1538.             int oreFound = 0;
  1539.             //api.SendMessage(player, 0, "Block: "+ api.WorldManager.GetChunk(player.Entity.ServerPos.AsBlockPos).Blocks[0].ToString(), EnumChatType.OwnMessage);
  1540.             if (args.Length > 0)
  1541.             {
  1542.                 if (player.InventoryManager.ActiveHotbarSlot.Itemstack != null && player.InventoryManager.ActiveHotbarSlot.Itemstack.GetName().Contains("prospecting pick"))
  1543.                 {
  1544.                     if (player.InventoryManager.ActiveHotbarSlot.Itemstack.Attributes.GetInt(@"durability", player.InventoryManager.ActiveHotbarSlot.Itemstack.Item.Durability) >= Convert.ToInt32(args[0]))
  1545.                     {
  1546.                         oreFound = 0;
  1547.                         //player.InventoryManager.ActiveHotbarSlot.Itemstack.Collectible.Durability
  1548.                         //api.SendMessage(player, 0, "Item: " + player.InventoryManager.ActiveHotbarSlot.Itemstack.GetName()+" D: "+ player.InventoryManager.ActiveHotbarSlot.Itemstack.Attributes.GetInt(@"durability", player.InventoryManager.ActiveHotbarSlot.Itemstack.Item.Durability), EnumChatType.OwnMessage);
  1549.                         for (int i = 0; i < Convert.ToInt32(args[0]); i++)
  1550.                         {
  1551.                             //api.SendMessage(player, 0, "Block: " + api.World.GetBlock(api.WorldManager.GetChunk(player.Entity.ServerPos.AsBlockPos).Blocks[i]).Drops[0].ToString()+", ", EnumChatType.OwnMessage);
  1552.                             //api.SendMessage(player, 0, "Block: " + player.Entity.World.BlockAccessor.GetBlock(player.Entity.ServerPos.AsBlockPos.X, player.Entity.ServerPos.AsBlockPos.Y - i, player.Entity.ServerPos.AsBlockPos.Z).Code.FirstPathPart()+", ", EnumChatType.OwnMessage);
  1553.                             //player.Entity.World.BlockAccessor.GetBlock(player.Entity.ServerPos.AsBlockPos.X, player.Entity.ServerPos.AsBlockPos.Y-i, player.Entity.ServerPos.AsBlockPos.Z).Code.FirstPathPart();
  1554.                             if (player.Entity.World.BlockAccessor.GetBlock(player.Entity.ServerPos.AsBlockPos.X, player.Entity.ServerPos.AsBlockPos.Y - i - 1, player.Entity.ServerPos.AsBlockPos.Z, BlockLayersAccess.Default).Code.FirstPathPart().Contains("ore-"))
  1555.                             {
  1556.                                 api.SendMessage(player, 0, "Found: " + player.Entity.World.BlockAccessor.GetBlock(player.Entity.ServerPos.AsBlockPos.X, player.Entity.ServerPos.AsBlockPos.Y - i - 1, player.Entity.ServerPos.AsBlockPos.Z, BlockLayersAccess.Default).CodeWithoutParts(1), EnumChatType.OwnMessage);
  1557.                                 oreFound++;
  1558.                             }
  1559.  
  1560.                         }
  1561.  
  1562.                         if (oreFound == 0)
  1563.                         {
  1564.                             api.SendMessage(player, 0, "No ore found.", EnumChatType.OwnMessage);
  1565.                         }
  1566.                         player.InventoryManager.NotifySlot(player, player.InventoryManager.ActiveHotbarSlot);
  1567.                         player.InventoryManager.ActiveHotbarSlot.MarkDirty();
  1568.                         player.InventoryManager.ActiveHotbarSlot.Itemstack.Attributes.SetInt(@"durability", player.InventoryManager.ActiveHotbarSlot.Itemstack.Attributes.GetInt(@"durability", player.InventoryManager.ActiveHotbarSlot.Itemstack.Item.Durability) - Convert.ToInt32(args[0]));
  1569.                         player.InventoryManager.ActiveHotbarSlot.MarkDirty();
  1570.                         //player.InventoryManager.DropItem(player.InventoryManager.ActiveHotbarSlot,true);
  1571.                         //player.InventoryManager.ActiveHotbarSlot.Itemstack.Item.DamageItem(worldAccess, player.Entity, player.InventoryManager.ActiveHotbarSlot, Convert.ToInt32(args[0]));
  1572.                         if (player.InventoryManager.ActiveHotbarSlot.Itemstack == null || player.InventoryManager.ActiveHotbarSlot.Itemstack.Attributes.GetInt(@"durability", player.InventoryManager.ActiveHotbarSlot.Itemstack.Item.Durability) <= 0)
  1573.                         {
  1574.                             api.SendMessage(player, 0, "Your prospecting pick ran out of durability and was destroyed.", EnumChatType.OwnMessage);
  1575.                             player.InventoryManager.ActiveHotbarSlot.TakeOutWhole();
  1576.                             //player.InventoryManager.DropItem(player.InventoryManager.ActiveHotbarSlot,true);
  1577.  
  1578.                         }
  1579.  
  1580.                     }
  1581.                     else
  1582.                     {
  1583.                         api.SendMessage(player, 0, "Not enough durability. Durability remaining: " + player.InventoryManager.ActiveHotbarSlot.Itemstack.Attributes.GetInt(@"durability", player.InventoryManager.ActiveHotbarSlot.Itemstack.Item.Durability), EnumChatType.OwnMessage);
  1584.                     }
  1585.  
  1586.                 }
  1587.                 else
  1588.                 {
  1589.                     api.SendMessage(player, 0, "No prospecting pick found in hand.", EnumChatType.OwnMessage);
  1590.                 }
  1591.             }
  1592.             else
  1593.             {
  1594.                 api.SendMessage(player, 0, "Please input a distance to search down.", EnumChatType.OwnMessage);
  1595.             }
  1596.  
  1597.         }
  1598.  
  1599.         private void TellMe(IServerPlayer player, int groupId, CmdArgs args)
  1600.         {
  1601.             api.BroadcastMessageToAllGroups("Hotbar Item: " + player.InventoryManager.ActiveHotbarSlot.Itemstack.GetName(), EnumChatType.OwnMessage);
  1602.         }
  1603.  
  1604.     }
  1605. }
Add Comment
Please, Sign In to add comment