Polraudio

Pols Server Utilities

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