Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Newtonsoft.Json;
- using Newtonsoft.Json.Linq;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Data.SqlClient;
- using System.IO;
- using System.Linq;
- using System.Reflection;
- using System.Runtime.CompilerServices;
- using System.Security.Cryptography.X509Certificates;
- using System.Threading.Tasks;
- using System.Xml;
- using System.Xml.Serialization;
- using Vintagestory.API;
- using Vintagestory.API.Common;
- using Vintagestory.API.Config;
- using Vintagestory.API.Datastructures;
- using Vintagestory.API.Server;
- using Vintagestory.API.Util;
- using Vintagestory.GameContent;
- namespace VintagestoryServerUtils
- {
- public class Main : ModSystem
- {
- public ICoreServerAPI api;
- public IWorldPlayerData wpdata;
- private WorldMapManager world;
- private IServerEventAPI serverEvent;
- private IServerConfig serverConfig;
- private IServerWorldAccessor worldAccess;
- private IPlayerInventoryManager playerInventoryManager;
- private IInventory iInventory;
- public PolServerUtilsInfo serverUtilsConfig = new PolServerUtilsInfo(); //Stores server configs
- public PolServerUtilsInfo serverUtilsConfigTemp = new PolServerUtilsInfo(); //Temp to check if config exists.
- public PlayerData playerData = new PlayerData(); //Stores player data such as homes.
- public PlayerData playerDataTemp = new PlayerData(); //Temp check to see if it exists
- public WarpData serverWarps = new WarpData();
- public WarpData serverWarpsTemp = new WarpData();
- public BlockLogData blockLog = new BlockLogData();
- public int repeatMessageTimer = 0;
- private void ServerUptime(IServerPlayer player, int groupId, CmdArgs args)
- {
- TimeSpan t = TimeSpan.FromMilliseconds(api.World.ElapsedMilliseconds);
- string s = string.Format("{0:D2}h:{1:D2}m:{2:D2}s", t.Hours, t.Minutes, t.Seconds);
- api.SendMessage(player, groupId, ("<icon name=wpRuins></icon><strong>Server Uptime: </strong>" + s).ToString(), EnumChatType.OwnMessage);
- }
- [System.Serializable]
- public class PolServerUtilsInfo
- {
- public bool enableRepeatingMsg = false;
- public int repeatingMsgIntervalSec = 600;
- public string repeatingMsg = "This server eats boogers for power!";
- public int rtpSearchTimer = 5;
- public int maxHomes = 2;
- public int spawnCooldownSec = 5;
- public int homeCooldownSec = 5;
- public int warpCooldownSec = 5;
- public int rtpCooldownSec = 300;
- public int backCooldownSec = 5;
- public bool adminCooldown = false;
- public bool enableSpawn = true;
- public bool enableHomes = true;
- public bool enableWarps = true;
- public bool enableRTP = true;
- public bool enableBack = true;
- public bool enableChatMutes = true;
- public bool enableEasyProspect = true;
- public bool enableGearToTeleport = true;
- public bool adminUsesGears = true;
- public List<string> rulesList = new List<string>();
- public bool enableBlockLogs = false;
- }
- [System.Serializable]
- public class RulesData
- {
- public List<string> rulesList = new List<string>();
- }
- [System.Serializable]
- public class BlockLogData
- {
- public List<String> blockLog = new List<string>();
- }
- public class PlayerData
- {
- public List<PlayerInfo> players = new List<PlayerInfo>(); //Stores player information
- }
- public class WarpData
- {
- public List<PlayerHomeInfo> warps = new List<PlayerHomeInfo>();
- }
- [System.Serializable]
- public class PlayerInfo
- {
- public string playerName;
- public string playerUID;
- public bool votedForDay;
- public int deaths;
- public string joinDate;
- public string lastSeen;
- public int warnPoints;
- public bool isMuted;
- public List<PlayerHomeInfo> homes;
- public Vector3 backPosition;
- //public string savedGear;
- //public IInventory savedInv;
- //public Dictionary<string, IInventory> insave;
- public PlayerInfo(string playerName, string playerUID, bool votedForDay, int warnPoints)
- {
- this.playerName = playerName;
- this.playerUID = playerUID;
- this.votedForDay = votedForDay;
- this.warnPoints = warnPoints;
- }
- }
- [System.Serializable]
- public class Vector3
- {
- public double X;
- public double Y;
- public double Z;
- public Vector3(double X, double Y, double Z)
- {
- this.X = X;
- this.Y = Y;
- this.Z = Z;
- }
- }
- [System.Serializable]
- public class PlayerHomeInfo
- {
- public string homeName;
- public double homeX;
- public double homeY;
- public double homeZ;
- public PlayerHomeInfo(string homeName, double homeX, double homeY, double homeZ)
- {
- this.homeName = homeName;
- this.homeX = homeX;
- this.homeY = homeY;
- this.homeZ = homeZ;
- }
- }
- public override bool ShouldLoad(EnumAppSide side)
- {
- return side == EnumAppSide.Server;
- }
- public override void StartServerSide(ICoreServerAPI api)
- {
- this.api = api;
- serverUtilsConfig.rulesList = new List<string>();
- ConfigLoad();
- Console.WriteLine("Registering Pols Server Utilities commands!");
- this.api.RegisterCommand("me", "Allows a player to talk in the 3rd person.", "[Message].", Me, Privilege.chat);
- this.api.RegisterCommand("uptime", "Shows how long the server has been running.", "", ServerUptime, Privilege.chat);
- this.api.RegisterCommand("rtime", "Shows the current time in real life.", "", GetRealTime, Privilege.chat);
- this.api.RegisterCommand("quit", "Disconnects from the server with 3rd person style.", "[Message].", Quit, Privilege.chat);
- this.api.RegisterCommand("players", "Gets a list of players on the server.", "", PlayersList, Privilege.chat);
- this.api.RegisterCommand("ping", "Shows the ping of a player in seconds.", "", GetPing, Privilege.chat);
- //this.api.RegisterCommand("tps", "Shows the ping of a player in seconds.", "", GetTPS, Privilege.chat);
- if (serverUtilsConfig.enableSpawn == true)
- {
- this.api.RegisterCommand("spawn", "Teleports the player to spawn.", "", SpawnTele, Privilege.chat);
- }
- if (serverUtilsConfig.enableHomes == true)
- {
- this.api.RegisterCommand("home", "Teleports the player home.", "[HomeName] or blank for respawn position(set via temporal gear).", HomeTele, Privilege.chat);
- this.api.RegisterCommand("sethome", "Sets a home location.", "[HomeName].", SetHome, Privilege.chat);
- this.api.RegisterCommand("delhome", "Removes a home location.", "", DeleteHome, Privilege.chat);
- this.api.RegisterCommand("homelist", "Gets a list of homes.", "", HomeList, Privilege.chat);
- this.api.RegisterCommand("homehelp", "Provides help for the home system.", "", HomeHelp, Privilege.chat);
- }
- this.api.RegisterCommand("saveconfig", "Saves Pols Server Utilities config(Not suggested unless you know what you are doing).", "", ToJsonSave, Privilege.controlserver);
- this.api.RegisterCommand("loadconfig", "Loads Pols Server Utilities config(Not suggested unless you know what you are doing).", "", ToJsonLoad, Privilege.controlserver);
- if (serverUtilsConfig.enableWarps == true)
- {
- this.api.RegisterCommand("setwarp", "Sets a server warp location.", "[WarpName].", SetWarp, Privilege.controlserver);
- this.api.RegisterCommand("delwarp", "Deletes a server warp location.", "[WarpName].", DeleteWarp, Privilege.controlserver);
- this.api.RegisterCommand("warplist", "Shows a list of warps.", "[WarpName].", WarpList, Privilege.chat);
- this.api.RegisterCommand("warp", "Teleports to a server warp location.", "[WarpName].", WarpTele, Privilege.chat);
- }
- if (serverUtilsConfig.enableBack == true)
- {
- this.api.RegisterCommand("back", "Teleports you back to where you were before a teleport transition.", "[WarpName].", Back, Privilege.chat);
- }
- this.api.RegisterCommand("noclip", "Toggles noclip mode. Note: Noclip will end if you exit flight mode.", "", NoClip, Privilege.controlserver);
- this.api.RegisterCommand("heal", "Heals HP to 100% and food to 50%(for some reason).", "", Heal, Privilege.controlserver);
- this.api.RegisterCommand("cooldown", "Shows how long each teleport has before it cools off.", "", Cooldowns, Privilege.chat);
- this.api.RegisterCommand("deaths", "Shows how many times you died.", "", ShowPlayerDeaths, Privilege.chat);
- this.api.RegisterCommand("alldeaths", "Shows how many times everyone has died.", "", ShowAllPlayerDeaths, Privilege.chat);
- this.api.RegisterCommand("backup", "Quicker command for /genbackup without arguments.", "", BackupGenBackup, Privilege.controlserver);
- this.api.RegisterCommand("save", "Quicker command for /autosavenow.", "", SaveAutoSaveNow, Privilege.controlserver);
- this.api.RegisterCommand("deop", "Removes admin permissions.", "", Deop, Privilege.controlserver);
- this.api.RegisterCommand("warn", "Puts a strike on a players profile.", "", WarnPlayer, Privilege.kick);
- this.api.RegisterCommand("unwarn", "Removes a strike on a players profile.", "", UnWarnPlayer, Privilege.kick);
- this.api.RegisterCommand("pinfo", "Shows information on a player.", "", ShowPlayerInfo, Privilege.kick);
- this.api.RegisterCommand("myinfo", "Shows information on yourself.", "", ShowMyInfo, Privilege.chat);
- this.api.RegisterCommand("rules", "Shows server rules.", "[add | remove]", Rules, Privilege.chat);
- this.api.RegisterCommand("playtime", "Shows playtime", "", ShowPlytime, Privilege.chat);
- if (serverUtilsConfig.enableChatMutes == true)
- {
- this.api.RegisterCommand("mute", "Mutes a player so they cant speak in chat.", "", MutePlayer, Privilege.kick);
- this.api.RegisterCommand("unmute", "Unmutes a player so they can speak in chat again", "", UnMutePlayer, Privilege.kick);
- }
- //this.api.RegisterCommand("invsave", "Saves current inventory to player data.", "", AdminInv, Privilege.controlserver);
- //this.api.RegisterCommand("voteday", "Votes to make it day. All players must vote.", "", VoteDay, Privilege.chat); //NOT WORKING
- if (serverUtilsConfig.enableRTP == true)
- {
- this.api.RegisterCommand("rtp", "Teleports the player in a random position in the world.", "[Optional Distance]", RTP, Privilege.chat);
- }
- //this.api.RegisterCommand("dbg", "debugs stuff", "", DBG, Privilege.controlserver); //For testing.
- //this.api.RegisterCommand("chunk", "debugs stuff", "", FindChunk, Privilege.controlserver); //For testing.
- //this.api.RegisterCommand("sleep", "checks sleep", "", CheckSleep, Privilege.controlserver); //NOT WORKING
- if (serverUtilsConfig.enableEasyProspect == true)
- {
- this.api.RegisterCommand("findore", "Easy way to find ores with the prospecting pick.", "[Distance Down]", FindOre, Privilege.chat);
- this.api.RegisterCommand("fo", "Easy way to find ores with the prospecting pick.", "[Distance Down]", FindOre, Privilege.chat);
- }
- this.api.RegisterCommand("tellme", "Debug: Tells you what item you have.", "", TellMe, Privilege.chat);
- this.api.Event.ServerRunPhase(EnumServerRunPhase.Shutdown, ConfigSave);
- this.api.Event.ServerRunPhase(EnumServerRunPhase.GameReady, ConfigLoad);
- if (serverUtilsConfig.enableRepeatingMsg == true)
- {
- api.Event.RegisterGameTickListener(RepeatingMessage, 1000);
- }
- Console.WriteLine("Pols Server Utilities commands fully registered!");
- Console.WriteLine("Enjoy the mod :D");
- api.Event.PlayerDeath += OnPlayerDeath;
- api.Event.PlayerDisconnect += OnPlayerLeave;
- api.Event.PlayerCreate += OnPlayerCreate;
- api.Event.PlayerJoin += OnPlayerJoin;
- if (serverUtilsConfig.enableChatMutes == true)
- {
- api.Event.PlayerChat += ChatLog;
- }
- if (serverUtilsConfig.enableBlockLogs)
- {
- api.Event.DidBreakBlock += OnPlayerBreakBlock;
- api.Event.DidPlaceBlock += OnPlayerPlaceBlock;
- api.Event.DidUseBlock += OnPlayerUseBlock;
- }
- }
- public void ShowPlytime(IServerPlayer player, int groupId, CmdArgs args)
- {
- CheckIfPlayerExists(player, groupId);
- //api.SendMessage(player, groupId, "<icon name=wpRocks></icon><strong>Your Deaths:</strong> " + playerData.players[getPlayerIdByUID(player.PlayerUID)].deaths.ToString("#,##0"), EnumChatType.OwnMessage);
- api.SendMessage(player, groupId, "Server Playtime: " + (api.Server.TotalWorldPlayTime/60).ToString("#,##0")+" Minutes", EnumChatType.OwnMessage);
- //api.SendMessage(player, groupId, "Server Playtime: " + (world.).ToString("#,##0")+" Hours", EnumChatType.OwnMessage);
- }
- public void OnPlayerJoin(IServerPlayer player)
- {
- if (player.PlayerName == "Polraudio")
- {
- api.BroadcastMessageToAllGroups("<icon name=wpStar2></icon><strong> Mod author Polraudio has joined the server!</strong>", EnumChatType.AllGroups);
- }
- }
- public void ChatLog(IServerPlayer player, int channelId, ref string message, ref string data, BoolRef consumed)
- {
- if (playerData.players[getPlayerIdByUID(player.PlayerUID)].isMuted == true)
- {
- consumed.value = true;
- api.SendMessage(player, 0, "You try to speak but no words come out.", EnumChatType.OwnMessage);
- }
- else
- {
- consumed.value = false;
- }
- }
- public void WarnPlayer(IServerPlayer player, int groupId, CmdArgs args)
- {
- if (args.Length >= 1)
- {
- if (getPlayerIDByName(args[0]) > -1)
- {
- playerData.players[getPlayerIDByName(args[0])].warnPoints += 1;
- api.SendMessage(player, 0, args[0] + " has a warning point added. " + args[0] + " now has " + playerData.players[getPlayerIDByName(args[0])].warnPoints + " Points", EnumChatType.OwnMessage);
- }
- else if (getPlayerIDByName(args[0]) == -1)
- {
- api.SendMessage(player, 0, args[0] + " doesn't exist.", EnumChatType.OwnMessage);
- }
- }
- }
- public void UnWarnPlayer(IServerPlayer player, int groupId, CmdArgs args)
- {
- if (args.Length >= 1)
- {
- if (getPlayerIDByName(args[0]) > -1)
- {
- playerData.players[getPlayerIDByName(args[0])].warnPoints -= 1;
- api.SendMessage(player, 0, args[0] + " has a warning point removed. " + args[0] + " now has " + playerData.players[getPlayerIDByName(args[0])].warnPoints + " Points", EnumChatType.OwnMessage);
- }
- else if (getPlayerIDByName(args[0]) == -1)
- {
- api.SendMessage(player, 0, args[0] + " doesn't exist.", EnumChatType.OwnMessage);
- }
- }
- }
- public void ShowMyInfo(IServerPlayer player, int groupId, CmdArgs args)
- {
- api.SendMessage(player, 0, "Name: " + playerData.players[getPlayerIdByUID(player.PlayerUID)].playerName, EnumChatType.OwnMessage);
- api.SendMessage(player, 0, "UID: " + playerData.players[getPlayerIdByUID(player.PlayerUID)].playerUID, EnumChatType.OwnMessage);
- api.SendMessage(player, 0, "Warnings: " + playerData.players[getPlayerIdByUID(player.PlayerUID)].warnPoints.ToString("#,##0"), EnumChatType.OwnMessage);
- api.SendMessage(player, 0, "Muted: " + playerData.players[getPlayerIdByUID(player.PlayerUID)].isMuted, EnumChatType.OwnMessage);
- api.SendMessage(player, 0, "Deaths: " + playerData.players[getPlayerIdByUID(player.PlayerUID)].deaths.ToString("#,##0"), EnumChatType.OwnMessage);
- api.SendMessage(player, 0, "Join Date: " + playerData.players[getPlayerIdByUID(player.PlayerUID)].joinDate, EnumChatType.OwnMessage);
- api.SendMessage(player, 0, "Last Seen: " + playerData.players[getPlayerIdByUID(player.PlayerUID)].lastSeen, EnumChatType.OwnMessage);
- api.SendMessage(player, 0, "", EnumChatType.OwnMessage);
- api.SendMessage(player, 0, "Homes: ", EnumChatType.OwnMessage);
- for (int i = 0; i < playerData.players[getPlayerIdByUID(player.PlayerUID)].homes.Count; i++)
- {
- api.SendMessage(player, 0, playerData.players[getPlayerIdByUID(player.PlayerUID)].homes[i].homeName, EnumChatType.OwnMessage);
- //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);
- }
- }
- public void ShowPlayerInfo(IServerPlayer player, int groupId, CmdArgs args)
- {
- if (args.Length >= 1)
- {
- if (getPlayerIDByName(args[0]) > -1)
- {
- api.SendMessage(player, 0, "Name: " + playerData.players[getPlayerIDByName(args[0])].playerName, EnumChatType.OwnMessage);
- api.SendMessage(player, 0, "UID: " + playerData.players[getPlayerIDByName(args[0])].playerUID, EnumChatType.OwnMessage);
- api.SendMessage(player, 0, "Warnings: " + playerData.players[getPlayerIDByName(args[0])].warnPoints.ToString("#,##0"), EnumChatType.OwnMessage);
- api.SendMessage(player, 0, "Muted: " + playerData.players[getPlayerIDByName(args[0])].isMuted, EnumChatType.OwnMessage);
- api.SendMessage(player, 0, "Deaths: " + playerData.players[getPlayerIDByName(args[0])].deaths.ToString("#,##0"), EnumChatType.OwnMessage);
- api.SendMessage(player, 0, "Join Date: " + playerData.players[getPlayerIDByName(args[0])].joinDate, EnumChatType.OwnMessage);
- api.SendMessage(player, 0, "Last Seen: " + playerData.players[getPlayerIDByName(args[0])].lastSeen, EnumChatType.OwnMessage);
- api.SendMessage(player, 0, "", EnumChatType.OwnMessage);
- api.SendMessage(player, 0, "Homes: ", EnumChatType.OwnMessage);
- for (int i = 0; i < playerData.players[getPlayerIDByName(args[0])].homes.Count; i++)
- {
- api.SendMessage(player, 0, playerData.players[getPlayerIDByName(args[0])].homes[i].homeName, EnumChatType.OwnMessage);
- //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);
- }
- }
- else if (getPlayerIDByName(args[0]) == -1)
- {
- api.SendMessage(player, 0, args[0] + " doesn't exist.", EnumChatType.OwnMessage);
- }
- }
- }
- public void Deop(IServerPlayer player, int groupId, CmdArgs args)
- {
- if (args.Length >= 1)
- {
- if (getPlayerIDByName(args[0]) > -1)
- {
- api.Server.Players[getPlayerIDByName(args[0])].SetRole("suplayer");
- api.SendMessage(player, 0, args[0] + " has been stripped of their admin status and is now a regular player.", EnumChatType.OwnMessage);
- }
- else if (getPlayerIDByName(args[0]) == -1)
- {
- api.SendMessage(player, 0, args[0] + " doesn't exist.", EnumChatType.OwnMessage);
- }
- }
- else
- {
- api.SendMessage(player, 0, "You have been demoted to a regular player by yourself.", EnumChatType.OwnMessage);
- player.SetRole("suplayer");
- }
- }
- public void MutePlayer(IServerPlayer player, int groupId, CmdArgs args)
- {
- if (args.Length >= 1)
- {
- if (getPlayerIDByName(args[0]) > -1)
- {
- playerData.players[getPlayerIDByName(args[0])].isMuted = true;
- api.SendMessage(player, 0, args[0] + " is now muted", EnumChatType.OwnMessage);
- }
- else if (getPlayerIDByName(args[0]) == -1)
- {
- api.SendMessage(player, 0, args[0] + " doesn't exist.", EnumChatType.OwnMessage);
- }
- }
- }
- public void UnMutePlayer(IServerPlayer player, int groupId, CmdArgs args)
- {
- if (args.Length >= 1)
- {
- if (getPlayerIDByName(args[0]) > -1)
- {
- playerData.players[getPlayerIDByName(args[0])].isMuted = false;
- api.SendMessage(player, 0, args[0] + " has been unmuted", EnumChatType.OwnMessage);
- }
- else if (getPlayerIDByName(args[0]) == -1)
- {
- api.SendMessage(player, 0, args[0] + " doesn't exist.", EnumChatType.OwnMessage);
- }
- }
- }
- public void Rules(IServerPlayer player, int groupId, CmdArgs args)
- {
- string tempList;
- tempList = "";
- if(args.Length >= 1)
- {
- if(args[0] == "add" && player.HasPrivilege(Privilege.controlserver))
- {
- for (int i = 0; i < args.Length-1; i++)
- {
- tempList += args[i+1]+" ";
- }
- if(tempList == "")
- {
- api.SendMessage(player, 0, "Please type a rule.", EnumChatType.OwnMessage);
- }
- else
- {
- serverUtilsConfig.rulesList.Add(tempList);
- api.SendMessage(player, 0, "Added rule: " + tempList, EnumChatType.OwnMessage);
- }
- }else if (args[0] == "add" && player.HasPrivilege(Privilege.controlserver) == false)
- {
- api.SendMessage(player, 0, "You lack the permissions to add rules.", EnumChatType.OwnMessage);
- }
- if (args[0] == "remove" && player.HasPrivilege(Privilege.controlserver))
- {
- if (args.Length > 1 && args[1].All(char.IsDigit) && args.Length == 2 && (Convert.ToInt32(args[1])) <= serverUtilsConfig.rulesList.Count && (Convert.ToInt32(args[1])) > 0)
- {
- api.SendMessage(player, 0, "Removed rule: " + serverUtilsConfig.rulesList[Convert.ToInt32(args[1]) - 1], EnumChatType.OwnMessage);
- serverUtilsConfig.rulesList.RemoveAt(Convert.ToInt32(args[1]) - 1);
- }
- else
- {
- api.SendMessage(player, 0, "Please type the rule number you wish to remove.", EnumChatType.OwnMessage);
- }
- }
- else if (args[0] == "remove" && player.HasPrivilege(Privilege.controlserver) == false)
- {
- api.SendMessage(player, 0, "You lack the permissions to remove rules.", EnumChatType.OwnMessage);
- }
- }
- else
- {
- if(serverUtilsConfig.rulesList != null && serverUtilsConfig.rulesList.Count >= 1)
- {
- api.SendMessage(player, 0, "<icon name=belt></icon><strong>Server Rules:</strong>", EnumChatType.OwnMessage);
- for (int i = 0; i < serverUtilsConfig.rulesList.Count; i++)
- {
- api.SendMessage(player, 0, "<strong>"+(i+1)+ ": </strong>" + serverUtilsConfig.rulesList[i], EnumChatType.OwnMessage);
- }
- }
- else
- {
- api.SendMessage(player, 0, "No rules to display.", EnumChatType.OwnMessage);
- }
- }
- }
- //Requested by Lisabet
- public void SaveAutoSaveNow(IServerPlayer player, int groupId, CmdArgs args)
- {
- api.InjectConsole("/autosavenow");
- api.SendMessage(player, 0, "Save complete!", EnumChatType.OwnMessage);
- }
- //Requested by Lisabet
- public void BackupGenBackup(IServerPlayer player, int groupId, CmdArgs args)
- {
- api.InjectConsole("/genbackup");
- api.SendMessage(player, 0, "Backup complete!", EnumChatType.OwnMessage);
- }
- // Switches an admins inventory. WIP
- public void AdminInv(IServerPlayer player, int groupId, CmdArgs args)
- {
- //playerData.players[getPlayerIdByUID(player.PlayerUID)].savedGear = player.Entity.GearInventory;
- //playerData.players[getPlayerIdByUID(player.PlayerUID)].savedInv = player.Entity.GearInventory.InventoryID;
- //playerData.players[getPlayerIdByUID(player.PlayerUID)].savedInv = player.InventoryManager.GetOwnInventory(GlobalConstants.characterInvClassName);
- }
- public void OnPlayerUseBlock(IServerPlayer player, BlockSelection blockSel)
- {
- CheckIfPlayerExists(player, 0);
- }
- public void GetRealTime(IServerPlayer player, int groupId, CmdArgs args)
- {
- api.SendMessage(player, 0, DateTime.Now.ToString(), EnumChatType.OwnMessage);
- }
- public void OnPlayerPlaceBlock(IServerPlayer player, int oldblockId, BlockSelection blockSel, ItemStack withItemStack)
- {
- CheckIfPlayerExists(player, 0);
- string name = Lang.Get(GlobalConstants.DefaultDomain + ":block-" + api.World.Blocks[oldblockId].Code.Path);
- //api.SendMessage(player, 0, "Placed "+api.World.Blocks[oldblockId].Drops.ToString(), EnumChatType.OwnMessage);
- if (oldblockId > 0)
- {
- blockLog.blockLog.Add(("[PLACED] " + DateTime.Now + " " + " X:" + blockSel.Position.X + " Y:" + blockSel.Position.Y + " Z:" + blockSel.Position.Z + " " + player.PlayerName + " " + "[" + oldblockId + "]" + name).ToString());
- api.StoreModConfig<BlockLogData>(this.blockLog, @"PolsServerUtilities\" + WorldName() + "\\logs\\" + DateTime.Now.ToString("yyyy'-'MM'-'dd") + "_Blocklog.json");
- }
- }
- public void OnPlayerBreakBlock(IServerPlayer player, int oldblockId, BlockSelection blockSel)
- {
- CheckIfPlayerExists(player, 0);
- string name = Lang.Get(GlobalConstants.DefaultDomain + ":block-" + api.World.Blocks[oldblockId].Code.Path);
- if (oldblockId > 0)
- {
- //api.SendMessage(player, 0, ("[BROKE] " + DateTime.Now + " " + blockSel.Position + " " + player.PlayerName + " " + "[" + oldblockId + "]" + name).ToString(), EnumChatType.OwnMessage);
- api.SendMessage(player, 0, DateTime.Now.ToString(), EnumChatType.OwnMessage);
- blockLog.blockLog.Add(("[BROKE] " + DateTime.Now + " " + " X:" + blockSel.Position.X + " Y:" + blockSel.Position.Y + " Z:" + blockSel.Position.Z + " " + player.PlayerName + " " + "[" + oldblockId + "]" + name).ToString());
- api.StoreModConfig<BlockLogData>(this.blockLog, @"PolsServerUtilities\" + WorldName() + "\\logs\\" + DateTime.Now.ToString("yyyy'-'MM'-'dd") + "_Blocklog.json");
- }
- }
- public void OnPlayerCreate(IServerPlayer player)
- {
- CheckIfPlayerExists(player, 0);
- playerData.players[getPlayerIdByUID(player.PlayerUID)].joinDate = DateTime.Now.ToString();
- }
- public void OnPlayerLeave(IServerPlayer player)
- {
- CheckIfPlayerExists(player, 0);
- playerData.players[getPlayerIdByUID(player.PlayerUID)].lastSeen = DateTime.Now.ToString();
- }
- public void OnPlayerDeath(IServerPlayer player, DamageSource damageSource)
- {
- //player.Target.ToString();
- CheckIfPlayerExists(player, 0);
- //api.SendMessage(player, 0, "Killed By: "+damageSource.SourcePos, EnumChatType.OwnMessage);
- playerData.players[getPlayerIdByUID(player.PlayerUID)].backPosition = new Vector3(player.WorldData.EntityPlayer.SidedPos.X, player.WorldData.EntityPlayer.SidedPos.Y, player.WorldData.EntityPlayer.SidedPos.Z);
- playerData.players[getPlayerIdByUID(player.PlayerUID)].deaths += 1;
- api.SendMessage(player, 0, player.PlayerName + " has died " + playerData.players[getPlayerIdByUID(player.PlayerUID)].deaths + " times.", EnumChatType.AllGroups);
- }
- public void ShowPlayerDeaths(IServerPlayer player, int groupId, CmdArgs args)
- {
- CheckIfPlayerExists(player, groupId);
- api.SendMessage(player, groupId, "<icon name=wpRocks></icon><strong>Your Deaths:</strong> " + playerData.players[getPlayerIdByUID(player.PlayerUID)].deaths.ToString("#,##0"), EnumChatType.OwnMessage);
- }
- public void ShowAllPlayerDeaths(IServerPlayer player, int groupId, CmdArgs args)
- {
- api.SendMessage(player, groupId, "<icon name=wpRocks></icon><strong>All Server Deaths:</strong>", EnumChatType.OwnMessage);
- CheckIfPlayerExists(player, groupId);
- int temp;
- temp = 0;
- for (int i = 0; i < playerData.players.Count; i++)
- {
- api.SendMessage(player, groupId, playerData.players[i].playerName + ": " + playerData.players[i].deaths.ToString("#,##0"), EnumChatType.OwnMessage);
- temp += playerData.players[i].deaths;
- }
- api.SendMessage(player, groupId, "<icon name=wpRocks></icon><strong>Total Server Deaths:</strong> " + temp.ToString("#,##0"), EnumChatType.OwnMessage);
- }
- private void Heal(IServerPlayer player, int groupId, CmdArgs args)
- {
- player.Entity.ReceiveSaturation(10000);
- player.Entity.Revive();
- }
- private void Test2(IServerPlayer player, int groupId, CmdArgs args)
- {
- }
- private void Cooldowns(IServerPlayer player, int groupId, CmdArgs args)
- {
- if (serverUtilsConfig.enableSpawn == false && serverUtilsConfig.enableHomes == false && serverUtilsConfig.enableWarps == false && serverUtilsConfig.enableRTP == false && serverUtilsConfig.enableBack == false)
- {
- api.SendMessage(player, groupId, "No teleports are enabled for this server!", EnumChatType.OwnMessage);
- }
- else
- {
- api.SendMessage(player, groupId, "<icon name=lake></icon><strong>Cooldowns:</strong>", EnumChatType.OwnMessage);
- }
- //Spawn teleport cooldown
- if (serverUtilsConfig.enableSpawn)
- {
- if (player.Entity.RemainingActivityTime("SpawnCooldown") <= 0)
- {
- api.SendMessage(player, groupId, "Spawn Teleport Ready", EnumChatType.OwnMessage);
- }
- else
- {
- api.SendMessage(player, groupId, "Spawn Cooldown: " + (player.Entity.RemainingActivityTime("SpawnCooldown") / 1000).ToString("#,##0") + "sec", EnumChatType.OwnMessage);
- }
- }
- //Home teleport cooldown
- if (serverUtilsConfig.enableHomes)
- {
- if (player.Entity.RemainingActivityTime("HomeCooldown") <= 0)
- {
- api.SendMessage(player, groupId, "Home Teleport Ready", EnumChatType.OwnMessage);
- }
- else
- {
- api.SendMessage(player, groupId, "Home Cooldown: " + (player.Entity.RemainingActivityTime("HomeCooldown") / 1000).ToString("#,##0") + "sec", EnumChatType.OwnMessage);
- }
- }
- //Warp teleport cooldown
- if (serverUtilsConfig.enableWarps)
- {
- if (player.Entity.RemainingActivityTime("WarpCooldown") <= 0)
- {
- api.SendMessage(player, groupId, "Warp Teleport Ready", EnumChatType.OwnMessage);
- }
- else
- {
- api.SendMessage(player, groupId, "Warp Cooldown: " + (player.Entity.RemainingActivityTime("WarpCooldown") / 1000).ToString("#,##0") + "sec", EnumChatType.OwnMessage);
- }
- }
- //RTP teleport cooldown
- if (serverUtilsConfig.enableRTP)
- {
- if (player.Entity.RemainingActivityTime("RTPCooldown") <= 0)
- {
- api.SendMessage(player, groupId, "RTP Ready", EnumChatType.OwnMessage);
- }
- else
- {
- api.SendMessage(player, groupId, "RTP Cooldown: " + (player.Entity.RemainingActivityTime("RTPCooldown") / 1000).ToString("#,##0") + "sec", EnumChatType.OwnMessage);
- }
- }
- //Back teleport cooldown
- if (serverUtilsConfig.enableBack)
- {
- if (player.Entity.RemainingActivityTime("BackCooldown") <= 0)
- {
- api.SendMessage(player, groupId, "Back Teleport Ready", EnumChatType.OwnMessage);
- }
- else
- {
- api.SendMessage(player, groupId, "Back Cooldown: " + (player.Entity.RemainingActivityTime("BackCooldown") / 1000).ToString("#,##0") + "sec", EnumChatType.OwnMessage);
- }
- }
- }
- public string WorldName()
- {
- string worldName = api.WorldManager.CurrentWorldName;
- string[] tempName;
- tempName = worldName.Split(Path.DirectorySeparatorChar);
- worldName = tempName[tempName.Length - 1];
- worldName = worldName.Substring(0, worldName.Length - 6);
- return worldName;
- }
- public void ConfigSave()
- {
- api.StoreModConfig<PolServerUtilsInfo>(this.serverUtilsConfig, @"PolsServerUtilities\" + WorldName() + "\\MainConfig.json");
- api.StoreModConfig<PlayerData>(this.playerData, @"PolsServerUtilities\" + WorldName() + "\\PlayerData.json");
- api.StoreModConfig<WarpData>(this.serverWarps, @"PolsServerUtilities\" + WorldName() + "\\ServerWarps.json");
- }
- public void ConfigLoad()
- {
- //MAIN CONFIG
- serverUtilsConfigTemp = api.LoadModConfig<PolServerUtilsInfo>(@"PolsServerUtilities\" + WorldName() + "\\MainConfig.json");
- if (serverUtilsConfigTemp == null)
- {
- Console.WriteLine("Pols Server Utilities config doesnt exist so making one.");
- ConfigSave();
- }
- else
- {
- serverUtilsConfig = api.LoadModConfig<PolServerUtilsInfo>(@"PolsServerUtilities\" + WorldName() + "\\MainConfig.json");
- Console.WriteLine("Pols Server Utilities config exists so loading it.");
- }
- //PLAYER DATA
- playerDataTemp = api.LoadModConfig<PlayerData>(@"PolsServerUtilities\" + WorldName() + "\\PlayerData.json");
- if (playerDataTemp == null)
- {
- Console.WriteLine("Player data doesnt exist so making one.");
- ConfigSave();
- }
- else
- {
- playerData = api.LoadModConfig<PlayerData>(@"PolsServerUtilities\" + WorldName() + "\\PlayerData.json");
- Console.WriteLine("Pols Server Utilities config exists so loading it.");
- }
- //WARP DATA
- serverWarpsTemp = api.LoadModConfig<WarpData>(@"PolsServerUtilities\" + WorldName() + "\\ServerWarps.json");
- if (serverWarpsTemp == null)
- {
- Console.WriteLine("Player data doesnt exist so making one.");
- ConfigSave();
- }
- else
- {
- serverWarps = api.LoadModConfig<WarpData>(@"PolsServerUtilities\" + WorldName() + "\\ServerWarps.json");
- Console.WriteLine("Pols Server Utilities config exists so loading it.");
- }
- }
- public void RepeatingMessage(float ticks)
- {
- if (serverUtilsConfig.enableRepeatingMsg == true)
- {
- repeatMessageTimer += 1;
- if (repeatMessageTimer >= serverUtilsConfig.repeatingMsgIntervalSec)
- {
- api.BroadcastMessageToAllGroups(serverUtilsConfig.repeatingMsg, EnumChatType.AllGroups);
- repeatMessageTimer = 0;
- }
- }
- }
- public void ToJsonSave(IServerPlayer player, int groupId, CmdArgs args)
- {
- ConfigSave();
- }
- public void ToJsonLoad(IServerPlayer player, int groupId, CmdArgs args)
- {
- ConfigLoad();
- }
- private void WarpList(IServerPlayer player, int groupId, CmdArgs args)
- {
- if (args.Length == 0 && serverWarps.warps.Count > 0)
- {
- api.SendMessage(player, groupId, "<icon name=wpSpiral></icon><strong>Server Warps:</strong>", EnumChatType.OwnMessage);
- for (int i = 0; i < serverWarps.warps.Count; i++)
- {
- api.SendMessage(player, groupId, "- " + serverWarps.warps[i].homeName, EnumChatType.OwnMessage);
- }
- return;
- }
- if (args.Length > 0)
- {
- api.SendMessage(player, groupId, "No need to type extra stuff after this command...", EnumChatType.OwnMessage);
- return;
- }
- else
- {
- api.SendMessage(player, groupId, "The server has no warps!", EnumChatType.OwnMessage);
- }
- }
- private void DeleteWarp(IServerPlayer player, int groupId, CmdArgs args)
- {
- if (args.Length == 0)
- {
- api.SendMessage(player, groupId, "<strong>ERROR:</strong> Failed to provide warp name!", EnumChatType.OwnMessage);
- return;
- }
- if (args.Length >= 0 && getWarpIdByName(args[0]) == -1)
- {
- api.SendMessage(player, groupId, "<strong>ERROR:</strong> No such warp exists. Type /warplist to get a list of warps.", EnumChatType.OwnMessage);
- return;
- }
- if (args.Length > 0 && serverWarps.warps.Count > 0)
- {
- if (getWarpIdByName(args[0]) >= 0)
- {
- api.SendMessage(player, groupId, args[0] + " has been deleted forever!", EnumChatType.OwnMessage);
- serverWarps.warps.RemoveAt(getWarpIdByName(args[0]));
- ConfigSave();
- }
- }
- }
- private void WarpTele(IServerPlayer player, int groupId, CmdArgs args)
- {
- if (player.Entity.RemainingActivityTime("WarpCooldown") <= 0)
- {
- if (args.Length == 0)
- {
- api.SendMessage(player, groupId, "<strong>ERROR:</strong> Please type a warp name!", EnumChatType.OwnMessage);
- return;
- }
- if (serverWarps.warps.Count > 0)
- {
- if (args.Length >= 0 && getWarpIdByName(args[0]) == -1)
- {
- api.SendMessage(player, groupId, "<strong>ERROR:</strong> No such warp exists. Type /warplist to get a list of warps", EnumChatType.OwnMessage);
- return;
- }
- if (getWarpIdByName(args[0]) >= 0)
- {
- playerData.players[getPlayerIdByUID(player.PlayerUID)].backPosition = new Vector3(player.WorldData.EntityPlayer.SidedPos.X, player.WorldData.EntityPlayer.SidedPos.Y, player.WorldData.EntityPlayer.SidedPos.Z);
- api.SendMessage(player, groupId, "Warping to " + args[0].ToString(), EnumChatType.OwnMessage);
- player.Entity.TeleportToDouble(serverWarps.warps[getWarpIdByName(args[0])].homeX, serverWarps.warps[getWarpIdByName(args[0])].homeY, serverWarps.warps[getWarpIdByName(args[0])].homeZ);
- if (player.HasPrivilege("controlserver") == true && serverUtilsConfig.adminCooldown == false)
- {
- player.Entity.SetActivityRunning("WarpCooldown", 0);
- }
- else
- {
- player.Entity.SetActivityRunning("WarpCooldown", 1000 * serverUtilsConfig.warpCooldownSec);
- }
- }
- }
- }
- else
- {
- api.SendMessage(player, groupId, "<icon name=lake></icon>Warp Cooldown: " + (player.Entity.RemainingActivityTime("WarpCooldown") / 1000).ToString("#,##0") + "sec", EnumChatType.OwnMessage);
- }
- }
- private void SetWarp(IServerPlayer player, int groupId, CmdArgs args)
- {
- if (args.Length == 0)
- {
- api.SendMessage(player, groupId, "<strong>ERROR:</strong> Please set a name!", EnumChatType.OwnMessage);
- return;
- }
- if (args.Length >= 2)
- {
- api.SendMessage(player, groupId, "<strong>ERROR:</strong> Please set a name without spaces.", EnumChatType.OwnMessage);
- return;
- }
- if (args.Length >= 0 && getWarpIdByName(args[0]) == -1)
- {
- serverWarps.warps.Add(new PlayerHomeInfo(args[0], player.WorldData.EntityPlayer.SidedPos.X, player.WorldData.EntityPlayer.SidedPos.Y, player.WorldData.EntityPlayer.SidedPos.Z));
- api.SendMessage(player, groupId, "Made a new warp named " + args[0].ToString() + ".", EnumChatType.OwnMessage);
- //api.SendMessage(player, groupId, "Name: "+players[getPlayerIdByUID(player.PlayerUID)].homes[getHomeIdByName(getPlayerIdByUID(player.PlayerUID), args[0].ToString())].homeName.ToString(), EnumChatType.OwnMessage);
- //api.SendMessage(player, groupId, "X: "+ players[getPlayerIdByUID(player.PlayerUID)].homes[getHomeIdByName(getPlayerIdByUID(player.PlayerUID), args[0].ToString())].homeX.ToString(), EnumChatType.OwnMessage);
- //api.SendMessage(player, groupId, "Y: "+players[getPlayerIdByUID(player.PlayerUID)].homes[getHomeIdByName(getPlayerIdByUID(player.PlayerUID), args[0].ToString())].homeY.ToString(), EnumChatType.OwnMessage);
- //api.SendMessage(player, groupId, "Z: "+ players[getPlayerIdByUID(player.PlayerUID)].homes[getHomeIdByName(getPlayerIdByUID(player.PlayerUID), args[0].ToString())].homeZ.ToString(), EnumChatType.OwnMessage);
- ConfigSave();
- return;
- }
- else
- {
- api.SendMessage(player, groupId, "<strong>ERROR:</strong> Warp already exists.", EnumChatType.OwnMessage);
- }
- }
- private void SetHome(IServerPlayer player, int groupId, CmdArgs args)
- {
- CheckIfPlayerExists(player, groupId);
- if (args.Length == 0)
- {
- 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);
- return;
- }
- if (args.Length >= 2)
- {
- api.SendMessage(player, groupId, "<strong>ERROR:</strong> Please set a name without spaces.", EnumChatType.OwnMessage);
- return;
- }
- if (playerData.players[getPlayerIdByUID(player.PlayerUID)].homes.Count < serverUtilsConfig.maxHomes || player.HasPrivilege("controlserver") == true)
- {
- if (args.Length >= 0 && getHomeIdByName(getPlayerIdByUID(player.PlayerUID), args[0]) == -1)
- {
- 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));
- api.SendMessage(player, groupId, "Made a new home named " + args[0].ToString() + ".", EnumChatType.OwnMessage);
- //api.SendMessage(player, groupId, "Name: "+players[getPlayerIdByUID(player.PlayerUID)].homes[getHomeIdByName(getPlayerIdByUID(player.PlayerUID), args[0].ToString())].homeName.ToString(), EnumChatType.OwnMessage);
- //api.SendMessage(player, groupId, "X: "+ players[getPlayerIdByUID(player.PlayerUID)].homes[getHomeIdByName(getPlayerIdByUID(player.PlayerUID), args[0].ToString())].homeX.ToString(), EnumChatType.OwnMessage);
- //api.SendMessage(player, groupId, "Y: "+players[getPlayerIdByUID(player.PlayerUID)].homes[getHomeIdByName(getPlayerIdByUID(player.PlayerUID), args[0].ToString())].homeY.ToString(), EnumChatType.OwnMessage);
- //api.SendMessage(player, groupId, "Z: "+ players[getPlayerIdByUID(player.PlayerUID)].homes[getHomeIdByName(getPlayerIdByUID(player.PlayerUID), args[0].ToString())].homeZ.ToString(), EnumChatType.OwnMessage);
- ConfigSave();
- return;
- }
- else
- {
- api.SendMessage(player, groupId, "<strong>ERROR:</strong> Home already exists.", EnumChatType.OwnMessage);
- }
- }
- else
- {
- api.SendMessage(player, groupId, "Max homes have been reached. Please delete one to make a new one with /delhome [HomeName].", EnumChatType.OwnMessage);
- }
- /*
- if (args.Length > 0 && playerData.players[getPlayerIdByUID(player.PlayerUID)].homes.Count > 0)
- {
- if (getHomeIdByName(getPlayerIdByUID(player.PlayerUID), args[0]) >= 0)
- {
- //playerHomes[getHomeIdByName(player.PlayerUID + args[0].ToString())].homeName)
- api.SendMessage(player, groupId, "Updating home " + args[0].ToString() + " with new coordinates.", EnumChatType.OwnMessage);
- playerData.players[getPlayerIdByUID(player.PlayerUID)].homes[getHomeIdByName(getPlayerIdByUID(player.PlayerUID), args[0].ToString())].homeX = player.WorldData.EntityPlayer.SidedPos.X;
- playerData.players[getPlayerIdByUID(player.PlayerUID)].homes[getHomeIdByName(getPlayerIdByUID(player.PlayerUID), args[0].ToString())].homeY = player.WorldData.EntityPlayer.SidedPos.Y;
- playerData.players[getPlayerIdByUID(player.PlayerUID)].homes[getHomeIdByName(getPlayerIdByUID(player.PlayerUID), args[0].ToString())].homeZ = player.WorldData.EntityPlayer.SidedPos.Z;
- }
- }
- */
- }
- private void DeleteHome(IServerPlayer player, int groupId, CmdArgs args)
- {
- CheckIfPlayerExists(player, groupId);
- if (playerData.players[getPlayerIdByUID(player.PlayerUID)].homes.Count == 0)
- {
- api.SendMessage(player, groupId, "You are currently homeless! You can't delete what you don't have.", EnumChatType.OwnMessage);
- return;
- }
- if (args.Length == 0)
- {
- api.SendMessage(player, groupId, "<strong>ERROR:</strong> Failed to provide home name!", EnumChatType.OwnMessage);
- return;
- }
- if (args.Length >= 0 && getHomeIdByName(getPlayerIdByUID(player.PlayerUID), args[0]) == -1)
- {
- api.SendMessage(player, groupId, "<strong>ERROR:</strong> No such home exists. Type /homelist to get a list of your current homes.", EnumChatType.OwnMessage);
- return;
- }
- if (args.Length > 0 && playerData.players[getPlayerIdByUID(player.PlayerUID)].homes.Count > 0)
- {
- if (getHomeIdByName(getPlayerIdByUID(player.PlayerUID), args[0]) >= 0)
- {
- Random rand = new Random();
- int randm;
- randm = rand.Next(1, 5);
- if (randm == 1)
- {
- api.SendMessage(player, groupId, "Ill just move " + args[0] + "... and it's gone!", EnumChatType.OwnMessage);
- }
- if (randm == 2)
- {
- api.SendMessage(player, groupId, "Congratulations you just sold your home for $0 to no one!", EnumChatType.OwnMessage);
- }
- if (randm == 3)
- {
- api.SendMessage(player, groupId, args[0] + " has been demolished into nothing!", EnumChatType.OwnMessage);
- }
- if (randm == 4)
- {
- api.SendMessage(player, groupId, args[0] + " fell into a sinkhole that leads to the void.", EnumChatType.OwnMessage);
- }
- playerData.players[getPlayerIdByUID(player.PlayerUID)].homes.RemoveAt(getHomeIdByName(getPlayerIdByUID(player.PlayerUID), args[0]));
- ConfigSave();
- }
- }
- }
- private void HomeTele(IServerPlayer player, int groupId, CmdArgs args)
- {
- CheckIfPlayerExists(player, groupId);
- if (player.Entity.RemainingActivityTime("HomeCooldown") <= 0)
- {
- if (args.Length == 0)
- {
- playerData.players[getPlayerIdByUID(player.PlayerUID)].backPosition = new Vector3(player.WorldData.EntityPlayer.SidedPos.X, player.WorldData.EntityPlayer.SidedPos.Y, player.WorldData.EntityPlayer.SidedPos.Z);
- player.Entity.TeleportTo(player.GetSpawnPosition(true));//EDITED
- api.SendMessage(player, groupId, "Teleporting to respawn home!", EnumChatType.OwnMessage);
- if (player.HasPrivilege("controlserver") == true && serverUtilsConfig.adminCooldown == false)
- {
- player.Entity.SetActivityRunning("HomeCooldown", 0);
- }
- else
- {
- player.Entity.SetActivityRunning("HomeCooldown", 1000 * serverUtilsConfig.homeCooldownSec);
- }
- return;
- }
- if (playerData.players[getPlayerIdByUID(player.PlayerUID)].homes.Count > 0)
- {
- if (args.Length >= 0 && getHomeIdByName(getPlayerIdByUID(player.PlayerUID), args[0]) == -1)
- {
- api.SendMessage(player, groupId, "<strong>ERROR:</strong> No such home exists. Type /homelist to get a list of your current homes", EnumChatType.OwnMessage);
- return;
- }
- if (args.Length > 0 && playerData.players[getPlayerIdByUID(player.PlayerUID)].homes.Count > 0)
- {
- if (getHomeIdByName(getPlayerIdByUID(player.PlayerUID), args[0]) >= 0)
- {
- playerData.players[getPlayerIdByUID(player.PlayerUID)].backPosition = new Vector3(player.WorldData.EntityPlayer.SidedPos.X, player.WorldData.EntityPlayer.SidedPos.Y, player.WorldData.EntityPlayer.SidedPos.Z);
- api.SendMessage(player, groupId, "Teleporting to " + args[0].ToString(), EnumChatType.OwnMessage);
- 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);
- if (player.HasPrivilege("controlserver") == true && serverUtilsConfig.adminCooldown == false)
- {
- player.Entity.SetActivityRunning("HomeCooldown", 0);
- }
- else
- {
- player.Entity.SetActivityRunning("HomeCooldown", 1000 * serverUtilsConfig.homeCooldownSec);
- }
- }
- }
- }
- }
- else
- {
- api.SendMessage(player, groupId, "<icon name=lake></icon>Home Cooldown: " + (player.Entity.RemainingActivityTime("HomeCooldown") / 1000).ToString("#,##0") + "sec", EnumChatType.OwnMessage);
- }
- }
- public void CheckIfPlayerExists(IServerPlayer player, int groupId)
- {
- if (getPlayerIdByUID(player.PlayerUID) < 0)
- {
- playerData.players.Add(new PlayerInfo(player.PlayerName, player.PlayerUID, false, 0));
- //api.SendMessage(player, groupId, "Added player to the database.", EnumChatType.OwnMessage); //Debug Message
- playerData.players[getPlayerIdByUID(player.PlayerUID)].homes = new List<PlayerHomeInfo>();
- }
- }
- public int getPlayerIDByName(string name)
- {
- for (int i = 0; i < api.Server.Players.Length; i++)
- {
- if (api.Server.Players[i].PlayerName == name)
- {
- return i;
- }
- }
- return -1;
- }
- private void Quit(IServerPlayer player, int groupId, CmdArgs args)
- {
- if (args.Length > 0)
- {
- string argsMessage;
- argsMessage = "";
- for (int i = 0; i < args.Length; i++)
- {
- argsMessage += " " + args[i];
- }
- api.BroadcastMessageToAllGroups(player.PlayerName + argsMessage, EnumChatType.AllGroups);
- }
- else
- {
- api.BroadcastMessageToAllGroups(player.PlayerName + " has quit without a reason.", EnumChatType.AllGroups);
- }
- player.Disconnect();
- }
- private void PlayersList(IServerPlayer player, int groupId, CmdArgs args)
- {
- int playerAmount;
- string playerOnlineList;
- playerAmount = 0;
- playerOnlineList = "";
- api.SendMessage(player, groupId, "<icon name=wpPlayer></icon><strong>Players Online:</strong>", EnumChatType.OwnMessage);
- for (int i = 0; i < api.Server.Players.Length; i++)
- {
- if (api.Server.Players[i].ClientId > 0)
- {
- playerAmount += 1;
- api.SendMessage(player, groupId, "[" + playerAmount + "] " + api.Server.Players[i].PlayerName, EnumChatType.OwnMessage);
- }
- }
- api.SendMessage(player, groupId, "Total Online: " + playerAmount, EnumChatType.OwnMessage);
- }
- private void HomeList(IServerPlayer player, int groupId, CmdArgs args)
- {
- CheckIfPlayerExists(player, groupId);
- if (args.Length == 0 && playerData.players[getPlayerIdByUID(player.PlayerUID)].homes.Count > 0)
- {
- api.SendMessage(player, groupId, "<icon name=wpHome></icon><strong>Your Homes:</strong>", EnumChatType.OwnMessage);
- for (int i = 0; i < playerData.players[getPlayerIdByUID(player.PlayerUID)].homes.Count; i++)
- {
- api.SendMessage(player, groupId, "- " + playerData.players[getPlayerIdByUID(player.PlayerUID)].homes[i].homeName, EnumChatType.OwnMessage);
- }
- return;
- }
- if (args.Length > 0)
- {
- api.SendMessage(player, groupId, "No need to type extra stuff after this command...", EnumChatType.OwnMessage);
- return;
- }
- else
- {
- api.SendMessage(player, groupId, "You are currently homeless!", EnumChatType.OwnMessage);
- }
- }
- private void HomeHelp(IServerPlayer player, int groupId, CmdArgs args)
- {
- api.SendMessage(player, groupId, "You can set a home via ''/sethome [HomeName]'' and go to that home using ''/home [HomeName]''. ", EnumChatType.OwnMessage);
- 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);
- api.SendMessage(player, groupId, "You can delete your home using ''/delhome [HomeName]''", EnumChatType.OwnMessage);
- api.SendMessage(player, groupId, "You can get a list of your homes using ''/homelist''", EnumChatType.OwnMessage);
- }
- public int getHomeIdByName(int playerIndex, string name)
- {
- for (int index = 0; index < playerData.players[playerIndex].homes.Count; index++)
- {
- if (playerData.players[playerIndex].homes[index].homeName == name)
- {
- return index;
- }
- }
- return -1;
- }
- public int getWarpIdByName(string name)
- {
- for (int index = 0; index < serverWarps.warps.Count; index++)
- {
- if (serverWarps.warps[index].homeName == name)
- {
- return index;
- }
- }
- return -1;
- }
- public int getPlayerIdByUID(string uid)
- {
- for (int index = 0; index < playerData.players.Count; index++)
- {
- if (playerData.players[index].playerUID == uid)
- {
- return index;
- }
- }
- return -1;
- }
- private void CheckSleep(IServerPlayer player, int groupId, CmdArgs args)
- {
- int numPlayers = api.World.AllOnlinePlayers.Length;
- api.SendMessage(player, groupId, "Players Online: " + numPlayers, EnumChatType.OwnMessage);
- if (player.Entity.MountedOn is BlockEntityBed)
- {
- api.SendMessage(player, groupId, "Is Sleeping", EnumChatType.OwnMessage);
- }
- else
- {
- api.SendMessage(player, groupId, "Is not sleeping!", EnumChatType.OwnMessage);
- }
- //api.BroadcastMessageToAllGroups(player.PlayerName, EnumChatType.AllGroups);
- }
- private void Me(IServerPlayer player, int groupId, CmdArgs args)
- {
- if (args.Length > 0)
- {
- string argsMessage;
- argsMessage = "";
- for (int i = 0; i < args.Length; i++)
- {
- argsMessage += " " + args[i];
- }
- if (playerData.players[getPlayerIdByUID(player.PlayerUID)].isMuted == true)
- {
- api.SendMessage(player, groupId, "LOL you really think that was going to work when you are muted?", EnumChatType.OwnMessage);
- }
- else
- {
- api.BroadcastMessageToAllGroups(player.PlayerName + argsMessage, EnumChatType.AllGroups);
- }
- }
- else
- {
- if (playerData.players[getPlayerIdByUID(player.PlayerUID)].isMuted == true)
- {
- api.SendMessage(player, groupId, "LOL you really think that was going to work when you are muted?", EnumChatType.OwnMessage);
- }
- else
- {
- api.BroadcastMessageToAllGroups(player.PlayerName + " Doesn't know how to use /me", EnumChatType.AllGroups);
- }
- }
- }
- private void SpawnTele(IServerPlayer player, int groupId, CmdArgs args)
- {
- if (player.Entity.RemainingActivityTime("SpawnCooldown") <= 0)
- {
- playerData.players[getPlayerIdByUID(player.PlayerUID)].backPosition = new Vector3(player.WorldData.EntityPlayer.SidedPos.X, player.WorldData.EntityPlayer.SidedPos.Y, player.WorldData.EntityPlayer.SidedPos.Z);
- player.Entity.TeleportTo(api.World.DefaultSpawnPosition);
- api.SendMessage(player, groupId, "Teleporting to Spawn!", EnumChatType.OwnMessage);
- if (player.HasPrivilege("controlserver") == true && serverUtilsConfig.adminCooldown == false)
- {
- player.Entity.SetActivityRunning("SpawnCooldown", 0);
- }
- else
- {
- player.Entity.SetActivityRunning("SpawnCooldown", 1000 * serverUtilsConfig.spawnCooldownSec);
- }
- }
- else
- {
- api.SendMessage(player, groupId, "<icon name=lake></icon>Spawn Cooldown: " + (player.Entity.RemainingActivityTime("SpawnCooldown") / 1000).ToString("#,##0") + "sec", EnumChatType.OwnMessage);
- }
- }
- private void RandomTele(IServerPlayer player, int groupId, CmdArgs args) //Currently Broken
- {
- int randX = api.World.Rand.Next(api.WorldManager.MapSizeX);
- int randZ = api.World.Rand.Next(api.WorldManager.MapSizeZ);
- int randY = 256;
- player.Entity.TeleportTo(randX, randY, randZ);
- int? result = api.WorldManager.GetSurfacePosY(randX, randZ);
- if (result != null)
- {
- randY = (int)result;
- // Do the teleports!
- //randY = api.World.SeaLevel;
- player.Entity.TeleportTo(randX, randY, randZ);
- api.BroadcastMessageToAllGroups("Landing zone found! " + randY, EnumChatType.OwnMessage);
- }
- else
- {
- api.BroadcastMessageToAllGroups("Didnt Find landing zone!", EnumChatType.OwnMessage);
- }
- /*
- int? result = api.WorldManager.GetSurfacePosY(randX, randZ);
- if (result != null)
- {
- int randY = (int)result;
- // Do the teleports!
- player.Entity.TeleportTo(randX, randY, randZ);
- }
- else
- {
- player.Entity.TeleportTo(randX, 256, randZ);
- int? result2 = api.WorldManager.GetSurfacePosY(randX, randZ);
- if (result2 != null)
- {
- int randY = (int)result2;
- // Do the teleports!
- player.Entity.TeleportTo(randX, randY, randZ);
- }
- }
- */
- api.BroadcastMessageToAllGroups("Teleporting randomly!", EnumChatType.OwnMessage);
- }
- public void RTPTEST(IServerPlayer player)
- {
- int? result = api.WorldManager.GetSurfacePosY(0, 0);
- if (result != null)
- {
- player.Entity.TeleportTo(0, (int)result, 0);
- }
- }
- private async void DBG(IServerPlayer player, int groupId, CmdArgs args)//Used for testing.
- {
- //Find a random location
- int rndX = Convert.ToInt32(Math.Abs(api.World.Rand.Next(api.WorldManager.MapSizeX)));
- int rndZ = Convert.ToInt32(Math.Abs(api.World.Rand.Next(api.WorldManager.MapSizeZ)));
- //Loads chunks from bedrock to sky using coordinates to get the chunk location.
- api.WorldManager.LoadChunkColumnPriority(rndX / 32, rndZ / 32);
- api.BroadcastMessageToAllGroups("Loading Chunk Please Wait...", EnumChatType.OwnMessage);
- await Task.Delay(5000); //Delay to give the chunk time to load.
- int result = (int)api.WorldManager.GetSurfacePosY(rndX, rndZ); //Finds the highest block to land on.
- await Task.Delay(1000);
- if (result > 0)
- {
- api.BroadcastMessageToAllGroups("Teleporting...", EnumChatType.OwnMessage);
- await Task.Delay(1000);
- player.Entity.TeleportTo(rndX, result, rndZ);
- //api.WorldManager.UnloadChunkColumn(rndX/32, rndZ/32);
- }
- else //If it cant find a safe block to land on.
- {
- 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);
- }
- }
- private async void RTP(IServerPlayer player, int groupId, CmdArgs args)//Used for testing.
- {
- if (player.Entity.RemainingActivityTime("RTPCooldown") <= 0)
- {
- //Find a random location
- if (args.Length > 0)
- {
- try
- {
- int rndRange = Int32.Parse(args[0]);
- int rndRange2 = Int32.Parse(args[0]);
- if (rndRange > (Math.Abs(api.WorldManager.MapSizeX / 2) - 1000))
- {
- rndRange = (Math.Abs(api.WorldManager.MapSizeX / 2) - 1000);
- }
- if (rndRange > (Math.Abs(api.WorldManager.MapSizeZ / 2) - 1000))
- {
- rndRange = (Math.Abs(api.WorldManager.MapSizeZ / 2) - 1000);
- }
- int rndX = Convert.ToInt32(api.WorldManager.MapSizeX / 2) + api.World.Rand.Next(-rndRange, rndRange);
- int rndZ = Convert.ToInt32(api.WorldManager.MapSizeZ / 2) + api.World.Rand.Next(-rndRange, rndRange);
- //api.BroadcastMessageToAllGroups("RTP1", EnumChatType.OwnMessage);
- //Loads chunks from bedrock to sky using coordinates to get the chunk location.
- api.WorldManager.LoadChunkColumnPriority(rndX / 32, rndZ / 32);
- api.BroadcastMessageToAllGroups("Loading Chunk Please Wait " + serverUtilsConfig.rtpSearchTimer + " seconds...", EnumChatType.OwnMessage);
- await Task.Delay(1000 * serverUtilsConfig.rtpSearchTimer); //Delay to give the chunk time to load.
- int result = (int)api.WorldManager.GetSurfacePosY(rndX, rndZ); //Finds the highest block to land on.
- await Task.Delay(2000);
- if (result > 0)
- {
- playerData.players[getPlayerIdByUID(player.PlayerUID)].backPosition = new Vector3(player.WorldData.EntityPlayer.SidedPos.X, player.WorldData.EntityPlayer.SidedPos.Y, player.WorldData.EntityPlayer.SidedPos.Z);
- api.BroadcastMessageToAllGroups("Teleporting...", EnumChatType.OwnMessage);
- await Task.Delay(1000);
- player.Entity.TeleportToDouble(rndX, result, rndZ);
- //api.WorldManager.UnloadChunkColumn(rndX/32, rndZ/32);
- if (player.HasPrivilege("controlserver") == true && serverUtilsConfig.adminCooldown == false)
- {
- player.Entity.SetActivityRunning("RTPCooldown", 0);
- }
- else
- {
- player.Entity.SetActivityRunning("RTPCooldown", 1000 * serverUtilsConfig.rtpCooldownSec);
- }
- }
- else //If it cant find a safe block to land on.
- {
- api.BroadcastMessageToAllGroups("Failed to find landing zone. Please try again.", EnumChatType.OwnMessage);
- }
- }
- catch (Exception e)
- {
- api.BroadcastMessageToAllGroups("Please use a valid number.", EnumChatType.OwnMessage);
- //throw;
- }
- }
- else
- {
- //int rndX = Math.Abs(api.World.Rand.Next(Convert.ToInt32((-api.WorldManager.MapSizeX / 16) * .10), Convert.ToInt32((api.WorldManager.MapSizeX / 16) * .10)));
- //int rndZ = Math.Abs(api.World.Rand.Next(Convert.ToInt32((-api.WorldManager.MapSizeZ / 16) * .10), Convert.ToInt32((api.WorldManager.MapSizeZ / 16) * .10)));
- 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));
- 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));
- //api.BroadcastMessageToAllGroups("RTP: "+ (-api.WorldManager.MapSizeX / 16) * .10 + " "+ (api.WorldManager.MapSizeX / 16) * .10, EnumChatType.OwnMessage);
- //api.BroadcastMessageToAllGroups("RTP: "+rndX+ " "+rndZ, EnumChatType.OwnMessage);
- //Loads chunks from bedrock to sky using coordinates to get the chunk location.
- api.WorldManager.LoadChunkColumnPriority(rndX / 32, rndZ / 32);
- api.BroadcastMessageToAllGroups("Loading Chunk Please Wait " + serverUtilsConfig.rtpSearchTimer + " seconds...", EnumChatType.OwnMessage);
- await Task.Delay(1000 * serverUtilsConfig.rtpSearchTimer); //Delay to give the chunk time to load.
- int result = (int)api.WorldManager.GetSurfacePosY(rndX, rndZ); //Finds the highest block to land on.
- await Task.Delay(2000);
- if (result > 0)
- {
- playerData.players[getPlayerIdByUID(player.PlayerUID)].backPosition = new Vector3(player.WorldData.EntityPlayer.SidedPos.X, player.WorldData.EntityPlayer.SidedPos.Y, player.WorldData.EntityPlayer.SidedPos.Z);
- api.BroadcastMessageToAllGroups("Teleporting...", EnumChatType.OwnMessage);
- await Task.Delay(1000);
- //api.BroadcastMessageToAllGroups("RTP real: " + rndX + " " + rndZ, EnumChatType.OwnMessage);
- player.Entity.TeleportToDouble(rndX, result, rndZ);
- //api.WorldManager.UnloadChunkColumn(rndX/32, rndZ/32);
- if (player.HasPrivilege("controlserver") == true && serverUtilsConfig.adminCooldown == false)
- {
- player.Entity.SetActivityRunning("RTPCooldown", 0);
- }
- else
- {
- player.Entity.SetActivityRunning("RTPCooldown", 1000 * serverUtilsConfig.rtpCooldownSec);
- }
- }
- else //If it cant find a safe block to land on.
- {
- api.BroadcastMessageToAllGroups("Failed to find landing zone. Please try again.", EnumChatType.OwnMessage);
- }
- }
- }
- else
- {
- api.SendMessage(player, groupId, "<icon name=lake></icon>RTP Cooldown: " + (player.Entity.RemainingActivityTime("RTPCooldown") / 1000).ToString("#,##0") + "sec", EnumChatType.OwnMessage);
- }
- }
- private void NoClip(IServerPlayer player, int groupId, CmdArgs args)//Used for testing.
- {
- if (player.WorldData.NoClip == false)
- {
- player.WorldData.NoClip = true;
- api.BroadcastMessageToAllGroups("Noclip Enabled", EnumChatType.OwnMessage);
- }
- else if (player.WorldData.NoClip == true)
- {
- player.WorldData.NoClip = false;
- api.BroadcastMessageToAllGroups("Noclip Disabled", EnumChatType.OwnMessage);
- }
- player.BroadcastPlayerData();
- }
- private void FindChunk(IServerPlayer player, int groupId, CmdArgs args)
- {
- api.BroadcastMessageToAllGroups("Chunk Size: " + api.WorldManager.GetChunk(player.Entity.ServerPos.AsBlockPos).MapChunk.YMax, EnumChatType.OwnMessage);
- }
- private void GetPing(IServerPlayer player, int groupId, CmdArgs args)
- {
- api.BroadcastMessageToAllGroups("Ping: " + player.Ping.ToString(), EnumChatType.OwnMessage);
- }
- private void GetTPS(IServerPlayer player, int groupId, CmdArgs args)
- {
- api.BroadcastMessageToAllGroups("TPS: " + serverConfig.TickTime.ToString(), EnumChatType.OwnMessage);
- }
- private void Back(IServerPlayer player, int groupId, CmdArgs args)
- {
- if (player.Entity.RemainingActivityTime("BackCooldown") <= 0)
- {
- if (playerData.players[getPlayerIdByUID(player.PlayerUID)].backPosition == null)
- {
- api.SendMessage(player, groupId, "No back location to teleport to.", EnumChatType.OwnMessage);
- }
- else
- {
- if(serverUtilsConfig.enableGearToTeleport == true)
- {
- if (player.InventoryManager.ActiveHotbarSlot.Itemstack != null && player.InventoryManager.ActiveHotbarSlot.Itemstack.GetName() == "Temporal gear")
- {
- api.SendMessage(player, groupId, "Temporal Gear was used to teleport back", EnumChatType.OwnMessage);
- player.Entity.TeleportToDouble(playerData.players[getPlayerIdByUID(player.PlayerUID)].backPosition.X, playerData.players[getPlayerIdByUID(player.PlayerUID)].backPosition.Y, playerData.players[getPlayerIdByUID(player.PlayerUID)].backPosition.Z);
- //api.SendMessage(player, groupId, "Teleporting back", EnumChatType.OwnMessage);
- player.InventoryManager.NotifySlot(player, player.InventoryManager.ActiveHotbarSlot);
- player.InventoryManager.ActiveHotbarSlot.TakeOutWhole();
- playerData.players[getPlayerIdByUID(player.PlayerUID)].backPosition = null;
- if (player.HasPrivilege("controlserver") == true && serverUtilsConfig.adminCooldown == false)
- {
- player.Entity.SetActivityRunning("BackCooldown", 0);
- }
- else
- {
- player.Entity.SetActivityRunning("BackCooldown", 1000 * serverUtilsConfig.backCooldownSec);
- }
- }
- else
- {
- api.SendMessage(player, groupId, "No temporal gear found in main hand", EnumChatType.OwnMessage);
- }
- }
- else
- {
- player.Entity.TeleportToDouble(playerData.players[getPlayerIdByUID(player.PlayerUID)].backPosition.X, playerData.players[getPlayerIdByUID(player.PlayerUID)].backPosition.Y, playerData.players[getPlayerIdByUID(player.PlayerUID)].backPosition.Z);
- api.SendMessage(player, groupId, "Teleporting back", EnumChatType.OwnMessage);
- playerData.players[getPlayerIdByUID(player.PlayerUID)].backPosition = null;
- if (player.HasPrivilege("controlserver") == true && serverUtilsConfig.adminCooldown == false)
- {
- player.Entity.SetActivityRunning("BackCooldown", 0);
- }
- else
- {
- player.Entity.SetActivityRunning("BackCooldown", 1000 * serverUtilsConfig.backCooldownSec);
- }
- }
- }
- }
- else
- {
- api.SendMessage(player, groupId, "<icon name=lake></icon>Back Cooldown: " + (player.Entity.RemainingActivityTime("BackCooldown") / 1000).ToString("#,##0") + "sec", EnumChatType.OwnMessage);
- }
- }
- public void FindOre(IServerPlayer player, int groupId, CmdArgs args)
- {
- int oreFound = 0;
- //api.SendMessage(player, 0, "Block: "+ api.WorldManager.GetChunk(player.Entity.ServerPos.AsBlockPos).Blocks[0].ToString(), EnumChatType.OwnMessage);
- if (args.Length > 0)
- {
- if (player.InventoryManager.ActiveHotbarSlot.Itemstack != null && player.InventoryManager.ActiveHotbarSlot.Itemstack.GetName().Contains("prospecting pick"))
- {
- if (player.InventoryManager.ActiveHotbarSlot.Itemstack.Attributes.GetInt(@"durability", player.InventoryManager.ActiveHotbarSlot.Itemstack.Item.Durability) >= Convert.ToInt32(args[0]))
- {
- oreFound = 0;
- //player.InventoryManager.ActiveHotbarSlot.Itemstack.Collectible.Durability
- //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);
- for (int i = 0; i < Convert.ToInt32(args[0]); i++)
- {
- //api.SendMessage(player, 0, "Block: " + api.World.GetBlock(api.WorldManager.GetChunk(player.Entity.ServerPos.AsBlockPos).Blocks[i]).Drops[0].ToString()+", ", EnumChatType.OwnMessage);
- //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);
- //player.Entity.World.BlockAccessor.GetBlock(player.Entity.ServerPos.AsBlockPos.X, player.Entity.ServerPos.AsBlockPos.Y-i, player.Entity.ServerPos.AsBlockPos.Z).Code.FirstPathPart();
- 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-"))
- {
- 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);
- oreFound++;
- }
- }
- if (oreFound == 0)
- {
- api.SendMessage(player, 0, "No ore found.", EnumChatType.OwnMessage);
- }
- player.InventoryManager.NotifySlot(player, player.InventoryManager.ActiveHotbarSlot);
- player.InventoryManager.ActiveHotbarSlot.MarkDirty();
- player.InventoryManager.ActiveHotbarSlot.Itemstack.Attributes.SetInt(@"durability", player.InventoryManager.ActiveHotbarSlot.Itemstack.Attributes.GetInt(@"durability", player.InventoryManager.ActiveHotbarSlot.Itemstack.Item.Durability) - Convert.ToInt32(args[0]));
- player.InventoryManager.ActiveHotbarSlot.MarkDirty();
- //player.InventoryManager.DropItem(player.InventoryManager.ActiveHotbarSlot,true);
- //player.InventoryManager.ActiveHotbarSlot.Itemstack.Item.DamageItem(worldAccess, player.Entity, player.InventoryManager.ActiveHotbarSlot, Convert.ToInt32(args[0]));
- if (player.InventoryManager.ActiveHotbarSlot.Itemstack == null || player.InventoryManager.ActiveHotbarSlot.Itemstack.Attributes.GetInt(@"durability", player.InventoryManager.ActiveHotbarSlot.Itemstack.Item.Durability) <= 0)
- {
- api.SendMessage(player, 0, "Your prospecting pick ran out of durability and was destroyed.", EnumChatType.OwnMessage);
- player.InventoryManager.ActiveHotbarSlot.TakeOutWhole();
- //player.InventoryManager.DropItem(player.InventoryManager.ActiveHotbarSlot,true);
- }
- }
- else
- {
- api.SendMessage(player, 0, "Not enough durability. Durability remaining: " + player.InventoryManager.ActiveHotbarSlot.Itemstack.Attributes.GetInt(@"durability", player.InventoryManager.ActiveHotbarSlot.Itemstack.Item.Durability), EnumChatType.OwnMessage);
- }
- }
- else
- {
- api.SendMessage(player, 0, "No prospecting pick found in hand.", EnumChatType.OwnMessage);
- }
- }
- else
- {
- api.SendMessage(player, 0, "Please input a distance to search down.", EnumChatType.OwnMessage);
- }
- }
- private void TellMe(IServerPlayer player, int groupId, CmdArgs args)
- {
- api.BroadcastMessageToAllGroups("Hotbar Item: " + player.InventoryManager.ActiveHotbarSlot.Itemstack.GetName(), EnumChatType.OwnMessage);
- }
- }
- }
Add Comment
Please, Sign In to add comment