diff --git a/source/BP-Essentials/BP-Essentials.csproj b/source/BP-Essentials/BP-Essentials.csproj index bd58cc6f..43dad619 100644 --- a/source/BP-Essentials/BP-Essentials.csproj +++ b/source/BP-Essentials/BP-Essentials.csproj @@ -1,4 +1,4 @@ - + @@ -10,7 +10,7 @@ Properties BP_Essentials BP_Essentials - v4.5 + v4.7.2 512 @@ -40,8 +40,12 @@ BP-Essentials.ruleset false + + false + + @@ -65,15 +69,19 @@ + + + + @@ -94,6 +102,7 @@ + @@ -107,29 +116,35 @@ - - - - + + + + + + - - + + + + + + + - - + @@ -138,7 +153,6 @@ - @@ -152,7 +166,6 @@ - diff --git a/source/BP-Essentials/Chat/Announce.cs b/source/BP-Essentials/Chat/Announce.cs index ec1f9e21..6d38158b 100644 --- a/source/BP-Essentials/Chat/Announce.cs +++ b/source/BP-Essentials/Chat/Announce.cs @@ -3,21 +3,44 @@ using System.Linq; using System.Text; using UnityEngine; -using static BP_Essentials.EssentialsVariablesPlugin; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.Variables; +using static BP_Essentials.HookMethods; using System.Threading; -namespace BP_Essentials.Chat +namespace BP_Essentials { - class Announce : EssentialsCorePlugin - { - public static void Run() + public class Announcer + { + public System.Timers.Timer Timer { get; private set; } + public List Announcements { get; set; } = new List(); + public double Interval + { + get => Timer.Interval; + set + { + Timer.Enabled = false; + Timer.Interval = value * 1000; + Timer.Enabled = true; + } + } + public Announcer(List announcements) : this() + { + Announcements = announcements; + } + public Announcer() { try { - _Timer.Elapsed += (sender, e) => OnTime(); - _Timer.Interval = TimeBetweenAnnounce * 1000; - _Timer.Enabled = true; + Timer = new System.Timers.Timer(); + + Timer.Elapsed += (sender, e) => OnTime(); + if (TimeBetweenAnnounce == 0) + { + Timer.Enabled = false; + return; + } + Timer.Interval = TimeBetweenAnnounce * 1000; + Timer.Enabled = true; } catch (Exception ex) { @@ -25,17 +48,21 @@ public static void Run() } } - private static void OnTime() - { - if (!string.IsNullOrWhiteSpace(Announcements[AnnounceIndex])) - { - foreach (var player in SvMan.players) - foreach (var line in Announcements[AnnounceIndex].Split(new[] { "\\r\\n", "\\r", "\\n" }, StringSplitOptions.None)) - player.Value.svPlayer.Send(SvSendType.Self, Channel.Reliable, ClPacket.GameMessage, line); - Debug.Log($"{SetTimeStamp.Run()}[INFO] Announcement made..."); - } - if (++AnnounceIndex > Announcements.Length - 1) - AnnounceIndex = 0; - } + void OnTime() + { + if (Announcements == null || Announcements.Count == 0) + return; + if (++AnnounceIndex > Announcements.Count - 1) + AnnounceIndex = 0; + if (string.IsNullOrWhiteSpace(Announcements[AnnounceIndex])) + return; + var lines = Announcements[AnnounceIndex].Split(new[] { "\r\n", "\r", "\n", "\\r\\n", "\\r", "\\n" }, StringSplitOptions.None); + foreach (var player in SvMan.players) + { + foreach (var line in lines) + player.Value.svPlayer.Send(SvSendType.Self, Channel.Reliable, ClPacket.GameMessage, line); + } + Debug.Log($"{PlaceholderParser.ParseTimeStamp()} [INFO] Announcement made..."); + } } } \ No newline at end of file diff --git a/source/BP-Essentials/Chat/Commands/Admin/Arrest.cs b/source/BP-Essentials/Chat/Commands/Admin/Arrest.cs index 3f4412f8..86a5aa5a 100644 --- a/source/BP-Essentials/Chat/Commands/Admin/Arrest.cs +++ b/source/BP-Essentials/Chat/Commands/Admin/Arrest.cs @@ -3,31 +3,28 @@ using System.Linq; using System.Text; using UnityEngine; -using static BP_Essentials.EssentialsVariablesPlugin; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.Variables; namespace BP_Essentials.Commands { class Arrest { - public static void Run(SvPlayer player, string message) - { - string arg1 = GetArgument.Run(1, false, true, message); - if (!string.IsNullOrEmpty(arg1)) - { - var shPlayer = GetShByStr.Run(arg1); - if (shPlayer == null) - { - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, NotFoundOnline); - return; - } - shPlayer.svPlayer.Restrain(shPlayer.manager.handcuffed); - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"Arrested " + shPlayer.username + $"."); - - } - else - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, ArgRequired); - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, ArgRequired); - } + public static void Run(SvPlayer player, string message) + { + string arg1 = GetArgument.Run(1, false, true, message); + if (string.IsNullOrEmpty(arg1)) + { + player.SendChatMessage(ArgRequired); + return; + } + var shPlayer = GetShByStr.Run(arg1); + if (shPlayer == null) + { + player.SendChatMessage(NotFoundOnline); + return; + } + shPlayer.svPlayer.Restrain(shPlayer.manager.handcuffed); + player.SendChatMessage($"Arrested {shPlayer.username}."); + } } } diff --git a/source/BP-Essentials/Chat/Commands/Admin/Back.cs b/source/BP-Essentials/Chat/Commands/Admin/Back.cs new file mode 100644 index 00000000..f2ae094b --- /dev/null +++ b/source/BP-Essentials/Chat/Commands/Admin/Back.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using UnityEngine; +using static BP_Essentials.Variables; +using static BP_Essentials.HookMethods; + +namespace BP_Essentials.Commands +{ + class Back + { + public static void Run(SvPlayer player, string message) + { + var lastLocation = PlayerList[player.player.ID].LastLocation; + if (!lastLocation.HasPositionSet()) + { + player.SendChatMessage($"There is no location to teleport to."); + return; + } + player.ResetAndSavePosition(lastLocation.Position, lastLocation.Rotation, lastLocation.PlaceIndex); + player.SendChatMessage($"You've been teleported to your last known location."); + } + } +} diff --git a/source/BP-Essentials/Chat/Commands/Admin/Ban.cs b/source/BP-Essentials/Chat/Commands/Admin/Ban.cs index 6c3ae406..d7435a86 100644 --- a/source/BP-Essentials/Chat/Commands/Admin/Ban.cs +++ b/source/BP-Essentials/Chat/Commands/Admin/Ban.cs @@ -1,29 +1,29 @@ using System; -using static BP_Essentials.EssentialsVariablesPlugin; +using static BP_Essentials.Variables; namespace BP_Essentials.Commands { public class Ban { - public static void Run(SvPlayer player, string message) - { - var arg1 = GetArgument.Run(1, false, false, message); - var arg2 = GetArgument.Run(2, false, true, message); - if (!string.IsNullOrEmpty(arg1) && !string.IsNullOrEmpty(arg2)) - { - var shPlayer = GetShByStr.Run(arg1, true); - if (shPlayer == null) - { - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, NotFoundOnlineIdOnly); - return; - } - LogMessage.LogOther($"{SetTimeStamp.Run()}[INFO] {shPlayer.username} Got banned by {player.playerData.username} (Reason: {arg2}"); - player.Send(SvSendType.All, Channel.Unsequenced, ClPacket.GameMessage, $"{shPlayer.username} Just got banned by {player.playerData.username} (Reason: {arg2})"); - SendDiscordMessage.BanMessage(shPlayer.username, player.playerData.username, arg2); - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"Banned {shPlayer.username}. (Reason: {arg2})"); - player.svManager.AddBanned(shPlayer); - player.svManager.Disconnect(shPlayer.svPlayer.connection); - } - else - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, ArgRequired); - } + public static void Run(SvPlayer player, string message) + { + var arg1 = GetArgument.Run(1, false, false, message); + var arg2 = GetArgument.Run(2, false, true, message); + if (string.IsNullOrEmpty(arg1) || string.IsNullOrEmpty(arg2)) + { + player.SendChatMessage(ArgRequired); + return; + } + var shPlayer = GetShByStr.Run(arg1, true); + if (shPlayer == null) + { + player.SendChatMessage(NotFoundOnlineIdOnly); + return; + } + LogMessage.LogOther($"{PlaceholderParser.ParseTimeStamp()} [INFO] {shPlayer.username} Got banned by {player.playerData.username} (Reason: {arg2}"); + player.Send(SvSendType.All, Channel.Unsequenced, ClPacket.GameMessage, $"{shPlayer.username} Just got banned by {player.playerData.username} (Reason: {arg2})"); + SendDiscordMessage.BanMessage(shPlayer.username, player.playerData.username, arg2); + player.SendChatMessage($"Banned {shPlayer.username}. (Reason: {arg2})"); + player.svManager.AddBanned(shPlayer); + player.svManager.Disconnect(shPlayer.svPlayer.connection, DisconnectTypes.Banned); + } } } \ No newline at end of file diff --git a/source/BP-Essentials/Chat/Commands/Admin/CheckAlts.cs b/source/BP-Essentials/Chat/Commands/Admin/CheckAlts.cs index 17c79dd7..8d92292e 100644 --- a/source/BP-Essentials/Chat/Commands/Admin/CheckAlts.cs +++ b/source/BP-Essentials/Chat/Commands/Admin/CheckAlts.cs @@ -3,58 +3,58 @@ using System.Linq; using System.Text; using UnityEngine; -using static BP_Essentials.EssentialsVariablesPlugin; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.Variables; +using static BP_Essentials.HookMethods; using System.IO; namespace BP_Essentials.Commands { class CheckAlts { - public static void Run(SvPlayer player, string message) - { - var arg1 = GetArgument.Run(1, false, false, message); - var found = 0; - if (!String.IsNullOrEmpty(arg1)) - { - var arg2 = GetArgument.Run(2, false, true, message); - if (arg1.Equals("ip", StringComparison.InvariantCultureIgnoreCase)) - { - var content = "Possible accounts using the IP " + arg2 + ":\r\n\r\n"; - var builder = new StringBuilder(); - builder.Append(content); - foreach (var line in File.ReadAllLines(IpListFile)) - { - if (line.EndsWith(arg2)) - { - ++found; - builder.Append(line.Replace(": " + arg2, String.Empty) + "\r\n"); - } - } - content = builder.ToString(); - content += "\r\n\r\n" + arg2 + " occurred " + found + " times in the iplog file." + "\r\n"; - player.Send(SvSendType.Self, Channel.Reliable, ClPacket.ServerInfo, content); - } - else if (arg1.Equals("ign", StringComparison.InvariantCultureIgnoreCase) || (arg1.Equals(nameof(player), StringComparison.InvariantCultureIgnoreCase))) - { - var content = "Possible logins on the account " + arg2 + " using the following IP's:\r\n\r\n"; - var builder = new StringBuilder(); - builder.Append(content); - foreach (var line in File.ReadAllLines(IpListFile)) - { - if (line.StartsWith(arg2 + ": ")) - { - ++found; - builder.Append(line.Replace(arg2 + ": ", String.Empty) + "\r\n"); - } - } - content = builder.ToString(); - content = content + "\r\n\r\n" + arg2 + " occurred " + found + " times in the iplog file." + "\r\n"; - player.Send(SvSendType.Self, Channel.Reliable, ClPacket.ServerInfo, content); - } - } - else - player.Send(SvSendType.Self, Channel.Reliable, ClPacket.GameMessage, GetArgument.Run(0, false,false,message) + "[IP/IGN] [Arg2] Eg " + GetArgument.Run(0,false,false,message) + " ip 127.0.0.1"); - } + public static void Run(SvPlayer player, string message) + { + var arg1 = GetArgument.Run(1, false, false, message); + var found = 0; + if (string.IsNullOrEmpty(arg1)) + { + player.SendChatMessage(GetArgument.Run(0, false, false, message) + "[IP/IGN] [Arg2] Eg " + GetArgument.Run(0, false, false, message) + " ip 127.0.0.1"); + return; + } + var arg2 = GetArgument.Run(2, false, true, message); + if (arg1.Equals("ip", StringComparison.InvariantCultureIgnoreCase)) + { + var content = "Possible accounts using the IP " + arg2 + ":\r\n\r\n"; + var builder = new StringBuilder(); + builder.Append(content); + foreach (var line in File.ReadAllLines(IpListFile)) + { + if (line.EndsWith(arg2, StringComparison.CurrentCulture)) + { + ++found; + builder.Append(line.Replace(": " + arg2, string.Empty) + "\r\n"); + } + } + content = builder.ToString(); + content += "\r\n\r\n" + arg2 + " occurred " + found + " times in the iplog file." + "\r\n"; + player.Send(SvSendType.Self, Channel.Reliable, ClPacket.ServerInfo, content); + } + else if (arg1.Equals("ign", StringComparison.InvariantCultureIgnoreCase) || (arg1.Equals(nameof(player), StringComparison.InvariantCultureIgnoreCase))) + { + var content = "Possible logins on the account " + arg2 + " using the following IP's:\r\n\r\n"; + var builder = new StringBuilder(); + builder.Append(content); + foreach (var line in File.ReadAllLines(IpListFile)) + { + if (line.StartsWith(arg2 + ": ", StringComparison.CurrentCulture)) + { + ++found; + builder.Append(line.Replace(arg2 + ": ", string.Empty) + "\r\n"); + } + } + content = builder.ToString(); + content = content + "\r\n\r\n" + arg2 + " occurred " + found + " times in the iplog file." + "\r\n"; + player.Send(SvSendType.Self, Channel.Reliable, ClPacket.ServerInfo, content); + } + } } } diff --git a/source/BP-Essentials/Chat/Commands/Admin/Clear.cs b/source/BP-Essentials/Chat/Commands/Admin/Clear.cs index 75b05eec..4be433f0 100644 --- a/source/BP-Essentials/Chat/Commands/Admin/Clear.cs +++ b/source/BP-Essentials/Chat/Commands/Admin/Clear.cs @@ -1,31 +1,31 @@ using System; using System.Collections.Generic; -using static BP_Essentials.EssentialsVariablesPlugin; +using static BP_Essentials.Variables; namespace BP_Essentials.Commands { public class Clear { - public static void Run(SvPlayer player, string message) - { - string arg1 = GetArgument.Run(1, false, true, message); - if (!string.IsNullOrEmpty(arg1)) - { - var shPlayer = GetShByStr.Run(arg1); - if (shPlayer == null) - { - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, NotFoundOnline); - return; - } - var tempList = new List(); - foreach (var item in shPlayer.myItems.Values) - tempList.Add(item); - for (int i = 0; i < tempList.Count; i++) - shPlayer.TransferItem(2, tempList[i].item.index, shPlayer.MyItemCount(tempList[i].item.index), true); - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"You cleared the inventory of {shPlayer.username}."); - shPlayer.svPlayer.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"Your inventory has been cleared by {player.playerData.username}."); - } - else - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, ArgRequired); - } + public static void Run(SvPlayer player, string message) + { + string arg1 = GetArgument.Run(1, false, true, message); + if (string.IsNullOrEmpty(arg1)) + { + player.SendChatMessage(ArgRequired); + return; + } + var shPlayer = GetShByStr.Run(arg1); + if (shPlayer == null) + { + player.SendChatMessage(NotFoundOnline); + return; + } + var tempList = new List(); + foreach (var item in shPlayer.myItems.Values) + tempList.Add(item); + for (int i = 0; i < tempList.Count; i++) + shPlayer.TransferItem(2, tempList[i].item.index, shPlayer.MyItemCount(tempList[i].item.index), true); + player.SendChatMessage($"You cleared the inventory of {shPlayer.username}."); + shPlayer.svPlayer.SendChatMessage($"Your inventory has been cleared by {player.playerData.username}."); + } } } \ No newline at end of file diff --git a/source/BP-Essentials/Chat/Commands/Admin/ClearWanted.cs b/source/BP-Essentials/Chat/Commands/Admin/ClearWanted.cs index 11ff9496..79006c34 100644 --- a/source/BP-Essentials/Chat/Commands/Admin/ClearWanted.cs +++ b/source/BP-Essentials/Chat/Commands/Admin/ClearWanted.cs @@ -3,34 +3,27 @@ using System.Linq; using System.Text; using UnityEngine; -using static BP_Essentials.EssentialsVariablesPlugin; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.Variables; +using static BP_Essentials.HookMethods; namespace BP_Essentials.Commands { class ClearWanted { - public static void Run(SvPlayer player, string message) - { - bool found = false; - string arg1 = GetArgument.Run(1, false, true, message); - string msg; - if (String.IsNullOrEmpty(arg1)) - { - arg1 = player.playerData.username; - msg = "yourself"; - } - foreach (var shPlayer in UnityEngine.Object.FindObjectsOfType()) - if (shPlayer.username == arg1 && !shPlayer.svPlayer.serverside || shPlayer.ID.ToString() == arg1.ToString() && !shPlayer.svPlayer.serverside) - { - msg = shPlayer.username; - shPlayer.ClearCrimes(); - shPlayer.svPlayer.Send(SvSendType.Self, Channel.Reliable, 33, shPlayer.ID); - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"Cleared crimes of '" + msg + "'."); - found = true; - } - if (!found) - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, NotFoundOnline); - } + public static void Run(SvPlayer player, string message) + { + string arg1 = GetArgument.Run(1, false, true, message); + if (string.IsNullOrEmpty(arg1)) + arg1 = player.player.username; + var currPlayer = GetShByStr.Run(arg1); + if (currPlayer == null) + { + player.SendChatMessage(NotFoundOnline); + return; + } + currPlayer.ClearCrimes(); + currPlayer.svPlayer.Send(SvSendType.Self, Channel.Reliable, ClPacket.ClearCrimes, currPlayer.ID); + player.SendChatMessage($"Cleared crimes of '{currPlayer.username}'."); + } } } diff --git a/source/BP-Essentials/Chat/Commands/Admin/CreateKit.cs b/source/BP-Essentials/Chat/Commands/Admin/CreateKit.cs index ae328623..de365c11 100644 --- a/source/BP-Essentials/Chat/Commands/Admin/CreateKit.cs +++ b/source/BP-Essentials/Chat/Commands/Admin/CreateKit.cs @@ -1,6 +1,6 @@ -using static BP_Essentials.EssentialsVariablesPlugin; +using static BP_Essentials.Variables; using System; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.HookMethods; using System.IO; using System.Collections.Generic; using Newtonsoft.Json; @@ -11,32 +11,41 @@ public class CreateKit { public static void Run(SvPlayer player, string message) { - var arg1 = GetArgument.Run(1, false, false, message); - var arg2 = GetArgument.Run(2, false, false, message); - var arg3 = GetArgument.Run(3, false, true, message); + var arg1 = GetArgument.Run(1, false, false, message); // (int)DelayInSeconds + var arg2 = GetArgument.Run(2, false, false, message); // (int)Price + var arg3 = GetArgument.Run(3, false, true, message); // (string)KitName if (string.IsNullOrEmpty(arg1.Trim()) || string.IsNullOrEmpty(arg2.Trim()) || string.IsNullOrEmpty(arg3.Trim())) { - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, ArgRequired); + player.SendChatMessage(ArgRequired); return; } if (!int.TryParse(arg1, out int arg1i) || !int.TryParse(arg2, out int arg2i)) { - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"Cannot convert {arg1} or {arg2} to a integer."); + player.SendChatMessage($"Cannot convert {arg1} or {arg2} to a integer."); return; } if (arg1i < 0) { - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"The delay must be a positive number (0 to disable)"); + player.SendChatMessage($"The delay must be a positive number (0 to disable)"); return; } - var file = Path.Combine(KitDirectory, $"{arg2}.json"); + var file = Path.Combine(KitDirectory, $"{arg3}.json"); if (File.Exists(file)) { - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"A kit already exists with that name."); + player.SendChatMessage($"A kit already exists with that name."); return; } - Kits.CreateKit(player, arg3, arg1i, arg2i, file); - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"Kit created. Please edit {file} to add ExecuteableBy."); + var obj = new KitsHandler.JsonModel + { + Delay = arg1i, + Price = arg2i < 0 ? 0 : arg2i, + Name = arg3, + ExecutableBy = "everyone" + }; + foreach (var item in player.player.myItems.Values) + obj.Items.Add(new KitsHandler.Kits_Item { Amount = item.count, Id = item.item.index }); + Variables.KitsHandler.CreateNew(obj, arg3); + player.SendChatMessage($"Kit created. Please edit {file} to add ExecuteableBy."); } } } \ No newline at end of file diff --git a/source/BP-Essentials/Chat/Commands/Admin/CreateWarp.cs b/source/BP-Essentials/Chat/Commands/Admin/CreateWarp.cs index d08a2ee1..722c25a1 100644 --- a/source/BP-Essentials/Chat/Commands/Admin/CreateWarp.cs +++ b/source/BP-Essentials/Chat/Commands/Admin/CreateWarp.cs @@ -1,6 +1,6 @@ -using static BP_Essentials.EssentialsVariablesPlugin; +using static BP_Essentials.Variables; using System; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.HookMethods; using System.IO; using System.Collections.Generic; using Newtonsoft.Json; @@ -11,32 +11,46 @@ public class CreateWarp { public static void Run(SvPlayer player, string message) { - var arg1 = GetArgument.Run(1, false, false, message); - var arg2 = GetArgument.Run(2, false, false, message); - var arg3 = GetArgument.Run(3, false, true, message); - if (string.IsNullOrEmpty(arg1.Trim()) || string.IsNullOrEmpty(arg2.Trim()) || string.IsNullOrEmpty(arg3.Trim())) + var arg1 = GetArgument.Run(1, false, false, message); // (int)DelayInSeconds + var arg2 = GetArgument.Run(2, false, false, message); // (int)Price + var arg3 = GetArgument.Run(3, false, true, message); // (string)KitName + if (string.IsNullOrEmpty(arg1.Trim()) || string.IsNullOrEmpty(arg2.Trim()) || string.IsNullOrEmpty(arg3.Trim())) { - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, ArgRequired); + player.SendChatMessage(ArgRequired); return; } if (!int.TryParse(arg1, out int arg1i) || !int.TryParse(arg2, out int arg2i)) { - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"Cannot convert {arg1} or {arg2} to a integer."); + player.SendChatMessage($"Cannot convert {arg1} or {arg2} to a integer."); return; } if (arg1i < 0) { - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"The delay must be a positive number (0 to disable)"); + player.SendChatMessage($"The delay must be a positive number (0 to disable)"); return; } + if (player.InApartment()) + { + player.SendChatMessage($"You cannot set a warp inside any apartment, as they are not fixed places."); + return; + } var file = Path.Combine(WarpDirectory, $"{arg3}.json"); if (File.Exists(file)) { - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"A warp already exists with that name."); + player.SendChatMessage($"A warp already exists with that name."); return; } - Warps.CreateWarp(player, arg3, arg1i, arg2i, file); - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"Warp created. Please edit {file} to add ExecuteableBy and Price."); + var obj = new WarpHandler.JsonModel + { + Delay = arg1i, + Price = arg2i < 0 ? 0 : arg2i, + Name = arg3, + ExecutableBy = "everyone", + Position = new WarpHandler.Position { X = player.player.GetPosition().x, Y = player.player.GetPosition().y, Z = player.player.GetPosition().z, PlaceIndex = player.player.GetPlaceIndex() }, + Rotation = new WarpHandler.Rotation { X = player.player.GetRotation().x, Y = player.player.GetRotation().y, Z = player.player.GetRotation().z, W = player.player.GetRotation().w } + }; + Variables.WarpHandler.CreateNew(obj, arg3); + player.SendChatMessage($"Warp created. Please edit {file} to add ExecuteableBy."); } } } \ No newline at end of file diff --git a/source/BP-Essentials/Chat/Commands/Admin/DebugCommands.cs b/source/BP-Essentials/Chat/Commands/Admin/DebugCommands.cs index f9a9f9a8..30ee805a 100644 --- a/source/BP-Essentials/Chat/Commands/Admin/DebugCommands.cs +++ b/source/BP-Essentials/Chat/Commands/Admin/DebugCommands.cs @@ -1,10 +1,11 @@ using UnityEngine; -using static BP_Essentials.EssentialsMethodsPlugin; -using static BP_Essentials.EssentialsVariablesPlugin; +using static BP_Essentials.HookMethods; +using static BP_Essentials.Variables; using System; using System.Reflection; using System.Text; using System.IO; +using System.Collections.Generic; namespace BP_Essentials.Commands { @@ -15,103 +16,123 @@ public static void Run(SvPlayer player, string message) var shPlayer = player.player; string arg = GetArgument.Run(1, false, false, message).Trim().ToLower(); - if (arg == "location" || arg == "getlocation") - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, "Your location: " + shPlayer.GetPosition()); - else if (arg == "getplayerhash" || arg == "gethash") - { - string arg2 = GetArgument.Run(2, false, true, message); - if (string.IsNullOrEmpty(arg2)) - { + switch (arg) + { + case "location": + case "getlocation": + player.SendChatMessage("Your location: " + shPlayer.GetPosition()); + break; + case "getplayerhash": + case "gethash": + { + string arg2 = GetArgument.Run(2, false, true, message); + if (string.IsNullOrEmpty(arg2)) + { - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, "Invalid arguments. /debug get(player)hash [username]"); - return; - } - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, "Hash of " + arg2 + " : " + Animator.StringToHash(arg2)); - } - else if (arg == "spaceindex" || arg == "getspaceindex") - { - string arg2 = GetArgument.Run(2, false, true, message); - if (string.IsNullOrEmpty(arg2)) - { - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, "Your SpaceIndex: " + shPlayer.GetPlaceIndex()); - return; - } - var argshPlayer = GetShByStr.Run(arg2); - if (argshPlayer == null) - { - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, NotFoundOnline); - return; - } - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, "SpaceIndex of '" + argshPlayer.svPlayer.playerData.username + "': " + argshPlayer.GetPlaceIndex()); - } - else if (arg == "createidlist") - { - string arg2 = GetArgument.Run(2, false, true, message); - if (string.IsNullOrEmpty(arg2)) - { - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, "Please select idlist type: /debug createidlist item/vehicle/skinid"); - return; - } - arg2 = arg2.Trim().ToLower(); - if (arg2 != "item" && arg2 != "vehicle" && arg2 != "skinid") - { - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, "Please select idlist type: /debug createidlist item/vehicle/skinid (Invalid value given as second arument)"); - return; - } - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, "Creating ID list.. please wait"); - var location = $"{FileDirectory}IDLists/{arg2}/IDLIST_{DateTime.Now.ToString("yyyy_mm_dd_hh_mm_ss")}.txt"; - if (!Directory.Exists($"{FileDirectory}IDLists/{arg2}")) - Directory.CreateDirectory($"{FileDirectory}IDLists/{arg2}"); - var sb = new StringBuilder(); - int currIndex = 1; - sb.Append("{\"items\": ["); - if (arg2 == "skinid") - { - for (int i = 0; i < shPlayer.manager.skinPrefabs.Length; i++) - { - sb.Append($"{{\"name\": \"{shPlayer.manager.skinPrefabs[i].name}\",\"id\": {currIndex},\"gameid\": {Animator.StringToHash(shPlayer.manager.skinPrefabs[i].name)}}},\n"); - ++currIndex; - } - } - else - { - foreach (var entity in shPlayer.manager.entities) - { - switch (arg2) - { - case "item": - if (entity != null && entity is ShItem) - sb.Append($"{{\"name\": \"{entity.name}\",\"id\": {++currIndex},\"gameid\": {entity.index}}},\n"); - break; - case "vehicle": - if (entity != null && entity is ShVehicle) - sb.Append($"{{\"name\": \"{entity.name}\",\"id\": {++currIndex},\"gameid\": {entity.index}}},\n"); - break; - default: - break; - } - } - } - File.WriteAllText(location, $"{sb.Remove(sb.Length - 2, 1)}]}}"); + player.SendChatMessage("Invalid arguments. /debug get(player)hash [username]"); + return; + } + player.SendChatMessage("Hash of " + arg2 + " : " + Animator.StringToHash(arg2)); + break; + } - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"Success! ID List has been saved in {location}. ({currIndex} entries.)"); - } - else if (arg == "jobarray") - { - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"Jobs array: (Length: {Jobs.Length}) {string.Join(", ", Jobs)}"); - } - else if (arg == "tpall") - { - foreach (var currPlayer in UnityEngine.Object.FindObjectsOfType()) - currPlayer.SvReset(shPlayer.GetPosition(), shPlayer.GetRotation(), shPlayer.GetPlaceIndex()); - } - else if (arg == "addcrimes") - { - player.SvAddCrime(CrimeIndex.Murder, null); - } - else - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, "/debug location/getplayerhash/getspaceindex/createidlist/jobarray"); - } + case "spaceindex": + case "getspaceindex": + { + string arg2 = GetArgument.Run(2, false, true, message); + if (string.IsNullOrEmpty(arg2)) + { + player.SendChatMessage("Your SpaceIndex: " + shPlayer.GetPlaceIndex()); + return; + } + var argshPlayer = GetShByStr.Run(arg2); + if (argshPlayer == null) + { + player.SendChatMessage(NotFoundOnline); + return; + } + player.SendChatMessage("SpaceIndex of '" + argshPlayer.svPlayer.playerData.username + "': " + argshPlayer.GetPlaceIndex()); + break; + } + + case "createidlist": + { + string arg2 = GetArgument.Run(2, false, true, message); + if (string.IsNullOrEmpty(arg2)) + { + player.SendChatMessage("Please select idlist type: /debug createidlist item/vehicle/skinid"); + return; + } + arg2 = arg2.Trim().ToLower(); + if (arg2 != "item" && arg2 != "vehicle" && arg2 != "skinid") + { + player.SendChatMessage("Please select idlist type: /debug createidlist item/vehicle/skinid (Invalid value given as second arument)"); + return; + } + player.SendChatMessage("Creating ID list.. please wait"); + var location = $"{FileDirectory}IDLists/{arg2}/IDLIST_{DateTime.Now.ToString("yyyy_mm_dd_hh_mm_ss")}.txt"; + if (!Directory.Exists($"{FileDirectory}IDLists/{arg2}")) + Directory.CreateDirectory($"{FileDirectory}IDLists/{arg2}"); + var sb = new StringBuilder(); + int currIndex = 0; + sb.Append("{\"items\": ["); + if (arg2 == "skinid") + { + for (int i = 0; i < shPlayer.manager.skinPrefabs.Length; i++) + { + sb.Append($"{{\"name\": \"{shPlayer.manager.skinPrefabs[i].name}\",\"id\": {currIndex},\"gameid\": {Animator.StringToHash(shPlayer.manager.skinPrefabs[i].name)}}},\n"); + ++currIndex; + } + } + else + { + var itemsAdded = new List(); + foreach (var entity in Builder.pb_Scene.instance.entityCollection) + { + if (entity == null) + continue; + if (((arg2 == "item" && entity is ShItem) || (arg2 == "vehicle" && entity is ShTransport && !(entity is ShParachute))) && !itemsAdded.Contains(entity.index)) + { + sb.Append($"{{\"name\": \"{entity.name.Replace("(Clone)", "")}\",\"id\": {++currIndex},\"gameid\": {entity.index}}},\n"); + itemsAdded.Add(entity.index); + } + } + } + File.WriteAllText(location, $"{sb.Remove(sb.Length - 2, 1)}]}}"); + + player.SendChatMessage($"Success! ID List has been saved in {location}. ({currIndex} entries.)"); + break; + } + + case "jobarray": + player.SendChatMessage($"Jobs array: (Length: {Jobs.Length}) {string.Join(", ", Jobs)}"); + break; + case "tpall": + { + foreach (var currPlayer in UnityEngine.Object.FindObjectsOfType()) + currPlayer.ResetAndSavePosition(shPlayer.GetPosition(), shPlayer.GetRotation(), shPlayer.GetPlaceIndex()); + break; + } + + case "addcrimes": + player.SvAddCrime(CrimeIndex.Murder, null); + break; + + case "disconnecttest": + player.Send(SvSendType.AllOthers, Channel.Unsequenced, ClPacket.DestroyEntity, player.player.ID); + break; + case "setmaxapartmententities": + player.entity.manager.apartmentLimit = 300; + player.SendChatMessage("success"); + break; + case "getmaxapartmententities": + player.SendChatMessage($"Max entities: {player.entity.manager.apartmentLimit}"); + break; + default: + player.SendChatMessage("/debug location/getplayerhash/getspaceindex/createidlist/jobarray"); + break; + } + } } } \ No newline at end of file diff --git a/source/BP-Essentials/Chat/Commands/Admin/DeleteKit.cs b/source/BP-Essentials/Chat/Commands/Admin/DeleteKit.cs index c5b4644e..72d6e6f1 100644 --- a/source/BP-Essentials/Chat/Commands/Admin/DeleteKit.cs +++ b/source/BP-Essentials/Chat/Commands/Admin/DeleteKit.cs @@ -1,6 +1,6 @@ -using static BP_Essentials.EssentialsVariablesPlugin; +using static BP_Essentials.Variables; using System; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.HookMethods; using System.IO; using System.Collections.Generic; using Newtonsoft.Json; @@ -14,17 +14,17 @@ public static void Run(SvPlayer player, string message) var arg1 = GetArgument.Run(1, false, true, message); if (string.IsNullOrEmpty(arg1.Trim())) { - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, ArgRequired); + player.SendChatMessage(ArgRequired); return; } var file = Path.Combine(KitDirectory, $"{arg1}.json"); if (!File.Exists(file)) { - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"No kits exist with that name."); + player.SendChatMessage($"No kits exist with that name."); return; } - Kits.DeleteKit(player, file, arg1); - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"Kit deleted."); + Variables.WarpHandler.DeleteExisting(arg1); + player.SendChatMessage($"Kit deleted."); } } } \ No newline at end of file diff --git a/source/BP-Essentials/Chat/Commands/Admin/DeleteWarp.cs b/source/BP-Essentials/Chat/Commands/Admin/DeleteWarp.cs index eb82e26b..936bdbae 100644 --- a/source/BP-Essentials/Chat/Commands/Admin/DeleteWarp.cs +++ b/source/BP-Essentials/Chat/Commands/Admin/DeleteWarp.cs @@ -1,6 +1,6 @@ -using static BP_Essentials.EssentialsVariablesPlugin; +using static BP_Essentials.Variables; using System; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.HookMethods; using System.IO; using System.Collections.Generic; using Newtonsoft.Json; @@ -14,17 +14,17 @@ public static void Run(SvPlayer player, string message) var arg1 = GetArgument.Run(1, false, true, message); if (string.IsNullOrEmpty(arg1.Trim())) { - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, ArgRequired); + player.SendChatMessage(ArgRequired); return; } var file = Path.Combine(WarpDirectory, $"{arg1}.json"); if (!File.Exists(file)) { - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"No warps exist with that name."); + player.SendChatMessage($"No warps exist with that name."); return; } - Warps.DeleteWarp(player, file, arg1); - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"Warp deleted."); + Variables.WarpHandler.DeleteExisting(arg1); + player.SendChatMessage($"Warp deleted."); } } } \ No newline at end of file diff --git a/source/BP-Essentials/Chat/Commands/Admin/Disconnect.cs b/source/BP-Essentials/Chat/Commands/Admin/Disconnect.cs index 7655ddde..aa12ca8c 100644 --- a/source/BP-Essentials/Chat/Commands/Admin/Disconnect.cs +++ b/source/BP-Essentials/Chat/Commands/Admin/Disconnect.cs @@ -3,8 +3,8 @@ using System.Linq; using System.Text; using UnityEngine; -using static BP_Essentials.EssentialsVariablesPlugin; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.Variables; +using static BP_Essentials.HookMethods; namespace BP_Essentials.Commands { @@ -15,17 +15,17 @@ public static void Run(SvPlayer player, string message) string arg1 = GetArgument.Run(1, false, true, message); if (string.IsNullOrEmpty(arg1)) { - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, ArgRequired); + player.SendChatMessage(ArgRequired); return; } - var shPlayer = GetShByStr.Run(arg1); - if (shPlayer == null) + var currPlayer = GetShByStr.Run(arg1); + if (currPlayer == null) { - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, NotFoundOnline); + player.SendChatMessage(NotFoundOnline); return; } - player.svManager.Disconnect(shPlayer.svPlayer.connection); - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"Disconnected {shPlayer.username}."); + player.svManager.Disconnect(currPlayer.svPlayer.connection, DisconnectTypes.Normal); + player.SendChatMessage($"Disconnected {currPlayer.username}."); } } } diff --git a/source/BP-Essentials/Chat/Commands/Admin/FakeJoin.cs b/source/BP-Essentials/Chat/Commands/Admin/FakeJoin.cs index 9dacea59..52f0e84f 100644 --- a/source/BP-Essentials/Chat/Commands/Admin/FakeJoin.cs +++ b/source/BP-Essentials/Chat/Commands/Admin/FakeJoin.cs @@ -3,20 +3,22 @@ using System.Linq; using System.Text; using UnityEngine; -using static BP_Essentials.EssentialsVariablesPlugin; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.Variables; +using static BP_Essentials.HookMethods; namespace BP_Essentials.Commands { class FakeJoin { - public static void Run(SvPlayer player, string message) - { - string arg1 = GetArgument.Run(1, false, true, message); - if (!String.IsNullOrEmpty(arg1)) - player.Send(SvSendType.All, Channel.Unsequenced, ClPacket.GameMessage, arg1 + " connected"); - else - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, ArgRequired); - } + public static void Run(SvPlayer player, string message) + { + string arg1 = GetArgument.Run(1, false, true, message); + if (string.IsNullOrEmpty(arg1)) + { + player.SendChatMessage(ArgRequired); + return; + } + player.Send(SvSendType.All, Channel.Unsequenced, ClPacket.GameMessage, arg1 + " connected"); + } } } diff --git a/source/BP-Essentials/Chat/Commands/Admin/FakeLeave.cs b/source/BP-Essentials/Chat/Commands/Admin/FakeLeave.cs index 4d14ce56..e28768fa 100644 --- a/source/BP-Essentials/Chat/Commands/Admin/FakeLeave.cs +++ b/source/BP-Essentials/Chat/Commands/Admin/FakeLeave.cs @@ -3,20 +3,22 @@ using System.Linq; using System.Text; using UnityEngine; -using static BP_Essentials.EssentialsVariablesPlugin; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.Variables; +using static BP_Essentials.HookMethods; namespace BP_Essentials.Commands { class FakeLeave { - public static void Run(SvPlayer player, string message) - { - string arg1 = GetArgument.Run(1, false, true, message); - if (!String.IsNullOrEmpty(arg1)) - player.Send(SvSendType.All, Channel.Unsequenced, ClPacket.GameMessage, arg1 + " disconnected"); - else - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, ArgRequired); - } + public static void Run(SvPlayer player, string message) + { + string arg1 = GetArgument.Run(1, false, true, message); + if (string.IsNullOrEmpty(arg1)) + { + player.SendChatMessage(ArgRequired); + return; + } + player.Send(SvSendType.All, Channel.Unsequenced, ClPacket.GameMessage, arg1 + " disconnected"); + } } } diff --git a/source/BP-Essentials/Chat/Commands/Admin/Feed.cs b/source/BP-Essentials/Chat/Commands/Admin/Feed.cs index 34e3b1f5..803890d7 100644 --- a/source/BP-Essentials/Chat/Commands/Admin/Feed.cs +++ b/source/BP-Essentials/Chat/Commands/Admin/Feed.cs @@ -3,8 +3,8 @@ using System.Linq; using System.Text; using UnityEngine; -using static BP_Essentials.EssentialsVariablesPlugin; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.Variables; +using static BP_Essentials.HookMethods; namespace BP_Essentials.Commands { @@ -13,26 +13,16 @@ class Feed public static void Run(SvPlayer player, string message) { string arg1 = GetArgument.Run(1, false, true, message); - string msg = $"Maxed stats for " + "{0}" + $"."; - if (String.IsNullOrEmpty(arg1)) - { - player.UpdateStats(100F, 100F, 100F, 100F); - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, String.Format(msg, "yourself")); - } - else - { - bool found = false; - foreach (var shPlayer in UnityEngine.Object.FindObjectsOfType()) - if (shPlayer.username == arg1 || shPlayer.ID.ToString() == arg1.ToString()) - if (!shPlayer.svPlayer.serverside) - { - shPlayer.svPlayer.UpdateStats(100F, 100F, 100F, 100F); - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, String.Format(msg, shPlayer.username)); - found = true; - } - if (!found) - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, NotFoundOnline); - } + if (string.IsNullOrEmpty(arg1)) + arg1 = player.player.username; + var currPlayer = GetShByStr.Run(arg1); + if (currPlayer == null) + { + player.SendChatMessage(NotFoundOnline); + return; + } + currPlayer.RestoreStats(); + player.SendChatMessage($"Maxed stats for {currPlayer.username}."); } } } \ No newline at end of file diff --git a/source/BP-Essentials/Chat/Commands/Admin/Free.cs b/source/BP-Essentials/Chat/Commands/Admin/Free.cs index e8da47a3..0cb6ec80 100644 --- a/source/BP-Essentials/Chat/Commands/Admin/Free.cs +++ b/source/BP-Essentials/Chat/Commands/Admin/Free.cs @@ -3,29 +3,29 @@ using System.Linq; using System.Text; using UnityEngine; -using static BP_Essentials.EssentialsVariablesPlugin; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.Variables; +using static BP_Essentials.HookMethods; namespace BP_Essentials.Commands { class Free { - public static void Run(SvPlayer player, string message) - { - string arg1 = GetArgument.Run(1, false, true, message); - if (!string.IsNullOrEmpty(arg1)) - { - var shPlayer = GetShByStr.Run(arg1); - if (shPlayer == null) - { - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, NotFoundOnline); - return; - } - UnRestrain.Run(shPlayer.svPlayer); - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"Freed " + shPlayer.username + $"."); - } - else - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, ArgRequired); - } + public static void Run(SvPlayer player, string message) + { + string arg1 = GetArgument.Run(1, false, true, message); + if (string.IsNullOrEmpty(arg1)) + { + player.SendChatMessage(ArgRequired); + return; + } + var currPlayer = GetShByStr.Run(arg1); + if (currPlayer == null) + { + player.SendChatMessage(NotFoundOnline); + return; + } + UnRestrain.Run(currPlayer.svPlayer); + player.SendChatMessage($"Freed {currPlayer.username}."); + } } } diff --git a/source/BP-Essentials/Chat/Commands/Admin/GetLogs.cs b/source/BP-Essentials/Chat/Commands/Admin/GetLogs.cs index 934bca54..ae184b12 100644 --- a/source/BP-Essentials/Chat/Commands/Admin/GetLogs.cs +++ b/source/BP-Essentials/Chat/Commands/Admin/GetLogs.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using static BP_Essentials.EssentialsVariablesPlugin; +using static BP_Essentials.Variables; using System.IO; using System.Text.RegularExpressions; using System.Linq; @@ -39,9 +39,9 @@ public static void Run(SvPlayer player, string logFile) {"[MESSAGE]",""}, {"<", "<"/* Escape Rich Text tags*/ } }; - content = "" + new Regex(string.Join("|", replace.Keys.Select(k => Regex.Escape(k)))).Replace(content, m => replace[m.Value]) + ""; - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"WARNING: This is a very unstable command and doesn't work all of the times."); - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"Limited to last 100 messages."); + content = "" + new Regex(string.Join("|", replace.Keys.Select(Regex.Escape))).Replace(content, m => replace[m.Value]) + ""; + player.SendChatMessage($"WARNING: This is a very unstable command and doesn't work all of the times."); + player.SendChatMessage($"Limited to last 100 messages."); player.Send(SvSendType.Self, Channel.Fragmented, ClPacket.ServerInfo, content); } } diff --git a/source/BP-Essentials/Chat/Commands/Admin/Give.cs b/source/BP-Essentials/Chat/Commands/Admin/Give.cs index 5dd08ee8..37ad3da7 100644 --- a/source/BP-Essentials/Chat/Commands/Admin/Give.cs +++ b/source/BP-Essentials/Chat/Commands/Admin/Give.cs @@ -3,40 +3,38 @@ using System.Linq; using System.Text; using UnityEngine; -using static BP_Essentials.EssentialsVariablesPlugin; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.Variables; +using static BP_Essentials.HookMethods; namespace BP_Essentials.Commands { class Give { - public static void Run(SvPlayer player, string message) - { - string arg1 = GetArgument.Run(1, false, false, message); - string arg2 = GetArgument.Run(2, false, false, message); - if (String.IsNullOrEmpty(arg1) || String.IsNullOrEmpty(arg2)) - { - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, ArgRequired); - return; - } - bool Parsed = int.TryParse(arg1, out int arg1int); - Parsed = int.TryParse(arg2, out int arg2int); - if (Parsed) - { - if (arg1int > 0 && arg1int <= IDs_Items.Length) - { - var shPlayer = player.player; - if (arg1.Length > 4) - shPlayer.TransferItem(1, arg1int, arg2int, true); - else - shPlayer.TransferItem(1, IDs_Items[arg1int - 1], arg2int, true); - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"Giving you item ID: {arg1}"); - } - else - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"Error: The ID must be between 1 and {IDs_Items.Length}."); - } - else - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"Error: Is that a valid number you provided as argument?"); - } + public static void Run(SvPlayer player, string message) + { + string arg1 = GetArgument.Run(1, false, false, message); + string arg2 = GetArgument.Run(2, false, false, message); + if (string.IsNullOrEmpty(arg1)) + { + player.SendChatMessage(ArgRequired); + return; + } + if (string.IsNullOrWhiteSpace(arg2)) + arg2 = "1"; + bool parsedSuccessfully = int.TryParse(arg1, out int arg1int); + parsedSuccessfully = int.TryParse(arg2, out int arg2int); + if (!parsedSuccessfully) + { + player.SendChatMessage(NotValidArg); + return; + } + if (arg1int < 0 || arg1int > IDs_Items.Length) + { + player.SendChatMessage($"Error: The ID must be between 1 and {IDs_Items.Length}."); + return; + } + player.player.TransferItem(DeltaInv.AddToMe, IDs_Items[arg1int - 1], arg2int, true); + player.SendChatMessage($"Giving you item ID: {arg1}"); + } } } diff --git a/source/BP-Essentials/Chat/Commands/Admin/GodMode.cs b/source/BP-Essentials/Chat/Commands/Admin/GodMode.cs index ac0b9877..a5c6fd05 100644 --- a/source/BP-Essentials/Chat/Commands/Admin/GodMode.cs +++ b/source/BP-Essentials/Chat/Commands/Admin/GodMode.cs @@ -1,45 +1,36 @@ - -using static BP_Essentials.EssentialsMethodsPlugin; -using static BP_Essentials.EssentialsVariablesPlugin; +using static BP_Essentials.HookMethods; +using static BP_Essentials.Variables; using System; using System.IO; using UnityEngine; -namespace BP_Essentials.Commands { - public class GodMode{ - public static void Run(SvPlayer player, string message) { - { - ReadFile.Run(GodListFile); - string name = GetArgument.Run(1, false, true, message); - string msg = String.Empty; - if (String.IsNullOrEmpty(name)) - { - name = player.playerData.username; - msg = $"Godmode {{0}}."; - } - else - foreach (var shPlayer in UnityEngine.Object.FindObjectsOfType()) - if (shPlayer.username == name && !shPlayer.svPlayer.serverside || shPlayer.ID.ToString() == name && !shPlayer.svPlayer.serverside) - { - name = shPlayer.username; - msg = $"Godmode {{0}} for '{name}'."; - break; - } - - if (GodListPlayers.Contains(name)) - { - RemoveStringFromFile.Run(GodListFile, name); - ReadFile.Run(GodListFile); - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, String.Format(msg, "disabled")); - } - else - { - File.AppendAllText(GodListFile, name + Environment.NewLine); - GodListPlayers.Add(name); - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, String.Format(msg, "enabled")); - } - - } - } - } +namespace BP_Essentials.Commands +{ + public class GodMode + { + public static void Run(SvPlayer player, string message) + { + string arg1 = GetArgument.Run(1, false, true, message); + if (string.IsNullOrEmpty(arg1)) + arg1 = player.player.username; + var currPlayer = GetShByStr.Run(arg1); + if (currPlayer == null) + { + player.SendChatMessage(NotFoundOnline); + return; + } + ReadFile.Run(GodListFile); + var msg = $"Godmode {{0}} for '{arg1}'."; + if (GodListPlayers.Contains(currPlayer.username)) + { + RemoveStringFromFile.Run(GodListFile, currPlayer.username); + ReadFile.Run(GodListFile); + player.SendChatMessage(string.Format(msg, "disabled")); + return; + } + File.AppendAllText(GodListFile, currPlayer.username + Environment.NewLine); + GodListPlayers.Add(currPlayer.username); + player.SendChatMessage(string.Format(msg, "enabled")); + } + } } \ No newline at end of file diff --git a/source/BP-Essentials/Chat/Commands/Admin/Heal.cs b/source/BP-Essentials/Chat/Commands/Admin/Heal.cs index 4c60c4cc..6ebcc7fe 100644 --- a/source/BP-Essentials/Chat/Commands/Admin/Heal.cs +++ b/source/BP-Essentials/Chat/Commands/Admin/Heal.cs @@ -3,8 +3,8 @@ using System.Linq; using System.Text; using UnityEngine; -using static BP_Essentials.EssentialsVariablesPlugin; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.Variables; +using static BP_Essentials.HookMethods; namespace BP_Essentials.Commands { @@ -13,26 +13,16 @@ class Heal public static void Run(SvPlayer player, string message) { string arg1 = GetArgument.Run(1, false, true, message); - string msg = $"Healed {{0}}."; - if (String.IsNullOrEmpty(arg1)) - { - player.Heal(100); - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, String.Format(msg, "yourself")); - } - else - { - bool found = false; - foreach (var shPlayer in UnityEngine.Object.FindObjectsOfType()) - if (shPlayer.username == arg1 || shPlayer.ID.ToString() == arg1.ToString()) - if (!shPlayer.svPlayer.serverside) - { - shPlayer.svPlayer.Heal(100); - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, String.Format(msg, shPlayer.username)); - found = true; - } - if (!found) - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, NotFoundOnline); - } + if (string.IsNullOrEmpty(arg1)) + arg1 = player.player.username; + var currPlayer = GetShByStr.Run(arg1); + if (currPlayer == null) + { + player.SendChatMessage(NotFoundOnline); + return; + } + currPlayer.svPlayer.Heal(100); + player.SendChatMessage($"Healed {currPlayer.username}."); } } } diff --git a/source/BP-Essentials/Chat/Commands/Admin/Info.cs b/source/BP-Essentials/Chat/Commands/Admin/Info.cs index e930b94e..0346a609 100644 --- a/source/BP-Essentials/Chat/Commands/Admin/Info.cs +++ b/source/BP-Essentials/Chat/Commands/Admin/Info.cs @@ -3,50 +3,43 @@ using System.Linq; using System.Text; using UnityEngine; -using static BP_Essentials.EssentialsVariablesPlugin; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.Variables; +using static BP_Essentials.HookMethods; namespace BP_Essentials.Commands { class Info { - public static void Run(SvPlayer player, string message) - { - var arg1 = GetArgument.Run(1, false, true, message); - var found = false; - if (!String.IsNullOrEmpty(arg1)) - { - foreach (var shPlayer in UnityEngine.Object.FindObjectsOfType()) - if (shPlayer.username == arg1 || shPlayer.ID.ToString() == arg1.ToString()) - if (!shPlayer.svPlayer.serverside) - { - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, "Info about: '" + shPlayer.username + "'."); - string[] contentarray = { - "Username: " + shPlayer.username, - "", - "", - "Job: " + Jobs[shPlayer.job.jobIndex], - "Health: " + Math.Floor(shPlayer.health), - "OwnsApartment: " + (bool)shPlayer.ownedApartment, - "Position: " + shPlayer.GetPosition().ToString(), - "WantedLevel: " + shPlayer.wantedLevel, - "IsAdmin: " + shPlayer.admin, - "BankBalance: " + shPlayer.svPlayer.bankBalance, - "ChatEnabled: " + playerList[shPlayer.ID].chatEnabled, - "IP: " + shPlayer.svPlayer.connection.IP - }; - - var content = string.Join("\r\n", contentarray); - - player.Send(SvSendType.Self, Channel.Reliable, ClPacket.ServerInfo, content); - - found = true; - } - if (!(found)) - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, NotFoundOnline); - } - else - player.Send(SvSendType.Self, Channel.Reliable, ClPacket.GameMessage, ArgRequired); - } + public static void Run(SvPlayer player, string message) + { + var arg1 = GetArgument.Run(1, false, true, message); + if (string.IsNullOrEmpty(arg1)) + { + player.Send(SvSendType.Self, Channel.Reliable, ClPacket.GameMessage, ArgRequired); + return; + } + var currPlayer = GetShByStr.Run(arg1); + if (currPlayer == null) + { + player.SendChatMessage(NotFoundOnline); + return; + } + string[] contentarray = { + "Username: " + currPlayer.username, + "", + "", + "Job: " + Jobs[currPlayer.job.jobIndex], + "Health: " + Math.Floor(currPlayer.health), + "OwnsApartment: " + (bool)currPlayer.ownedApartment, + "Position: " + currPlayer.GetPosition().ToString(), + "WantedLevel: " + currPlayer.wantedLevel, + "IsAdmin: " + currPlayer.admin, + "BankBalance: " + currPlayer.svPlayer.bankBalance, + "ChatEnabled: " + PlayerList[currPlayer.ID].ChatEnabled, + "IP: " + currPlayer.svPlayer.connection.IP + }; + var content = string.Join("\r\n", contentarray); + player.Send(SvSendType.Self, Channel.Reliable, ClPacket.ServerInfo, content); + } } } diff --git a/source/BP-Essentials/Chat/Commands/Admin/Jail.cs b/source/BP-Essentials/Chat/Commands/Admin/Jail.cs index 6d8d404f..c4042725 100644 --- a/source/BP-Essentials/Chat/Commands/Admin/Jail.cs +++ b/source/BP-Essentials/Chat/Commands/Admin/Jail.cs @@ -3,8 +3,8 @@ using System.Linq; using System.Text; using UnityEngine; -using static BP_Essentials.EssentialsVariablesPlugin; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.Variables; +using static BP_Essentials.HookMethods; namespace BP_Essentials.Commands { @@ -15,28 +15,28 @@ public static void Run(SvPlayer player, string message) string arg1 = GetArgument.Run(1, false, true, message); if (string.IsNullOrEmpty(arg1)) { - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, ArgRequired); + player.SendChatMessage(ArgRequired); return; } - arg1 = arg1.Remove(arg1.LastIndexOf(" ")).Trim(); + arg1 = arg1.Remove(arg1.LastIndexOf(" ", StringComparison.CurrentCulture)).Trim(); var shPlayer = GetShByStr.Run(arg1); if (shPlayer == null) { - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, NotFoundOnline); + player.SendChatMessage(NotFoundOnline); return; } - if (!float.TryParse(message.Split(' ').Last().Trim(), out float t)) + if (!float.TryParse(message.Split(' ').Last().Trim(), out float time)) { - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, ArgRequired); + player.SendChatMessage(ArgRequired); return; } - if (!SendToJail.Run(shPlayer, t)) + if (!SendToJail.Run(shPlayer, time)) { - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"Cannot send {shPlayer.username} To jail."); + player.SendChatMessage($"Cannot send {shPlayer.username} To jail."); return; } - shPlayer.svPlayer.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"{player.player.username} sent you to jail."); - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"Sent {shPlayer.username} To jail."); + shPlayer.svPlayer.SendChatMessage($"{player.player.username} sent you to jail."); + player.SendChatMessage($"Sent {shPlayer.username} To jail."); } } } diff --git a/source/BP-Essentials/Chat/Commands/Admin/Kick.cs b/source/BP-Essentials/Chat/Commands/Admin/Kick.cs index d5ad1312..68718c93 100644 --- a/source/BP-Essentials/Chat/Commands/Admin/Kick.cs +++ b/source/BP-Essentials/Chat/Commands/Admin/Kick.cs @@ -3,8 +3,8 @@ using System.Linq; using System.Text; using UnityEngine; -using static BP_Essentials.EssentialsVariablesPlugin; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.Variables; +using static BP_Essentials.HookMethods; namespace BP_Essentials.Commands { @@ -15,17 +15,17 @@ public static void Run(SvPlayer player, string message) string arg1 = GetArgument.Run(1, false, true, message); if (string.IsNullOrEmpty(arg1)) { - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, ArgRequired); + player.SendChatMessage(ArgRequired); return; } var shPlayer = GetShByStr.Run(arg1); if (shPlayer == null) { - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, NotFoundOnline); + player.SendChatMessage(NotFoundOnline); return; } player.svManager.Kick(shPlayer.svPlayer.connection); - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"Kicked " + shPlayer.username + $"."); + player.SendChatMessage($"Kicked {shPlayer.username}."); } } } diff --git a/source/BP-Essentials/Chat/Commands/Admin/Kill.cs b/source/BP-Essentials/Chat/Commands/Admin/Kill.cs index 19aae821..f5fffd03 100644 --- a/source/BP-Essentials/Chat/Commands/Admin/Kill.cs +++ b/source/BP-Essentials/Chat/Commands/Admin/Kill.cs @@ -3,29 +3,29 @@ using System.Linq; using System.Text; using UnityEngine; -using static BP_Essentials.EssentialsVariablesPlugin; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.Variables; +using static BP_Essentials.HookMethods; namespace BP_Essentials.Commands { class Kill { - public static void Run(SvPlayer player, string message) - { - string arg1 = GetArgument.Run(1, false, true, message); - if (!string.IsNullOrEmpty(arg1)) - { - var shPlayer = GetShByStr.Run(arg1); - if (shPlayer == null) - { - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, NotFoundOnline); - return; - } - shPlayer.svPlayer.SvSuicide(); - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"Killed " + shPlayer.username + $"."); - } - else - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, ArgRequired); - } + public static void Run(SvPlayer player, string message) + { + string arg1 = GetArgument.Run(1, false, true, message); + if (string.IsNullOrEmpty(arg1)) + { + player.SendChatMessage(ArgRequired); + return; + } + var currPlayer = GetShByStr.Run(arg1); + if (currPlayer == null) + { + player.SendChatMessage(NotFoundOnline); + return; + } + currPlayer.svPlayer.SvSuicide(); + player.SendChatMessage($"Killed {currPlayer.username}."); + } } } diff --git a/source/BP-Essentials/Chat/Commands/Admin/Knockout.cs b/source/BP-Essentials/Chat/Commands/Admin/Knockout.cs index 2f099402..069577fe 100644 --- a/source/BP-Essentials/Chat/Commands/Admin/Knockout.cs +++ b/source/BP-Essentials/Chat/Commands/Admin/Knockout.cs @@ -3,29 +3,29 @@ using System.Linq; using System.Text; using UnityEngine; -using static BP_Essentials.EssentialsVariablesPlugin; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.Variables; +using static BP_Essentials.HookMethods; namespace BP_Essentials.Commands { class Knockout { - public static void Run(SvPlayer player, string message) - { - string arg1 = GetArgument.Run(1, false, true, message); - if (!string.IsNullOrEmpty(arg1)) - { - var shPlayer = GetShByStr.Run(arg1); - if (shPlayer == null) - { - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, NotFoundOnline); - return; - } - shPlayer.svPlayer.SvForceStance(StanceIndex.KnockedOut); - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"Knocked out {shPlayer.username}."); - } - else - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, ArgRequired); - } + public static void Run(SvPlayer player, string message) + { + string arg1 = GetArgument.Run(1, false, true, message); + if (string.IsNullOrEmpty(arg1)) + { + player.SendChatMessage(ArgRequired); + return; + } + var currPlayer = GetShByStr.Run(arg1); + if (currPlayer == null) + { + player.SendChatMessage(NotFoundOnline); + return; + } + currPlayer.svPlayer.SvForceStance(StanceIndex.KnockedOut); + player.SendChatMessage($"Knocked out {currPlayer.username}."); + } } } diff --git a/source/BP-Essentials/Chat/Commands/Admin/LatestVoteResults.cs b/source/BP-Essentials/Chat/Commands/Admin/LatestVoteResults.cs index 57d78913..8dde3216 100644 --- a/source/BP-Essentials/Chat/Commands/Admin/LatestVoteResults.cs +++ b/source/BP-Essentials/Chat/Commands/Admin/LatestVoteResults.cs @@ -3,22 +3,22 @@ using System.Linq; using System.Text; using UnityEngine; -using static BP_Essentials.EssentialsVariablesPlugin; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.Variables; +using static BP_Essentials.HookMethods; namespace BP_Essentials.Commands { class LatestVoteResults { - public static void Run(SvPlayer player, string message) - { - if (!LatestVotePeople.Any()) - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"The list seems empty."); - else - { - string content = string.Join("\r\n", LatestVotePeople.ToArray()); - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.ServerInfo, "\r\nPlayers that voted 'yes' on the latest votekick: \r\n\r\n" + content); - } - } + public static void Run(SvPlayer player, string message) + { + if (!LatestVotePeople.Any()) + { + player.SendChatMessage($"The list seems empty."); + return; + } + string content = string.Join("\r\n", LatestVotePeople); + player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.ServerInfo, "\r\nPlayers that voted 'yes' on the latest votekick: \r\n\r\n" + content); + } } } diff --git a/source/BP-Essentials/Chat/Commands/Admin/Launch.cs b/source/BP-Essentials/Chat/Commands/Admin/Launch.cs index 824cc8f7..6d285037 100644 --- a/source/BP-Essentials/Chat/Commands/Admin/Launch.cs +++ b/source/BP-Essentials/Chat/Commands/Admin/Launch.cs @@ -3,8 +3,8 @@ using System.Linq; using System.Text; using UnityEngine; -using static BP_Essentials.EssentialsVariablesPlugin; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.Variables; +using static BP_Essentials.HookMethods; namespace BP_Essentials.Commands { @@ -12,23 +12,21 @@ class Launch { public static void Run(SvPlayer player, string message) { - string arg1 = GetArgument.Run(1, false, true, message); - if (String.IsNullOrEmpty(arg1)) - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, ArgRequired); - else - { - bool playerfound = false; - foreach (var shPlayer in UnityEngine.Object.FindObjectsOfType()) - if (shPlayer.username == arg1 && !shPlayer.svPlayer.serverside || shPlayer.ID.ToString() == arg1 && !shPlayer.svPlayer.serverside) - { - shPlayer.svPlayer.SvForce(new Vector3(0f, 6500f, 0f)); - shPlayer.svPlayer.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"Off you go!"); - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"You've launched {shPlayer.username} into space!"); - playerfound = true; - } - if (!playerfound) - player.Send(SvSendType.Self, Channel.Reliable, ClPacket.GameMessage, NotFoundOnline); - } + string arg1 = GetArgument.Run(1, false, true, message); + if (string.IsNullOrEmpty(arg1)) + { + player.SendChatMessage(ArgRequired); + return; + } + var currPlayer = GetShByStr.Run(arg1); + if (currPlayer == null) + { + player.SendChatMessage(NotFoundOnline); + return; + } + currPlayer.svPlayer.SvForce(new Vector3(0f, 6500f, 0f)); + currPlayer.svPlayer.SendChatMessage($"Off you go!"); + player.SendChatMessage($"You've launched {currPlayer.username} into space!"); } } } diff --git a/source/BP-Essentials/Chat/Commands/Admin/Money.cs b/source/BP-Essentials/Chat/Commands/Admin/Money.cs index 39398582..d8ce7a33 100644 --- a/source/BP-Essentials/Chat/Commands/Admin/Money.cs +++ b/source/BP-Essentials/Chat/Commands/Admin/Money.cs @@ -3,46 +3,41 @@ using System.Linq; using System.Text; using UnityEngine; -using static BP_Essentials.EssentialsVariablesPlugin; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.Variables; +using static BP_Essentials.HookMethods; namespace BP_Essentials.Commands { - class Money - { - public static void Run(SvPlayer player, string message) - { - string CorrSyntax = $"" + GetArgument.Run(0, false, false, message) + $" [Player] [Amount] (Incorrect or missing argument(s).)"; - string arg1 = GetArgument.Run(1, false, true, message); - string arg2 = message.Split(' ').Last().Trim(); - if (String.IsNullOrEmpty(arg1) || String.IsNullOrEmpty(arg2)) - { - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, CorrSyntax); - return; - } - else - { - int lastIndex = arg1.LastIndexOf(" "); - if (lastIndex != -1) - arg1 = arg1.Remove(lastIndex).Trim(); - } - bool isNumeric = int.TryParse(arg2, out int arg2int); - if (isNumeric) - { - bool found = false; - foreach (var shPlayer in UnityEngine.Object.FindObjectsOfType()) - if (shPlayer.username == arg1 && !shPlayer.svPlayer.serverside || shPlayer.ID.ToString() == arg1 && !shPlayer.svPlayer.serverside) - { - shPlayer.TransferMoney(DeltaInv.AddToMe, arg2int, true); - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"Successfully gave " + shPlayer.username + " " + arg2int + $"$"); - shPlayer.svPlayer.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"" + player.playerData.username + $" gave you " + arg2int + $"$!"); - found = true; - } - if (!found) - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, NotFoundOnline); - } - else - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, CorrSyntax); - } - } + class Money + { + public static void Run(SvPlayer player, string message) + { + string arg1 = GetArgument.Run(1, false, true, message); + string arg2 = message.Split(' ').Last().Trim(); + string correctSyntax = $"{GetArgument.Run(0, false, false, message)} [Player] [Amount] (Incorrect or missing argument(s).)"; + if (string.IsNullOrEmpty(arg1) || string.IsNullOrEmpty(arg2)) + { + player.SendChatMessage(correctSyntax); + return; + } + int lastIndex = arg1.LastIndexOf(" ", StringComparison.CurrentCulture); + if (lastIndex != -1) + arg1 = arg1.Remove(lastIndex).Trim(); + bool parsedSuccessfully = int.TryParse(arg2, out var arg2int); + if (!parsedSuccessfully) + { + player.SendChatMessage(correctSyntax); + return; + } + var currPlayer = GetShByStr.Run(arg1); + if (currPlayer == null) + { + player.SendChatMessage(NotFoundOnline); + return; + } + currPlayer.TransferMoney(DeltaInv.AddToMe, arg2int, true); + player.SendChatMessage($"Successfully gave {currPlayer.username} {arg2int}$"); + currPlayer.svPlayer.SendChatMessage($"{player.player.username} gave you {arg2int}$!"); + } + } } diff --git a/source/BP-Essentials/Chat/Commands/Admin/Mute.cs b/source/BP-Essentials/Chat/Commands/Admin/Mute.cs index 078a00f7..b1d80a8c 100644 --- a/source/BP-Essentials/Chat/Commands/Admin/Mute.cs +++ b/source/BP-Essentials/Chat/Commands/Admin/Mute.cs @@ -3,45 +3,39 @@ using System.Linq; using System.Text; using UnityEngine; -using static BP_Essentials.EssentialsVariablesPlugin; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.Variables; +using static BP_Essentials.HookMethods; using System.IO; namespace BP_Essentials.Commands { - class Mute - { - public static void Run(SvPlayer player, string message) - { - string muteuser = null; - var found = false; - muteuser = GetArgument.Run(1, false, true, message); - foreach (var shPlayer in UnityEngine.Object.FindObjectsOfType()) - if (shPlayer.username == muteuser.ToString() || shPlayer.ID.ToString() == muteuser.ToString()) - if (!shPlayer.svPlayer.serverside) - { - muteuser = shPlayer.username; - found = true; - } - if (!found) - { - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, NotFoundOnline); - return; - } - ReadFile.Run(MuteListFile); - if (!MutePlayers.Contains(muteuser)) - { - MutePlayers.Add(muteuser); - File.AppendAllText(MuteListFile, muteuser + Environment.NewLine); - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"Muted " + muteuser + ""); - - } - else - { - RemoveStringFromFile.Run(MuteListFile, muteuser); - ReadFile.Run(MuteListFile); - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"Unmuted " + muteuser + ""); - } - } - } + class Mute + { + public static void Run(SvPlayer player, string message) + { + string arg1 = GetArgument.Run(1, false, true, message); + if (string.IsNullOrEmpty(arg1)) + { + player.SendChatMessage(ArgRequired); + return; + } + var currPlayer = GetShByStr.Run(arg1); + if (currPlayer == null) + { + player.SendChatMessage(NotFoundOnline); + return; + } + ReadFile.Run(MuteListFile); + if (!MutePlayers.Contains(currPlayer.username)) + { + MutePlayers.Add(currPlayer.username); + File.AppendAllText(MuteListFile, currPlayer.username + Environment.NewLine); + player.SendChatMessage($"Muted {currPlayer.username}."); + return; + } + RemoveStringFromFile.Run(MuteListFile, currPlayer.username); + ReadFile.Run(MuteListFile); + player.SendChatMessage($"Unmuted {currPlayer.username}."); + } + } } diff --git a/source/BP-Essentials/Chat/Commands/Admin/Promote.cs b/source/BP-Essentials/Chat/Commands/Admin/Promote.cs index 76c0214a..5ef8e0f0 100644 --- a/source/BP-Essentials/Chat/Commands/Admin/Promote.cs +++ b/source/BP-Essentials/Chat/Commands/Admin/Promote.cs @@ -1,31 +1,31 @@ using System; using System.Collections.Generic; -using static BP_Essentials.EssentialsVariablesPlugin; +using static BP_Essentials.Variables; namespace BP_Essentials.Commands { public class Promote { - public static void Run(SvPlayer player, string message) - { - string arg1 = GetArgument.Run(1, false, true, message); - if (!string.IsNullOrEmpty(arg1)) - { - var shPlayer = GetShByStr.Run(arg1); - if (shPlayer == null) - { - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, NotFoundOnline); - return; - } - if (shPlayer.rank >= 2) - { - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"{shPlayer.username} Already has the highest rank!"); - return; - } - shPlayer.svPlayer.Reward(shPlayer.maxExperience - shPlayer.experience + 1, 0); - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"Promoted {shPlayer.username} to rank {shPlayer.rank +1}."); - } - else - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, ArgRequired); - } + public static void Run(SvPlayer player, string message) + { + string arg1 = GetArgument.Run(1, false, true, message); + if (string.IsNullOrEmpty(arg1)) + { + player.SendChatMessage(ArgRequired); + return; + } + var currPlayer = GetShByStr.Run(arg1); + if (currPlayer == null) + { + player.SendChatMessage(NotFoundOnline); + return; + } + if (currPlayer.rank >= 2) + { + player.SendChatMessage($"{currPlayer.username} Already has the highest rank!"); + return; + } + currPlayer.svPlayer.Reward(currPlayer.maxExperience - currPlayer.experience + 1, 0); + player.SendChatMessage($"Promoted {currPlayer.username} to rank {currPlayer.rank + 1}."); + } } } \ No newline at end of file diff --git a/source/BP-Essentials/Chat/Commands/Admin/Reload.cs b/source/BP-Essentials/Chat/Commands/Admin/Reload.cs index 7b381159..4e7e0224 100644 --- a/source/BP-Essentials/Chat/Commands/Admin/Reload.cs +++ b/source/BP-Essentials/Chat/Commands/Admin/Reload.cs @@ -3,8 +3,8 @@ using System.Linq; using System.Text; using UnityEngine; -using static BP_Essentials.EssentialsVariablesPlugin; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.Variables; +using static BP_Essentials.HookMethods; namespace BP_Essentials.Commands { diff --git a/source/BP-Essentials/Chat/Commands/Admin/RepairVehicle.cs b/source/BP-Essentials/Chat/Commands/Admin/RepairVehicle.cs new file mode 100644 index 00000000..5d481465 --- /dev/null +++ b/source/BP-Essentials/Chat/Commands/Admin/RepairVehicle.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using UnityEngine; +using static BP_Essentials.Variables; +using static BP_Essentials.HookMethods; + +namespace BP_Essentials.Commands +{ + class RepairVehicle + { + public static void Run(SvPlayer player, string message) + { + var vehicle = player.player.curMount as ShTransport; + if (!player.player.curMount || vehicle == null) + { + player.SendChatMessage($"You must be in a vehicle to execute this command."); + return; + } + vehicle.RestoreStats(); + player.SendChatMessage($"Your vehicle has been repaired."); + } + } +} diff --git a/source/BP-Essentials/Chat/Commands/Admin/Restrain.cs b/source/BP-Essentials/Chat/Commands/Admin/Restrain.cs index ffd9212d..438bca2f 100644 --- a/source/BP-Essentials/Chat/Commands/Admin/Restrain.cs +++ b/source/BP-Essentials/Chat/Commands/Admin/Restrain.cs @@ -3,33 +3,33 @@ using System.Linq; using System.Text; using UnityEngine; -using static BP_Essentials.EssentialsVariablesPlugin; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.Variables; +using static BP_Essentials.HookMethods; namespace BP_Essentials.Commands { class Restrain { - public static void Run(SvPlayer player, string message) - { - string arg1 = GetArgument.Run(1, false, true, message); - if (!string.IsNullOrEmpty(arg1)) - { - var shPlayer = GetShByStr.Run(arg1); - if (shPlayer == null) - { - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, NotFoundOnline); - return; - } - shPlayer.svPlayer.Restrain(shPlayer.manager.handcuffed); - var shRetained = shPlayer.curEquipable as ShRestrained; - shPlayer.svPlayer.SvSetEquipable(shRetained.otherRestrained.index); - if (!shPlayer.svPlayer.serverside) - shPlayer.svPlayer.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, "You've been restrained"); - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"Restrained " + shPlayer.username + $"."); - } - else - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, ArgRequired); - } + public static void Run(SvPlayer player, string message) + { + string arg1 = GetArgument.Run(1, false, true, message); + if (string.IsNullOrEmpty(arg1)) + { + player.SendChatMessage(ArgRequired); + return; + } + var currPlayer = GetShByStr.Run(arg1); + if (currPlayer == null) + { + player.SendChatMessage(NotFoundOnline); + return; + } + currPlayer.svPlayer.Restrain(currPlayer.manager.handcuffed); + var shRetained = currPlayer.curEquipable as ShRestrained; + currPlayer.svPlayer.SvSetEquipable(shRetained.otherRestrained.index); + if (!currPlayer.svPlayer.serverside) + currPlayer.svPlayer.SendChatMessage("You've been restrained"); + player.SendChatMessage($"Restrained {currPlayer.username}."); + } } } diff --git a/source/BP-Essentials/Chat/Commands/Admin/Say.cs b/source/BP-Essentials/Chat/Commands/Admin/Say.cs index 2bfe3e50..cb1e8b1f 100644 --- a/source/BP-Essentials/Chat/Commands/Admin/Say.cs +++ b/source/BP-Essentials/Chat/Commands/Admin/Say.cs @@ -3,24 +3,23 @@ using System.Linq; using System.Text; using UnityEngine; -using static BP_Essentials.EssentialsVariablesPlugin; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.Variables; +using static BP_Essentials.HookMethods; using System.Text.RegularExpressions; namespace BP_Essentials.Commands { - class Say - { - public static void Run(SvPlayer player, string message) - { - string arg1 = GetArgument.Run(1, false, true, message); - if (String.IsNullOrEmpty(arg1)) - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, ArgRequired); - else - { - arg1 = new Regex("(<)").Replace(arg1, "<"); - player.Send(SvSendType.All, Channel.Unsequenced, ClPacket.GameMessage, $"{MsgSayPrefix} {player.playerData.username}: {arg1}"); - } - } - } + class Say + { + public static void Run(SvPlayer player, string message) + { + string arg1 = GetArgument.Run(1, false, true, message); + if (string.IsNullOrEmpty(arg1)) + { + player.SendChatMessage(ArgRequired); + return; + } + player.Send(SvSendType.All, Channel.Unsequenced, ClPacket.GameMessage, $"{MsgSayPrefix} {player.playerData.username}: {arg1.FilterString()}"); + } + } } diff --git a/source/BP-Essentials/Chat/Commands/Admin/Search.cs b/source/BP-Essentials/Chat/Commands/Admin/Search.cs index 3db5a62a..ce7b9437 100644 --- a/source/BP-Essentials/Chat/Commands/Admin/Search.cs +++ b/source/BP-Essentials/Chat/Commands/Admin/Search.cs @@ -3,8 +3,8 @@ using System.Linq; using System.Text; using UnityEngine; -using static BP_Essentials.EssentialsVariablesPlugin; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.Variables; +using static BP_Essentials.HookMethods; namespace BP_Essentials.Commands { @@ -12,34 +12,37 @@ class Search { public static void Run(SvPlayer player, string message) { - string arg1 = GetArgument.Run(1, false, true, message); - if (String.IsNullOrEmpty(arg1)) - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, ArgRequired); - else - { - foreach (var shPlayer2 in UnityEngine.Object.FindObjectsOfType()) - if (shPlayer2.username == arg1 && !shPlayer2.svPlayer.serverside || shPlayer2.ID.ToString() == arg1 && !shPlayer2.svPlayer.serverside) - { - foreach (var shPlayer in UnityEngine.Object.FindObjectsOfType()) - if (shPlayer.svPlayer == player && !shPlayer.svPlayer.serverside) - { - if (!shPlayer2.IsDead()) - { - if (shPlayer2.otherEntity) - shPlayer2.svPlayer.SvStopInventory(true); - shPlayer2.viewers.Add(shPlayer); - shPlayer.otherEntity = shPlayer2; - player.Send(SvSendType.Self, Channel.Fragmented, 13, shPlayer.otherEntity.ID, shPlayer.otherEntity.SerializeMyItems()); - if (!shPlayer2.svPlayer.serverside && shPlayer2.viewers.Count == 1) - shPlayer2.svPlayer.Send(SvSendType.Self, Channel.Reliable, 16, new System.Object[] { }); - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"Viewing inventory of {shPlayer2.username}"); - shPlayer2.svPlayer.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"{AdminSearchingInv}"); - } - else - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"Player is dead."); - } - } - } + string arg1 = GetArgument.Run(1, false, true, message); + if (string.IsNullOrEmpty(arg1)) + { + player.SendChatMessage(ArgRequired); + return; + } + var currPlayer = GetShByStr.Run(arg1); + if (currPlayer == null) + { + player.SendChatMessage(NotFoundOnline); + return; + } + if (currPlayer == player.player) + { + player.SendChatMessage($"You cannot search yourself."); + return; + } + if (currPlayer.IsDead()) + { + player.SendChatMessage($"You cannot search this player because he or she is dead."); + return; + } + if (currPlayer.otherEntity) + currPlayer.svPlayer.SvStopInventory(true); + currPlayer.viewers.Add(player.player); + player.player.otherEntity = currPlayer; + player.Send(SvSendType.Self, Channel.Fragmented, ClPacket.Searching, player.player.otherEntity.ID, player.player.otherEntity.SerializeMyItems()); + if (!currPlayer.svPlayer.serverside && currPlayer.viewers.Count == 1) + currPlayer.svPlayer.Send(SvSendType.Self, Channel.Reliable, ClPacket.ShowSearchedInventory, new object[] { }); + player.SendChatMessage($"Viewing inventory of {currPlayer.username}"); + currPlayer.svPlayer.SendChatMessage(AdminSearchingInv); } } } diff --git a/source/BP-Essentials/Chat/Commands/Admin/Slap.cs b/source/BP-Essentials/Chat/Commands/Admin/Slap.cs index 785281a4..1f335070 100644 --- a/source/BP-Essentials/Chat/Commands/Admin/Slap.cs +++ b/source/BP-Essentials/Chat/Commands/Admin/Slap.cs @@ -3,39 +3,32 @@ using System.Linq; using System.Text; using UnityEngine; -using static BP_Essentials.EssentialsVariablesPlugin; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.Variables; +using static BP_Essentials.HookMethods; namespace BP_Essentials.Commands { class Slap { - public static void Run(SvPlayer player, string message) - { - string arg1 = GetArgument.Run(1, false, true, message); - if (String.IsNullOrEmpty(arg1)) - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, ArgRequired); - else - { - bool playerfound = false; - foreach (var shPlayer in UnityEngine.Object.FindObjectsOfType()) - if (shPlayer.username == arg1 && !shPlayer.svPlayer.serverside || shPlayer.ID.ToString() == arg1 && !shPlayer.svPlayer.serverside) - { - foreach (var shPlayer2 in UnityEngine.Object.FindObjectsOfType()) - if (shPlayer2.svPlayer == player && !shPlayer2.svPlayer.serverside) - { - int amount = new System.Random().Next(4, 15); - shPlayer.svPlayer.Damage(DamageIndex.Null, amount, null, null); - shPlayer.svPlayer.SvForce(new Vector3(500f, 0f, 500f)); - shPlayer.svPlayer.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"You got slapped by {shPlayer2.username}! [-{amount} HP]"); - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"You've slapped {shPlayer.username}. [-{amount} HP]"); - playerfound = true; - } - } - if (!playerfound) - player.Send(SvSendType.Self, Channel.Reliable, ClPacket.GameMessage, NotFoundOnline); - - } - } + public static void Run(SvPlayer player, string message) + { + string arg1 = GetArgument.Run(1, false, true, message); + if (string.IsNullOrEmpty(arg1)) + { + player.SendChatMessage(ArgRequired); + return; + } + var currPlayer = GetShByStr.Run(arg1); + if (currPlayer == null) + { + player.SendChatMessage(NotFoundOnline); + return; + } + int amount = new System.Random().Next(4, 15); + currPlayer.svPlayer.Damage(DamageIndex.Null, amount, null, null); + currPlayer.svPlayer.SvForce(new Vector3(500f, 0f, 500f)); + currPlayer.svPlayer.SendChatMessage($"You got slapped by {player.player.username}! [-{amount} HP]"); + player.SendChatMessage($"You've slapped {currPlayer.username}. [-{amount} HP]"); + } } } diff --git a/source/BP-Essentials/Chat/Commands/Admin/Snap.cs b/source/BP-Essentials/Chat/Commands/Admin/Snap.cs new file mode 100644 index 00000000..ec82e64b --- /dev/null +++ b/source/BP-Essentials/Chat/Commands/Admin/Snap.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using UnityEngine; +using static BP_Essentials.Variables; +using static BP_Essentials.HookMethods; + +namespace BP_Essentials.Commands +{ + // lol + class Snap + { + public static void Run(SvPlayer player, string message) + { + var playersToBePwned = (new System.Random().NextDouble() >= 0.5 ? PlayerList.Take(PlayerList.Count / 2) : PlayerList.Skip(PlayerList.Count / 2)).Select(x => x.Value.ShPlayer).ToList(); + for (int i = 0; i < playersToBePwned.Count; i++) + playersToBePwned[i].svPlayer.SvSuicide(); + player.Send(SvSendType.All, Channel.Unsequenced, ClPacket.GameMessage, $"Perfectly balanced, as all things should be."); + } + } +} diff --git a/source/BP-Essentials/Chat/Commands/Admin/SpawnVehicle.cs b/source/BP-Essentials/Chat/Commands/Admin/SpawnVehicle.cs index 9cc5abdb..aa4d36fb 100644 --- a/source/BP-Essentials/Chat/Commands/Admin/SpawnVehicle.cs +++ b/source/BP-Essentials/Chat/Commands/Admin/SpawnVehicle.cs @@ -3,44 +3,44 @@ using System.Linq; using System.Text; using UnityEngine; -using static BP_Essentials.EssentialsVariablesPlugin; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.Variables; +using static BP_Essentials.HookMethods; namespace BP_Essentials.Commands { - class SpawnVehicle - { - public static void Run(SvPlayer player, string message) - { - string arg1 = GetArgument.Run(1, false, false, message); - if (String.IsNullOrEmpty(arg1)) - { - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, ArgRequired); - return; - } - bool Parsed = int.TryParse(arg1, out int arg1int); - if (Parsed) - { - if (arg1int > 0 && arg1int <= IDs_Vehicles.Length) - { - var shPlayer = player.player; - var pos = shPlayer.GetPosition(); - if (player.player.GetPlaceIndex() != 0) - { - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"Cannot spawn inside a building."); - return; - } - if (arg1.Length > 4) - SvMan.AddNewEntity(ShManager.GetEntity(arg1int), shPlayer.manager.places[0], new Vector3(pos.x, pos.y + 10F, pos.z), shPlayer.GetRotation()); - else - SvMan.AddNewEntity(ShManager.GetEntity(IDs_Vehicles[arg1int - 1]), shPlayer.manager.places[0], new Vector3(pos.x, pos.y + 7F, pos.z), shPlayer.GetRotation()); - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"Spawning in vehicle with the ID: {arg1}"); - } - else - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"Error: The ID must be between 1 and {IDs_Vehicles.Length}."); - } - else - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"Error: Is that a valid number you provided as argument?"); - } - } + class SpawnVehicle + { + public static void Run(SvPlayer player, string message) + { + string arg1 = GetArgument.Run(1, false, true, message); + if (string.IsNullOrEmpty(arg1)) + { + player.SendChatMessage(ArgRequired); + return; + } + bool parsedSuccessfully = int.TryParse(arg1, out int arg1int); + if (!parsedSuccessfully) + { + player.SendChatMessage(NotValidArg); + return; + } + if (arg1int < 0 || arg1int > IDs_Vehicles.Length) + { + player.SendChatMessage($"Error: The ID must be between 1 and {IDs_Vehicles.Length}."); + return; + } + var shPlayer = player.player; + var pos = shPlayer.GetPosition(); + if (!player.player.IsOutside()) + { + player.SendChatMessage($"Cannot spawn inside a building."); + return; + } + if (arg1.Length > 4) + SvMan.AddNewEntity(ShManager.GetEntity(arg1int), shPlayer.manager.places[0], new Vector3(pos.x, pos.y + 10F, pos.z), shPlayer.GetRotation(), false); + else + SvMan.AddNewEntity(ShManager.GetEntity(IDs_Vehicles[arg1int - 1]), shPlayer.manager.places[0], new Vector3(pos.x, pos.y + 7F, pos.z), shPlayer.GetRotation(), false); + player.SendChatMessage($"Spawning in vehicle with the ID: {arg1}"); + } + } } diff --git a/source/BP-Essentials/Chat/Commands/Admin/Spy.cs b/source/BP-Essentials/Chat/Commands/Admin/Spy.cs index ed664f74..18af30f0 100644 --- a/source/BP-Essentials/Chat/Commands/Admin/Spy.cs +++ b/source/BP-Essentials/Chat/Commands/Admin/Spy.cs @@ -1,13 +1,12 @@ -using static BP_Essentials.EssentialsVariablesPlugin; +using static BP_Essentials.Variables; namespace BP_Essentials.Commands { public class Spy { public static void Run(SvPlayer player, string message) { - var shPlayer = player.player; - playerList[shPlayer.ID].spyEnabled = !playerList[shPlayer.ID].spyEnabled; - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"SpyChat {(playerList[shPlayer.ID].spyEnabled ? "Enabled" : "Disabled")}."); + PlayerList[player.player.ID].SpyEnabled = !PlayerList[player.player.ID].SpyEnabled; + player.SendChatMessage($"SpyChat {(PlayerList[player.player.ID].SpyEnabled ? "Enabled" : "Disabled")}."); } } } diff --git a/source/BP-Essentials/Chat/Commands/Admin/Strip.cs b/source/BP-Essentials/Chat/Commands/Admin/Strip.cs index fedba55d..383701be 100644 --- a/source/BP-Essentials/Chat/Commands/Admin/Strip.cs +++ b/source/BP-Essentials/Chat/Commands/Admin/Strip.cs @@ -3,44 +3,41 @@ using System.Linq; using System.Text; using UnityEngine; -using static BP_Essentials.EssentialsVariablesPlugin; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.Variables; +using static BP_Essentials.HookMethods; namespace BP_Essentials.Commands { - class Strip - { - public static void Run(SvPlayer player, string message) - { - string arg1 = GetArgument.Run(1, false, true, message); - if (String.IsNullOrEmpty(arg1)) - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, ArgRequired); - else - { - bool playerfound = false; - foreach (var shPlayer in UnityEngine.Object.FindObjectsOfType()) - if (shPlayer.username == arg1 && !shPlayer.svPlayer.serverside || shPlayer.ID.ToString() == arg1 && !shPlayer.svPlayer.serverside) - { - // To be improved - shPlayer.svPlayer.SvSetWearable(-1626497894); //NullArmor - shPlayer.svPlayer.SvSetWearable(673780802); //NullBack - shPlayer.svPlayer.SvSetWearable(-1638932793); //NullBody - shPlayer.svPlayer.SvSetWearable(1089711634); //NullFace - shPlayer.svPlayer.SvSetWearable(2064679354); //NullFeet - shPlayer.svPlayer.SvSetWearable(1174688158); //NullHands - shPlayer.svPlayer.SvSetWearable(-501996567); //NullHead - shPlayer.svPlayer.SvSetWearable(-1191209217); //NullLegs - foreach (var item in shPlayer.myItems.Values.ToList()) - if (item.item.GetType() == typeof(ShWearable)) - shPlayer.TransferItem(2, item.item.index, shPlayer.MyItemCount(item.item.index), true); - shPlayer.svPlayer.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"{player.playerData.username} Removed your clothes."); - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"Removed {shPlayer.username}'s clothes."); - playerfound = true; - } - if (!playerfound) - player.Send(SvSendType.Self, Channel.Reliable, ClPacket.GameMessage, NotFoundOnline); - - } - } - } + class Strip + { + public static void Run(SvPlayer player, string message) + { + string arg1 = GetArgument.Run(1, false, true, message); + if (string.IsNullOrEmpty(arg1)) + { + player.SendChatMessage(ArgRequired); + return; + } + var currPlayer = GetShByStr.Run(arg1); + if (currPlayer == null) + { + player.SendChatMessage(NotFoundOnline); + return; + } + // To be improved + currPlayer.svPlayer.SvSetWearable(-1626497894); //NullArmor + currPlayer.svPlayer.SvSetWearable(673780802); //NullBack + currPlayer.svPlayer.SvSetWearable(-1638932793); //NullBody + currPlayer.svPlayer.SvSetWearable(1089711634); //NullFace + currPlayer.svPlayer.SvSetWearable(2064679354); //NullFeet + currPlayer.svPlayer.SvSetWearable(1174688158); //NullHands + currPlayer.svPlayer.SvSetWearable(-501996567); //NullHead + currPlayer.svPlayer.SvSetWearable(-1191209217); //NullLegs + foreach (var item in currPlayer.myItems.Values.ToList()) + if (item.item.GetType() == typeof(ShWearable)) + currPlayer.TransferItem(DeltaInv.RemoveFromMe, item.item.index, currPlayer.MyItemCount(item.item.index), true); + currPlayer.svPlayer.SendChatMessage($"{player.playerData.username} Removed your clothes."); + player.SendChatMessage($"Removed {currPlayer.username}'s clothes."); + } + } } diff --git a/source/BP-Essentials/Chat/Commands/Admin/Sudo.cs b/source/BP-Essentials/Chat/Commands/Admin/Sudo.cs new file mode 100644 index 00000000..280a914d --- /dev/null +++ b/source/BP-Essentials/Chat/Commands/Admin/Sudo.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using UnityEngine; +using static BP_Essentials.Variables; +using static BP_Essentials.HookMethods; + +namespace BP_Essentials.Commands +{ + class Sudo + { + public static void Run(SvPlayer player, string message) + { + string arg1 = GetArgument.Run(1, false, false, message); + string arg2 = GetArgument.Run(2, false, true, message); + if (string.IsNullOrEmpty(arg1) || string.IsNullOrEmpty(arg2)) + { + player.SendChatMessage(ArgRequired); + return; + } + var shPlayer = GetShByStr.Run(arg1, true); + if (shPlayer == null) + { + player.SendChatMessage(NotFoundOnlineIdOnly); + return; + } + shPlayer.svPlayer.SvGlobalChatMessage(arg2); + player.SendChatMessage($"You sudo'ed {shPlayer.username} to type {arg2} in the global chat."); + } + } +} diff --git a/source/BP-Essentials/Chat/Commands/Admin/ToggleReceiveStaffChat.cs b/source/BP-Essentials/Chat/Commands/Admin/ToggleReceiveStaffChat.cs index b93c4a68..23aecca5 100644 --- a/source/BP-Essentials/Chat/Commands/Admin/ToggleReceiveStaffChat.cs +++ b/source/BP-Essentials/Chat/Commands/Admin/ToggleReceiveStaffChat.cs @@ -3,8 +3,8 @@ using System.Linq; using System.Text; using UnityEngine; -using static BP_Essentials.EssentialsVariablesPlugin; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.Variables; +using static BP_Essentials.HookMethods; namespace BP_Essentials.Commands { @@ -13,15 +13,15 @@ class ToggleReceiveStaffChat public static void Run(SvPlayer player, string message) { var shplayer = player.player; - if (playerList[shplayer.ID].receiveStaffChat) + if (PlayerList[shplayer.ID].ReceiveStaffChat) { - playerList[shplayer.ID].receiveStaffChat = false; - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"Staff chat messages disabled. You'll not receive any staff chat messages anymore."); + PlayerList[shplayer.ID].ReceiveStaffChat = false; + player.SendChatMessage($"Staff chat messages disabled. You'll not receive any staff chat messages anymore."); } else { - playerList[shplayer.ID].receiveStaffChat = true; - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"Staff chat message enabled. You'll now receive staff messages."); + PlayerList[shplayer.ID].ReceiveStaffChat = true; + player.SendChatMessage($"Staff chat messages enabled. You'll now receive staff messages."); } } } diff --git a/source/BP-Essentials/Chat/Commands/Admin/ToggleStaffChat.cs b/source/BP-Essentials/Chat/Commands/Admin/ToggleStaffChat.cs index 43c0f783..819b19ae 100644 --- a/source/BP-Essentials/Chat/Commands/Admin/ToggleStaffChat.cs +++ b/source/BP-Essentials/Chat/Commands/Admin/ToggleStaffChat.cs @@ -3,41 +3,33 @@ using System.Linq; using System.Text; using UnityEngine; -using static BP_Essentials.EssentialsVariablesPlugin; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.Variables; +using static BP_Essentials.HookMethods; using System.Text.RegularExpressions; namespace BP_Essentials.Commands { class ToggleStaffChat { - public static void Run(SvPlayer player, string message) - { - var arg1 = GetArgument.Run(1, false, true, message); - var shplayer = player.player; - if (string.IsNullOrEmpty(arg1)) - { - if (playerList[shplayer.ID].staffChatEnabled) - { - playerList[shplayer.ID].staffChatEnabled = false; - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"Staff chat disabled."); - } - else - { - playerList[shplayer.ID].staffChatEnabled = true; - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"Staff chat enabled."); - } - } - else - { - _msg = AdminChatMessage; - _msg = _msg.Replace("{username}", new Regex("(<)").Replace(shplayer.username, "<")); - _msg = _msg.Replace("{id}", new Regex("(<)").Replace($"{shplayer.ID}", "<")); - _msg = _msg.Replace("{jobindex}", new Regex("(<)").Replace($"{shplayer.job.jobIndex}", "<")); - _msg = _msg.Replace("{jobname}", new Regex("(<)").Replace($"{shplayer.job.info.jobName}", "<")); - _msg = _msg.Replace("{message}", new Regex("(<)").Replace(Chat.LangAndChatBlock.Run(arg1), "<")); - SendChatMessageToAdmins.Run(_msg); - } - } + public static void Run(SvPlayer player, string message) + { + var arg1 = GetArgument.Run(1, false, true, message); + var shplayer = player.player; + if (string.IsNullOrEmpty(arg1)) + { + if (PlayerList[shplayer.ID].StaffChatEnabled) + { + PlayerList[shplayer.ID].StaffChatEnabled = false; + player.SendChatMessage($"Staff chat disabled."); + } + else + { + PlayerList[shplayer.ID].StaffChatEnabled = true; + player.SendChatMessage($"Staff chat enabled."); + } + return; + } + SendChatMessageToAdmins.Run(PlaceholderParser.ParseUserMessage(player.player, AdminChatMessage, arg1)); + } } } diff --git a/source/BP-Essentials/Chat/Commands/Admin/Tp.cs b/source/BP-Essentials/Chat/Commands/Admin/Tp.cs index 046a0383..3401919c 100644 --- a/source/BP-Essentials/Chat/Commands/Admin/Tp.cs +++ b/source/BP-Essentials/Chat/Commands/Admin/Tp.cs @@ -1,25 +1,27 @@ -using static BP_Essentials.EssentialsVariablesPlugin; +using static BP_Essentials.Variables; using System; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.HookMethods; -namespace BP_Essentials.Commands { - public class Tp { - public static void Run(SvPlayer player, string message) - { - string arg1 = GetArgument.Run(1, false, true, message); - if (!string.IsNullOrEmpty(arg1)) - { - var shPlayer = GetShByStr.Run(arg1); - if (shPlayer == null) - { - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, NotFoundOnline); - return; - } - player.SvReset(shPlayer.GetPosition(), shPlayer.GetRotation(), shPlayer.GetPlaceIndex()); - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"Teleported to " + shPlayer.username + $"."); - } - else - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, ArgRequired); - } - } +namespace BP_Essentials.Commands +{ + public class Tp + { + public static void Run(SvPlayer player, string message) + { + string arg1 = GetArgument.Run(1, false, true, message); + if (string.IsNullOrEmpty(arg1)) + { + player.SendChatMessage(ArgRequired); + return; + } + var shPlayer = GetShByStr.Run(arg1); + if (shPlayer == null) + { + player.SendChatMessage(NotFoundOnline); + return; + } + player.ResetAndSavePosition(shPlayer.GetPosition(), shPlayer.GetRotation(), shPlayer.GetPlaceIndex()); + player.SendChatMessage($"Teleported to {shPlayer.username}."); + } + } } \ No newline at end of file diff --git a/source/BP-Essentials/Chat/Commands/Admin/TpAll.cs b/source/BP-Essentials/Chat/Commands/Admin/TpAll.cs index 0a74f6a0..5f633346 100644 --- a/source/BP-Essentials/Chat/Commands/Admin/TpAll.cs +++ b/source/BP-Essentials/Chat/Commands/Admin/TpAll.cs @@ -1,6 +1,6 @@ -using static BP_Essentials.EssentialsVariablesPlugin; +using static BP_Essentials.Variables; using System; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.HookMethods; namespace BP_Essentials.Commands { @@ -10,10 +10,9 @@ public static void Run(SvPlayer player, string message) { var pos = player.player.GetPosition(); var rot = player.player.GetRotation(); - var pIndex = player.player.GetPlaceIndex(); foreach (var currPlayer in SvMan.players.Values) - currPlayer.svPlayer.SvReset(pos, rot, pIndex); - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"Teleported everyone to your location."); + currPlayer.svPlayer.ResetAndSavePosition(pos, rot, player.player.GetPlaceIndex()); + player.SendChatMessage($"Teleported everyone to your location."); } } } \ No newline at end of file diff --git a/source/BP-Essentials/Chat/Commands/Admin/TpHere.cs b/source/BP-Essentials/Chat/Commands/Admin/TpHere.cs index e76f3a51..f81c67c8 100644 --- a/source/BP-Essentials/Chat/Commands/Admin/TpHere.cs +++ b/source/BP-Essentials/Chat/Commands/Admin/TpHere.cs @@ -1,29 +1,29 @@ -using static BP_Essentials.EssentialsVariablesPlugin; +using static BP_Essentials.Variables; using System; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.HookMethods; namespace BP_Essentials.Commands { public class TpHere { - public static void Run(SvPlayer player, string message) - { - string arg1 = GetArgument.Run(1, false, true, message); - if (!string.IsNullOrEmpty(arg1)) - { - var shPlayer = GetShByStr.Run(arg1); - var shPlayer1 = player.player; - if (shPlayer == null) - { - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, NotFoundOnline); - return; - } - shPlayer.svPlayer.SvReset(shPlayer1.GetPosition(), shPlayer1.GetRotation(), shPlayer1.GetPlaceIndex()); - shPlayer.svPlayer.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"" + shPlayer1.username + $" Teleported you to him."); - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"Teleported " + shPlayer.username + $" To you."); - } - else - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, ArgRequired); - } + public static void Run(SvPlayer player, string message) + { + string arg1 = GetArgument.Run(1, false, true, message); + if (string.IsNullOrEmpty(arg1)) + { + player.SendChatMessage(ArgRequired); + return; + } + var shPlayer = GetShByStr.Run(arg1); + var shPlayer1 = player.player; + if (shPlayer == null) + { + player.SendChatMessage(NotFoundOnline); + return; + } + shPlayer.svPlayer.ResetAndSavePosition(shPlayer1.GetPosition(), shPlayer1.GetRotation(), shPlayer1.GetPlaceIndex()); + shPlayer.svPlayer.SendChatMessage($"{shPlayer1.username} Teleported you to him."); + player.SendChatMessage($"Teleported {shPlayer.username} To you."); + } } } \ No newline at end of file diff --git a/source/BP-Essentials/Chat/Commands/Admin/TpJob.cs b/source/BP-Essentials/Chat/Commands/Admin/TpJob.cs new file mode 100644 index 00000000..cb3c193e --- /dev/null +++ b/source/BP-Essentials/Chat/Commands/Admin/TpJob.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using static BP_Essentials.Variables; + +namespace BP_Essentials.Commands +{ + class TpJob + { + public static void Run(SvPlayer player, string message) + { + var arg1 = GetArgument.Run(1, false, true, message); + if (string.IsNullOrWhiteSpace(arg1)) + { + player.SendChatMessage(ArgRequired); + return; + } + var bosses = UnityEngine.Object.FindObjectsOfType().Where(x => x.boss || x.svPlayer.serverside); + var boss = bosses.FirstOrDefault(x => x.ID.ToString() == arg1 || x.username == arg1 || x.username.StartsWith(arg1, StringComparison.CurrentCultureIgnoreCase) || x.job.info.jobName == arg1.ToLower() || x.job.info.jobName.StartsWith(arg1, StringComparison.CurrentCultureIgnoreCase)); + if (boss == default(ShPlayer)) + { + player.SendChatMessage(NotFoundOnline); + return; + } + player.ResetAndSavePosition(boss.svPlayer); + player.SendChatMessage($"Teleported to {boss.username} ({boss.job.info.jobName})"); + } + } +} diff --git a/source/BP-Essentials/Chat/Commands/Admin/TpLocation.cs b/source/BP-Essentials/Chat/Commands/Admin/TpLocation.cs index ef37b2f3..22fdec84 100644 --- a/source/BP-Essentials/Chat/Commands/Admin/TpLocation.cs +++ b/source/BP-Essentials/Chat/Commands/Admin/TpLocation.cs @@ -1,13 +1,14 @@ -using static BP_Essentials.EssentialsVariablesPlugin; +using static BP_Essentials.Variables; using System; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.HookMethods; using System.Collections.Generic; using UnityEngine; using System.Linq; namespace BP_Essentials.Commands { - public class TpLocation + [Obsolete] + public class TpLocation { [Obsolete] public static void Run(SvPlayer player, string message) @@ -15,17 +16,17 @@ public static void Run(SvPlayer player, string message) var arg1 = GetArgument.Run(1, false, true, message); if (string.IsNullOrEmpty(arg1.Trim())) { - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, ArgRequired); + player.SendChatMessage(ArgRequired); return; } foreach (var currKey in PlaceDictionary.Keys) if (currKey.Contains(arg1)) { - player.SvReset(PlaceDictionary[currKey], player.player.GetRotation(), 0); - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"Teleported to {currKey[1]}."); + player.ResetAndSavePosition(PlaceDictionary[currKey], player.player.GetRotation(), 0); + player.SendChatMessage($"Teleported to {currKey[1]}."); return; } - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"Invalid place name!"); + player.SendChatMessage($"Invalid place name!"); } } } \ No newline at end of file diff --git a/source/BP-Essentials/Chat/Commands/Admin/TpToApartment.cs b/source/BP-Essentials/Chat/Commands/Admin/TpToApartment.cs index d8f3602c..54be5f41 100644 --- a/source/BP-Essentials/Chat/Commands/Admin/TpToApartment.cs +++ b/source/BP-Essentials/Chat/Commands/Admin/TpToApartment.cs @@ -1,15 +1,19 @@ -using static BP_Essentials.EssentialsVariablesPlugin; +using static BP_Essentials.Variables; using UnityEngine; +using System; + namespace BP_Essentials.Commands { - public class TpToApartment + [Obsolete] + public class TpToApartment { - public static void Run(SvPlayer player, string message) + [Obsolete] + public static void Run(SvPlayer player, string message) { var arg1 = GetArgument.Run(1, false, true, message); if (string.IsNullOrEmpty(arg1)) { - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, ArgRequired); + player.SendChatMessage(ArgRequired); return; } switch (arg1) @@ -19,24 +23,24 @@ public static void Run(SvPlayer player, string message) case "1": case "1.200": case "1000": - player.SvReset(new Vector3(643.1F, 0, -61.4F), Quaternion.identity, 0); - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"Teleported to 1.2k apartment."); + player.ResetAndSavePosition(new Vector3(643.1F, 0, -61.4F), Quaternion.identity, 0); + player.SendChatMessage($"Teleported to 1.2k apartment."); break; case "5k": case "2": case "5000": - player.SvReset(new Vector3(518.8F, 0, -127.2F), Quaternion.identity, 0); - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"Teleported to 5k apartment."); + player.ResetAndSavePosition(new Vector3(518.8F, 0, -127.2F), Quaternion.identity, 0); + player.SendChatMessage($"Teleported to 5k apartment."); break; case "10k": case "10": case "3": case "10000": - player.SvReset(new Vector3(1.7F, 0, -92.8F), Quaternion.identity, 0); - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"Teleported to 10k apartment."); + player.ResetAndSavePosition(new Vector3(1.7F, 0, -92.8F), Quaternion.identity, 0); + player.SendChatMessage($"Teleported to 10k apartment."); break; default: - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"{GetArgument.Run(0, false, false, message)} [1.2k, 5k, 10k]"); + player.SendChatMessage($"{GetArgument.Run(0, false, false, message)} [1.2k, 5k, 10k]"); break; } } diff --git a/source/BP-Essentials/Chat/Commands/Admin/Wipe.cs b/source/BP-Essentials/Chat/Commands/Admin/Wipe.cs index a5c01dcf..8a5d4322 100644 --- a/source/BP-Essentials/Chat/Commands/Admin/Wipe.cs +++ b/source/BP-Essentials/Chat/Commands/Admin/Wipe.cs @@ -1,6 +1,6 @@ -using static BP_Essentials.EssentialsVariablesPlugin; +using static BP_Essentials.Variables; using System; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.HookMethods; using System.IO; using System.Linq; using UnityEngine; @@ -15,26 +15,27 @@ public static void Run(SvPlayer player, string message) string arg1 = GetArgument.Run(1, false, true, message); if (string.IsNullOrEmpty(arg1)) { - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, ArgRequired); + player.SendChatMessage(ArgRequired); return; } if (WipePassword == "default") { - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"Password was not changed yet, cannot use this command."); + player.SendChatMessage($"Password was not changed yet, cannot use this command."); return; } if (arg1 != WipePassword) { - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"Invalid password."); + player.SendChatMessage($"Invalid password."); return; } - Debug.Log($"{SetTimeStamp.Run()}[INFO] Wipe command ran by {player.player.username}, password matched, deleting all save files."); - foreach (var currPlayer in playerList.Values) - player.svManager.Disconnect(currPlayer.Shplayer.svPlayer.connection); + Debug.Log($"{PlaceholderParser.ParseTimeStamp()} [INFO] Wipe command ran by {player.player.username}, password matched, deleting all save files."); + foreach (var currPlayer in PlayerList.Values.ToList()) + player.svManager.Disconnect(currPlayer.ShPlayer.svPlayer.connection, DisconnectTypes.Problem); Thread.Sleep(500); - foreach (string file in Directory.GetFiles(Path.Combine(Application.persistentDataPath, "PlayerData/"), "*.json").Where(item => item.EndsWith(".json"))) - File.Delete(file); - Debug.Log($"{SetTimeStamp.Run()}[INFO] All user data deleted!"); + var files = Directory.GetFiles(Path.Combine(Application.persistentDataPath, "PlayerData/"), "*.json").Where(item => item.EndsWith(".json", StringComparison.CurrentCulture)); + foreach (var file in files.ToList()) + File.Delete(file); + Debug.Log($"{PlaceholderParser.ParseTimeStamp()} [INFO] All user data deleted!"); } } } \ No newline at end of file diff --git a/source/BP-Essentials/Chat/Commands/Admin/_SetJob.cs b/source/BP-Essentials/Chat/Commands/Admin/_SetJob.cs index 59ff5a48..53c41310 100644 --- a/source/BP-Essentials/Chat/Commands/Admin/_SetJob.cs +++ b/source/BP-Essentials/Chat/Commands/Admin/_SetJob.cs @@ -3,48 +3,50 @@ using System.Linq; using System.Text; using UnityEngine; -using static BP_Essentials.EssentialsVariablesPlugin; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.Variables; +using static BP_Essentials.HookMethods; using System.Reflection; namespace BP_Essentials.Commands { class _SetJob : SvPlayer { - public static void Run(SvPlayer player, string message) - { - string NotValidArg = $"Error: Is that a valid number you provided as argument?"; - string arg1 = GetArgument.Run(1, false, false, message); - string arg2 = GetArgument.Run(2, false, true, message); - byte arg1int = 10; - string msg = $"Set {{0}}'s Job to {{1}}."; - if (String.IsNullOrEmpty(arg2)) - arg2 = player.player.username; - if (!String.IsNullOrEmpty(arg1)) - { - bool Parsed = true; - if (Jobs.Contains(arg1)) - arg1int = Convert.ToByte((Array.IndexOf(Jobs, arg1))); - else - Parsed = byte.TryParse(arg1, out arg1int); - if (Parsed) - { - foreach (var shPlayer in UnityEngine.Object.FindObjectsOfType()) - if (shPlayer.username == arg2 || shPlayer.ID.ToString() == arg2.ToString()) - if (arg1int <= Jobs.Length && arg1int >= 0) - { - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, String.Format(msg, shPlayer.username, Jobs[arg1int])); - SetJob.Run(shPlayer, arg1int, true, false); - - } - else - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"Error: The value must be between 0 and {Jobs.Length}."); - } - else - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, NotValidArg); - } - else - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, NotValidArg); - } + public static void Run(SvPlayer player, string message) + { + string arg1 = GetArgument.Run(1, false, false, message); + string arg2 = GetArgument.Run(2, false, true, message); + byte arg1Parsed = 10; + string msg = $"Set {{0}}'s Job to {{1}}."; + if (string.IsNullOrEmpty(arg2)) + arg2 = player.player.username; + if (string.IsNullOrEmpty(arg1)) + { + player.SendChatMessage(NotValidArg); + return; + } + bool parsedCorrectly = true; + if (Jobs.Contains(arg1)) + arg1Parsed = Convert.ToByte((Array.IndexOf(Jobs, arg1))); + else + parsedCorrectly = byte.TryParse(arg1, out arg1Parsed); + if (!parsedCorrectly) + { + player.SendChatMessage(NotValidArg); + return; + } + if (arg1Parsed > Jobs.Length || arg1Parsed < 0) + { + player.SendChatMessage($"Error: The value must be between 0 and {Jobs.Length}."); + return; + } + var currPlayer = GetShByStr.Run(arg2); + if (currPlayer == null) + { + player.SendChatMessage(NotFoundOnline); + return; + } + player.SendChatMessage(string.Format(msg, currPlayer.username, Jobs[arg1Parsed])); + SetJob.Run(currPlayer, arg1Parsed, true, false); + } } } diff --git a/source/BP-Essentials/Chat/Commands/Everyone/Afk.cs b/source/BP-Essentials/Chat/Commands/Everyone/Afk.cs index 3b6c10ea..0c67dab8 100644 --- a/source/BP-Essentials/Chat/Commands/Everyone/Afk.cs +++ b/source/BP-Essentials/Chat/Commands/Everyone/Afk.cs @@ -1,22 +1,22 @@ using System; -using static BP_Essentials.EssentialsVariablesPlugin; +using static BP_Essentials.Variables; using System.IO; namespace BP_Essentials.Commands { public class Afk { public static void Run(SvPlayer player, string message) { ReadFile.Run(AfkListFile); - if (AfkPlayers.Contains(player.playerData.username)) + if (AfkPlayers.Contains(player.player.username)) { - RemoveStringFromFile.Run(AfkListFile, player.playerData.username); + RemoveStringFromFile.Run(AfkListFile, player.player.username); ReadFile.Run(AfkListFile); - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"You are no longer AFK."); + player.SendChatMessage($"You are no longer AFK."); } else { - File.AppendAllText(AfkListFile, player.playerData.username + Environment.NewLine); - AfkPlayers.Add(player.playerData.username); - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"You are now AFK."); + File.AppendAllText(AfkListFile, player.player.username + Environment.NewLine); + AfkPlayers.Add(player.player.username); + player.SendChatMessage($"You are now AFK."); } } } diff --git a/source/BP-Essentials/Chat/Commands/Everyone/Atm.cs b/source/BP-Essentials/Chat/Commands/Everyone/Atm.cs index 7ce746c1..5e56e64d 100644 --- a/source/BP-Essentials/Chat/Commands/Everyone/Atm.cs +++ b/source/BP-Essentials/Chat/Commands/Everyone/Atm.cs @@ -3,8 +3,8 @@ using System.Linq; using System.Text; using UnityEngine; -using static BP_Essentials.EssentialsVariablesPlugin; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.Variables; +using static BP_Essentials.HookMethods; namespace BP_Essentials.Commands { @@ -12,7 +12,7 @@ class Atm { public static void Run(SvPlayer player, string message) { - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"Opening ATM menu.."); + player.SendChatMessage($"Opening ATM menu.."); player.Send(SvSendType.Self, Channel.Reliable, ClPacket.ShowATMMenu, player.bankBalance); } } diff --git a/source/BP-Essentials/Chat/Commands/Everyone/ClearChat.cs b/source/BP-Essentials/Chat/Commands/Everyone/ClearChat.cs index b84c0040..c85c4dea 100644 --- a/source/BP-Essentials/Chat/Commands/Everyone/ClearChat.cs +++ b/source/BP-Essentials/Chat/Commands/Everyone/ClearChat.cs @@ -1,31 +1,30 @@ using System; using System.Threading; -using static BP_Essentials.EssentialsVariablesPlugin; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.Variables; +using static BP_Essentials.HookMethods; namespace BP_Essentials.Commands { public class ClearChat { - public static void Run(SvPlayer player, string message) - { - string arg1 = GetArgument.Run(1, false, false, message); - if (arg1 == "all" || arg1 == "everyone") - { - if (player.player.admin) - { - for (var i = 0; i < 6; i++) - player.Send(SvSendType.All, Channel.Unsequenced, 10, " "); - player.Send(SvSendType.All, Channel.Unsequenced, 10, $"{player.playerData.username} Cleared the chat for everyone."); - } - else - player.Send(SvSendType.Self, Channel.Unsequenced, 10, MsgNoPerm); - } - else - { - - for (var i = 0; i < 6; i++) - player.Send(SvSendType.Self, Channel.Unsequenced, 10, " "); - player.Send(SvSendType.Self, Channel.Unsequenced, 10, $"Cleared the chat for yourself."); - } - } + public static void Run(SvPlayer player, string message) + { + string arg1 = GetArgument.Run(1, false, false, message); + if (arg1 == "all" || arg1 == "everyone") + { + if (!player.player.admin) + { + player.Send(SvSendType.Self, Channel.Unsequenced, 10, MsgNoPerm); + return; + } + for (var i = 0; i < 6; i++) + player.Send(SvSendType.All, Channel.Unsequenced, 10, " "); + player.Send(SvSendType.All, Channel.Unsequenced, 10, $"{player.playerData.username} Cleared the chat for everyone."); + } + else + { + for (var i = 0; i < 6; i++) + player.Send(SvSendType.Self, Channel.Unsequenced, 10, " "); + player.Send(SvSendType.Self, Channel.Unsequenced, 10, $"Cleared the chat for yourself."); + } + } } } diff --git a/source/BP-Essentials/Chat/Commands/Everyone/Confirm.cs b/source/BP-Essentials/Chat/Commands/Everyone/Confirm.cs index 37e97856..6c5bbb28 100644 --- a/source/BP-Essentials/Chat/Commands/Everyone/Confirm.cs +++ b/source/BP-Essentials/Chat/Commands/Everyone/Confirm.cs @@ -3,8 +3,8 @@ using System.Linq; using System.Text; using UnityEngine; -using static BP_Essentials.EssentialsVariablesPlugin; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.Variables; +using static BP_Essentials.HookMethods; namespace BP_Essentials.Commands { @@ -15,10 +15,10 @@ public static void Run(SvPlayer player, string message) var shPlayer = player.player; if (!shPlayer.ownedApartment) { - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"You don't have a apartment to sell!"); + player.SendChatMessage($"You don't have a apartment to sell!"); return; } - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"Selling apartment..."); + player.SendChatMessage($"Selling apartment..."); SellApartment(shPlayer); } public static void SellApartment(ShPlayer shPlayer) diff --git a/source/BP-Essentials/Chat/Commands/Everyone/Essentials.cs b/source/BP-Essentials/Chat/Commands/Everyone/Essentials.cs index 39caae06..a167bc2e 100644 --- a/source/BP-Essentials/Chat/Commands/Everyone/Essentials.cs +++ b/source/BP-Essentials/Chat/Commands/Everyone/Essentials.cs @@ -1,34 +1,36 @@ using System; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.HookMethods; namespace BP_Essentials.Commands { public class Essentials { public static void Run(SvPlayer player, string message) { string arg = GetArgument.Run(1, false, false, message).Trim().ToLower(); - if (arg == "ver" || arg == "version") - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, "Version: " + EssentialsVariablesPlugin.Version); - else if (arg == "info") - { - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, "Essentials Created by UserR00T & DeathByKorea & BP"); - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, "Version " + EssentialsVariablesPlugin.Version); - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, "Type '/essentials help' for more info. "); - } - else if (arg == "help") - { - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, "Subcommands for /essentials:"); - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, " - help : Shows this menu."); - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, " - info : Shows infomation about the developer."); - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, " - ver/version : Shows version number."); - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, " - cmd/command : Gives a link to the website of BP-Essentials."); - } - else if (arg == "cmd" || arg == "cmds" || arg == "command" || arg == "commands") - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, "Up to date help can be found at http://bit.do/BPEssentials"); - else - { - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, "Essentials Created by UserR00T & DeathByKorea & BP."); - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, "Version " + EssentialsVariablesPlugin.Version); - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, "Type '/essentials help' for more info. "); - } - } + switch (arg) + { + case "ver": + case "version": + player.SendChatMessage("Version: " + Variables.Version); + break; + case "help": + player.SendChatMessage("Subcommands for /essentials:"); + player.SendChatMessage(" - help : Shows this menu."); + player.SendChatMessage(" - info : Shows infomation about the developer."); + player.SendChatMessage(" - ver/version : Shows version number."); + player.SendChatMessage(" - cmd/command : Gives a link to the website of BP-Essentials."); + break; + case "cmd": + case "cmds": + case "command": + case "commands": + player.SendChatMessage("Up to date help can be found at https://goo.gl/Rwhtjs"); + break; + case "info": + default: + player.SendChatMessage("Essentials Created by UserR00T & DeathByKorea & BP."); + player.SendChatMessage("Version " + Variables.Version); + player.SendChatMessage("Type '/essentials help' for more info. "); + break; + } + } } } \ No newline at end of file diff --git a/source/BP-Essentials/Chat/Commands/Everyone/GetKit.cs b/source/BP-Essentials/Chat/Commands/Everyone/GetKit.cs index 6cd7f0dd..ef22271c 100644 --- a/source/BP-Essentials/Chat/Commands/Everyone/GetKit.cs +++ b/source/BP-Essentials/Chat/Commands/Everyone/GetKit.cs @@ -3,8 +3,8 @@ using System.Linq; using System.Text; using UnityEngine; -using static BP_Essentials.EssentialsVariablesPlugin; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.Variables; +using static BP_Essentials.HookMethods; using System.IO; namespace BP_Essentials.Commands @@ -16,35 +16,35 @@ public static void Run(SvPlayer player, string message) var arg1 = GetArgument.Run(1, false, true, message); if (string.IsNullOrEmpty(arg1.Trim())) { - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, ArgRequired); + player.SendChatMessage(ArgRequired); return; } - if (!listKits.Any(x=>x.Name == arg1)) + if (!Variables.KitsHandler.List.Any(x=>x.Name == arg1)) { - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"That kit doesn't exist."); + player.SendChatMessage($"That kit doesn't exist."); return; } - var obj = listKits.FirstOrDefault(x => x.Name == arg1); + var obj = Variables.KitsHandler.List.FirstOrDefault(x => x.Name == arg1); if (!HasPermission.Run(player, obj.ExecutableBy, false, player.player.job.jobIndex)) { - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"You do not have access to that kit."); + player.SendChatMessage($"You do not have access to that kit."); return; } if (obj.Disabled) { - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"That kit is currently disabled."); + player.SendChatMessage($"That kit is currently disabled."); return; } if (obj.CurrentlyInCooldown.ContainsKey(player.player.username)) { - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"You already used this kit. Please wait {obj.CurrentlyInCooldown[player.player.username]} second(s) before executing this command again."); + player.SendChatMessage($"You already used this kit. Please wait {obj.CurrentlyInCooldown[player.player.username]} second(s) before executing this command again."); return; } if (obj.Price > 0) { if (player.player.MyMoneyCount() < obj.Price) { - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"You do not have enough money to get this kit. (You have: {player.player.MyMoneyCount()} | Needed: {obj.Price})"); + player.SendChatMessage($"You do not have enough money to get this kit. (You have: {player.player.MyMoneyCount()} | Needed: {obj.Price})"); return; } player.player.TransferMoney(DeltaInv.RemoveFromMe, obj.Price, true); @@ -54,8 +54,9 @@ public static void Run(SvPlayer player, string message) player.player.TransferItem(DeltaInv.AddToMe, item.Id, item.Amount, true); } if (obj.Delay > 0) - player.StartCoroutine(Kits.KitCooldown(player.player.username, obj)); - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"You've been given the kit {arg1}."); - } + SvMan.StartCoroutine(Variables.KitsHandler.StartCooldown(player.player.username, obj)); + player.SendChatMessage($"You've been given the kit {arg1}.{(obj.Delay > 0 ? $" You can get this kit again in {obj.Delay} seconds." : "")}"); + + } } } diff --git a/source/BP-Essentials/Chat/Commands/Everyone/GoToWarp.cs b/source/BP-Essentials/Chat/Commands/Everyone/GoToWarp.cs index bda901d5..429a5349 100644 --- a/source/BP-Essentials/Chat/Commands/Everyone/GoToWarp.cs +++ b/source/BP-Essentials/Chat/Commands/Everyone/GoToWarp.cs @@ -3,8 +3,8 @@ using System.Linq; using System.Text; using UnityEngine; -using static BP_Essentials.EssentialsVariablesPlugin; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.Variables; +using static BP_Essentials.HookMethods; using System.IO; namespace BP_Essentials.Commands @@ -16,43 +16,43 @@ public static void Run(SvPlayer player, string message) var arg1 = GetArgument.Run(1, false, true, message); if (string.IsNullOrEmpty(arg1.Trim())) { - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, ArgRequired); + player.SendChatMessage(ArgRequired); return; } - if (!listWarps.Any(x=>x.Name == arg1)) + if (!Variables.WarpHandler.List.Any(x=>x.Name == arg1)) { - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"That warp doesn't exist."); + player.SendChatMessage($"That warp doesn't exist."); return; } - var obj = listWarps.FirstOrDefault(x => x.Name == arg1); + var obj = Variables.WarpHandler.List.FirstOrDefault(x => x.Name == arg1); if (!HasPermission.Run(player, obj.ExecutableBy, false, player.player.job.jobIndex)) { - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"You do not have access to that warp."); + player.SendChatMessage($"You do not have access to that warp."); return; } if (obj.Disabled) { - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"That warp is currently disabled."); + player.SendChatMessage($"That warp is currently disabled."); return; } if (obj.CurrentlyInCooldown.ContainsKey(player.player.username)) { - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"You already went to that warp. Please wait {obj.CurrentlyInCooldown[player.player.username]} second(s) before executing this command again."); + player.SendChatMessage($"You already went to that warp. Please wait {obj.CurrentlyInCooldown[player.player.username]} second(s) before executing this command again."); return; } if (obj.Price > 0) { if (player.player.MyMoneyCount() < obj.Price) { - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"You do not have enough money to pay for this warp. (You have: {player.player.MyMoneyCount()} | Needed: {obj.Price})"); + player.SendChatMessage($"You do not have enough money to pay for this warp. (You have: {player.player.MyMoneyCount()} | Needed: {obj.Price})"); return; } player.player.TransferMoney(DeltaInv.RemoveFromMe, obj.Price, true); } - player.SvReset(new Vector3(obj.Position.X, obj.Position.Y, obj.Position.Z), new Quaternion(obj.Rotation.X, obj.Rotation.Y, obj.Rotation.Z, obj.Rotation.W), 0); + player.ResetAndSavePosition(new Vector3(obj.Position.X, obj.Position.Y, obj.Position.Z), new Quaternion(obj.Rotation.X, obj.Rotation.Y, obj.Rotation.Z, obj.Rotation.W), obj.Position.PlaceIndex); if (obj.Delay > 0) - player.StartCoroutine(Warps.WarpCooldown(player.player.username, obj)); - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"You've been teleported to the warp named {arg1}."); + SvMan.StartCoroutine(Variables.WarpHandler.StartCooldown(player.player.username, obj)); + player.SendChatMessage($"You've been teleported to the warp named {arg1}.{(obj.Delay > 0 ? $" You can teleport to this warp again in {obj.Delay} seconds." : "")}"); } } } diff --git a/source/BP-Essentials/Chat/Commands/Everyone/Home.cs b/source/BP-Essentials/Chat/Commands/Everyone/Home.cs index af0b9f64..037df59b 100644 --- a/source/BP-Essentials/Chat/Commands/Everyone/Home.cs +++ b/source/BP-Essentials/Chat/Commands/Everyone/Home.cs @@ -1,20 +1,20 @@ using System; -using static BP_Essentials.EssentialsVariablesPlugin; +using static BP_Essentials.Variables; using System.IO; namespace BP_Essentials.Commands { - public class Home + public static class Home { public static void Run(SvPlayer player, string message) { var shPlayer = player.player; if (!shPlayer.ownedApartment) { - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"You don't have a apartment to teleport to!"); + player.SendChatMessage($"You don't have a apartment to teleport to!"); return; } - player.SvReset(shPlayer.ownedApartment.svDoor.other.spawnPoint.position, shPlayer.ownedApartment.svDoor.other.spawnPoint.rotation, 0); - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"Teleported to your apartment."); + player.ResetAndSavePosition(shPlayer.ownedApartment.svDoor.transform.position, shPlayer.ownedApartment.svDoor.transform.rotation, 0); + player.SendChatMessage($"Teleported to your apartment."); } } } \ No newline at end of file diff --git a/source/BP-Essentials/Chat/Commands/Everyone/ListKits.cs b/source/BP-Essentials/Chat/Commands/Everyone/ListKits.cs index 7442a8b9..e515419a 100644 --- a/source/BP-Essentials/Chat/Commands/Everyone/ListKits.cs +++ b/source/BP-Essentials/Chat/Commands/Everyone/ListKits.cs @@ -3,8 +3,8 @@ using System.Linq; using System.Text; using UnityEngine; -using static BP_Essentials.EssentialsVariablesPlugin; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.Variables; +using static BP_Essentials.HookMethods; namespace BP_Essentials.Commands { @@ -12,8 +12,8 @@ class ListKits { public static void Run(SvPlayer player, string message) { - var kits = listKits.Where(x => !x.Disabled && HasPermission.Run(player, x.ExecutableBy, false, player.player.job.jobIndex)).Select(n=>n.Name + $"{(n.Price != 0 ? $" ({n.Price})" : "")}").ToArray(); - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"Kits you can obtain ({kits.Length}): {(kits == null || kits.Length == 0 ? "none" : string.Join(", ", kits))}"); + var kits = Variables.KitsHandler.List.Where(x => !x.Disabled && HasPermission.Run(player, x.ExecutableBy, false, player.player.job.jobIndex)).Select(n=>n.Name + $"{(n.Price != 0 ? $" ({n.Price})" : "")}").ToArray(); //linq rocks, and yes this was an very important comment. + player.SendChatMessage($"Kits you can obtain ({kits.Length}): {(kits == null || kits.Length == 0 ? "none" : string.Join(", ", kits))}"); } } } diff --git a/source/BP-Essentials/Chat/Commands/Everyone/ListWarps.cs b/source/BP-Essentials/Chat/Commands/Everyone/ListWarps.cs index 5d652ae0..e8761d35 100644 --- a/source/BP-Essentials/Chat/Commands/Everyone/ListWarps.cs +++ b/source/BP-Essentials/Chat/Commands/Everyone/ListWarps.cs @@ -3,8 +3,8 @@ using System.Linq; using System.Text; using UnityEngine; -using static BP_Essentials.EssentialsVariablesPlugin; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.Variables; +using static BP_Essentials.HookMethods; namespace BP_Essentials.Commands { @@ -12,8 +12,8 @@ class ListWarps { public static void Run(SvPlayer player, string message) { - var warps = listWarps.Where(x => !x.Disabled && HasPermission.Run(player, x.ExecutableBy, false, player.player.job.jobIndex)).Select(n=>n.Name + $"{(n.Price != 0 ? $" ({n.Price})" : "")}").ToArray(); - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"Warps you can teleport to ({warps.Length}): {(warps == null || warps.Length == 0 ? "none" : string.Join(", ", warps))}"); + var warps = Variables.WarpHandler.List.Where(x => !x.Disabled && HasPermission.Run(player, x.ExecutableBy, false, player.player.job.jobIndex)).Select(n=>n.Name + $"{(n.Price != 0 ? $" ({n.Price})" : "")}").ToArray(); + player.SendChatMessage($"Warps you can teleport to ({warps.Length}): {(warps == null || warps.Length == 0 ? "none" : string.Join(", ", warps))}"); } } } diff --git a/source/BP-Essentials/Chat/Commands/Everyone/Me.cs b/source/BP-Essentials/Chat/Commands/Everyone/Me.cs new file mode 100644 index 00000000..3b0d85f2 --- /dev/null +++ b/source/BP-Essentials/Chat/Commands/Everyone/Me.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using static BP_Essentials.Variables; + +namespace BP_Essentials.Commands +{ + class Me + { + public static void Run(SvPlayer player, string message) + { + var arg1 = GetArgument.Run(1, false, true, message); + if (string.IsNullOrWhiteSpace(arg1)) + { + player.SendChatMessage(ArgRequired); + return; + } + player.Send(LocalChatMe ? SvSendType.Local : SvSendType.All, Channel.Unsequenced, ClPacket.GameMessage, PlaceholderParser.ParseUserMessage(player.player, MeMessage, arg1)); + } + } +} diff --git a/source/BP-Essentials/Chat/Commands/Everyone/OnlinePlayers.cs b/source/BP-Essentials/Chat/Commands/Everyone/OnlinePlayers.cs index bba9047f..6b8b96f4 100644 --- a/source/BP-Essentials/Chat/Commands/Everyone/OnlinePlayers.cs +++ b/source/BP-Essentials/Chat/Commands/Everyone/OnlinePlayers.cs @@ -3,25 +3,16 @@ using System.Linq; using System.Text; using UnityEngine; -using static BP_Essentials.EssentialsVariablesPlugin; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.Variables; +using static BP_Essentials.HookMethods; namespace BP_Essentials.Commands { class OnlinePlayers { - public static void Run(SvPlayer player, string message) - { - var realPlayers = UnityEngine.Object.FindObjectsOfType().Count(shPlayer => !shPlayer.svPlayer.serverside); - switch (realPlayers) - { - case 1: - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"There is {realPlayers} player online"); - break; - default: - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"There are {realPlayers} players online"); - break; - } - } + public static void Run(SvPlayer player, string message) + { + player.SendChatMessage($"There are/is {PlayerList.Count} player(s) online"); + } } } diff --git a/source/BP-Essentials/Chat/Commands/Everyone/Pay.cs b/source/BP-Essentials/Chat/Commands/Everyone/Pay.cs index 6e9407e8..d9a82144 100644 --- a/source/BP-Essentials/Chat/Commands/Everyone/Pay.cs +++ b/source/BP-Essentials/Chat/Commands/Everyone/Pay.cs @@ -1,57 +1,52 @@ -using static BP_Essentials.EssentialsVariablesPlugin; +using static BP_Essentials.Variables; using System; using System.Linq; using UnityEngine; namespace BP_Essentials.Commands { - public class Pay - { - public static void Run(SvPlayer player, string message) - { - string CorrSyntax = $"" + GetArgument.Run(0, false, false, message) + $" [Player] [Amount] (Incorrect or missing argument(s).)"; - string arg1 = GetArgument.Run(1, false, true, message); - string arg2 = message.Split(' ').Last().Trim(); - if (String.IsNullOrEmpty(GetArgument.Run(1, false, false, message)) || String.IsNullOrEmpty(arg2)) - { - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, CorrSyntax); - return; - } - else - { - int lastIndex = arg1.LastIndexOf(" "); - if (lastIndex != -1) - arg1 = arg1.Remove(lastIndex).Trim(); - } - var isNumeric = int.TryParse(arg2, out int arg2Int); - if (isNumeric) - { - if (arg2Int <= 0) - { - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"Cannot transfer 0$."); - return; - } - foreach (var shPlayer in UnityEngine.Object.FindObjectsOfType()) - if (shPlayer.username == arg1 && !shPlayer.svPlayer.serverside || shPlayer.ID.ToString() == arg1.ToString() && !shPlayer.svPlayer.serverside) - foreach (var _shPlayer in UnityEngine.Object.FindObjectsOfType()) - if (_shPlayer.svPlayer == player && !_shPlayer.svPlayer.serverside) - { - if (_shPlayer.MyMoneyCount() >= arg2Int) - { - _shPlayer.TransferMoney(DeltaInv.RemoveFromMe, arg2Int, true); - shPlayer.TransferMoney(DeltaInv.AddToMe, arg2Int, true); - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"Successfully transfered {arg2Int}$ to {shPlayer.username}!"); - shPlayer.svPlayer.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"{player.playerData.username} gave you {arg2Int}$!"); - } - else - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"Cannot transfer money, do you have " + arg2Int + $"$ in your inventory?"); - return; - } + public class Pay + { + public static void Run(SvPlayer player, string message) + { + string correctSyntax = $"{GetArgument.Run(0, false, false, message)} [Player] [Amount] (Incorrect or missing argument(s).)"; + string arg1 = GetArgument.Run(1, false, true, message); + string arg2 = message.Split(' ').Last().Trim(); + if (string.IsNullOrEmpty(GetArgument.Run(1, false, false, message)) || string.IsNullOrEmpty(arg2)) + { + player.SendChatMessage(correctSyntax); + return; + } + int lastIndex = arg1.LastIndexOf(" ", StringComparison.CurrentCulture); + if (lastIndex != -1) + arg1 = arg1.Remove(lastIndex).Trim(); + var parsedSuccessfully = int.TryParse(arg2, out int arg2Int); + if (!parsedSuccessfully) + { + player.SendChatMessage(correctSyntax); + return; + } + if (arg2Int <= 0) + { + player.SendChatMessage($"Cannot transfer 0$ or less."); + return; + } + var currPlayer = GetShByStr.Run(arg1); + if (currPlayer == null) + { + player.SendChatMessage(NotFoundOnline); + return; + } - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, NotFoundOnline); - } - else - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, CorrSyntax); - } - } + if (player.player.MyMoneyCount() < arg2Int) + { + player.SendChatMessage($"Cannot transfer money, do you have {arg2Int}$ in your inventory?"); + return; + } + player.player.TransferMoney(DeltaInv.RemoveFromMe, arg2Int, true); + currPlayer.TransferMoney(DeltaInv.AddToMe, arg2Int, true); + player.SendChatMessage($"Successfully transfered {arg2Int}$ to {currPlayer.username}!"); + currPlayer.svPlayer.SendChatMessage($"{player.player.username} gave you {arg2Int}$!"); + } + } } diff --git a/source/BP-Essentials/Chat/Commands/Everyone/PmUser.cs b/source/BP-Essentials/Chat/Commands/Everyone/PmUser.cs index 3246c441..c3213da2 100644 --- a/source/BP-Essentials/Chat/Commands/Everyone/PmUser.cs +++ b/source/BP-Essentials/Chat/Commands/Everyone/PmUser.cs @@ -3,8 +3,8 @@ using System.Linq; using System.Text; using UnityEngine; -using static BP_Essentials.EssentialsVariablesPlugin; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.Variables; +using static BP_Essentials.HookMethods; namespace BP_Essentials.Commands { @@ -16,18 +16,18 @@ public static void Run(SvPlayer player, string message) string arg2 = GetArgument.Run(2, false, true, message); if (string.IsNullOrEmpty(arg1) || string.IsNullOrEmpty(arg2)) { - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, ArgRequired); + player.SendChatMessage(ArgRequired); return; } var shPlayer = GetShByStr.Run(arg1, true); if (shPlayer == null) { - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, NotFoundOnlineIdOnly); + player.SendChatMessage(NotFoundOnlineIdOnly); return; } - playerList[shPlayer.ID].ReplyToUser = player.player; - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"[PM] {shPlayer.username} > {arg2}"); - shPlayer.svPlayer.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"[PM] {player.player.username} < {arg2}"); + PlayerList[shPlayer.ID].ReplyToUser = player.player; + player.SendChatMessage($"[PM] {shPlayer.username} > {arg2}"); + shPlayer.svPlayer.SendChatMessage($"[PM] {player.player.username} < {arg2}"); } } } diff --git a/source/BP-Essentials/Chat/Commands/Everyone/ReplyUser.cs b/source/BP-Essentials/Chat/Commands/Everyone/ReplyUser.cs index 196eaa7e..45fe75df 100644 --- a/source/BP-Essentials/Chat/Commands/Everyone/ReplyUser.cs +++ b/source/BP-Essentials/Chat/Commands/Everyone/ReplyUser.cs @@ -3,8 +3,8 @@ using System.Linq; using System.Text; using UnityEngine; -using static BP_Essentials.EssentialsVariablesPlugin; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.Variables; +using static BP_Essentials.HookMethods; namespace BP_Essentials.Commands { @@ -12,21 +12,21 @@ class ReplyUser { public static void Run(SvPlayer player, string message) { - var replyUser = playerList[player.player.ID].ReplyToUser; + var replyUser = PlayerList[player.player.ID].ReplyToUser; if (replyUser == null || !IsOnline.Run(replyUser)) { - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"There is nobody to respond to. (User could've went offline.)"); + player.SendChatMessage($"There is nobody to respond to. (User could've went offline.)"); return; } string arg1 = GetArgument.Run(1, false, true, message); if (string.IsNullOrEmpty(arg1)) { - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, ArgRequired); + player.SendChatMessage(ArgRequired); return; } - - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"[PM] {replyUser.username} > {arg1}"); - replyUser.svPlayer.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"[PM] {player.player.username} < {arg1}"); + PlayerList[replyUser.ID].ReplyToUser = player.player; + player.SendChatMessage($"[PM] {replyUser.username} > {arg1}"); + replyUser.svPlayer.SendChatMessage($"[PM] {player.player.username} < {arg1}"); } } } diff --git a/source/BP-Essentials/Chat/Commands/Everyone/Report.cs b/source/BP-Essentials/Chat/Commands/Everyone/Report.cs index 63a8a2a6..07b22ce7 100644 --- a/source/BP-Essentials/Chat/Commands/Everyone/Report.cs +++ b/source/BP-Essentials/Chat/Commands/Everyone/Report.cs @@ -3,55 +3,48 @@ using System.Linq; using System.Text; using UnityEngine; -using static BP_Essentials.EssentialsVariablesPlugin; +using static BP_Essentials.Variables; namespace BP_Essentials.Commands { class Report { - public static void Run(SvPlayer player, string message) - { - string arg1 = GetArgument.Run(1, false, true, message); - if (!String.IsNullOrEmpty(arg1)) - { - foreach (KeyValuePair item in playerList) - if (item.Value.Shplayer.svPlayer == player) - { - if (item.Value.Shplayer.username != arg1) - { - if (!item.Value.Shplayer.admin) - { - bool playerfound = false; - foreach (var shPlayer in UnityEngine.Object.FindObjectsOfType()) - if (shPlayer.username == arg1 && !shPlayer.svPlayer.serverside || shPlayer.ID.ToString() == arg1 && !shPlayer.svPlayer.serverside) - { - playerfound = true; - if (!shPlayer.admin) - { - var builder = new StringBuilder(); - builder.Append("Reporting " + arg1 + "\nReason:\n\n"); - for (int i = 0; i < ReportReasons.Length; i++) - builder.Append("F" + (i + 2) + ": " + ReportReasons[i] + "\n"); - player.Send(SvSendType.Self, Channel.Reliable, ClPacket.ShowFunctionMenu, builder + "\nPress F11 To close this (G)UI"); - item.Value.LastMenu = CurrentMenu.Report; - item.Value.ReportedPlayer = shPlayer; - } - else - player.Send(SvSendType.Self, Channel.Reliable, ClPacket.GameMessage, $"Hey! You cannot report an admin."); - break; - } - if (!playerfound) - player.Send(SvSendType.Self, Channel.Reliable, ClPacket.GameMessage, NotFoundOnline); - } - else - player.Send(SvSendType.Self, Channel.Reliable, ClPacket.GameMessage, $"Hey! You cannot report as admin."); - } - else - player.Send(SvSendType.Self, Channel.Reliable, ClPacket.GameMessage, $"Hey! You cannot report yourself, dummy."); - } - } - else - player.Send(SvSendType.Self, Channel.Reliable, ClPacket.GameMessage, $"Missing argument! Correct syntax: {GetArgument.Run(0, false, false, message)} [player]"); - } + public static void Run(SvPlayer player, string message) + { + string arg1 = GetArgument.Run(1, false, true, message); + if (string.IsNullOrEmpty(arg1)) + { + player.Send(SvSendType.Self, Channel.Reliable, ClPacket.GameMessage, $"Missing argument! Correct syntax: {GetArgument.Run(0, false, false, message)} [player]"); + return; + } + var currPlayer = GetShByStr.Run(arg1); + if (currPlayer == null) + { + player.SendChatMessage(NotFoundOnline); + return; + } + if (currPlayer == player.player) + { + player.Send(SvSendType.Self, Channel.Reliable, ClPacket.GameMessage, $"Hey! You cannot report yourself, dummy."); + return; + } + if (player.player.admin) + { + player.Send(SvSendType.Self, Channel.Reliable, ClPacket.GameMessage, $"Hey! You cannot report as admin."); + return; + } + if (currPlayer.admin) + { + player.Send(SvSendType.Self, Channel.Reliable, ClPacket.GameMessage, $"Hey! You cannot report an admin."); + return; + } + var builder = new StringBuilder(); + builder.Append("Reporting " + arg1 + "\nReason:\n\n"); + for (int i = 0; i < ReportReasons.Length; i++) + builder.Append("F" + (i + 2) + ": " + ReportReasons[i] + "\n"); + player.Send(SvSendType.Self, Channel.Reliable, ClPacket.ShowFunctionMenu, builder + "\nPress F11 To close this (G)UI"); + PlayerList[player.player.ID].LastMenu = CurrentMenu.Report; + PlayerList[player.player.ID].ReportedPlayer = currPlayer; + } } } diff --git a/source/BP-Essentials/Chat/Commands/Everyone/ToggleChat.cs b/source/BP-Essentials/Chat/Commands/Everyone/ToggleChat.cs index 6c918789..fe33853e 100644 --- a/source/BP-Essentials/Chat/Commands/Everyone/ToggleChat.cs +++ b/source/BP-Essentials/Chat/Commands/Everyone/ToggleChat.cs @@ -3,8 +3,8 @@ using System.Linq; using System.Text; using UnityEngine; -using static BP_Essentials.EssentialsVariablesPlugin; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.Variables; +using static BP_Essentials.HookMethods; namespace BP_Essentials.Commands { @@ -12,23 +12,8 @@ class ToggleChat { public static void Run(SvPlayer player, string message) { - foreach (var player2 in playerList.Values) - { - if (player2.Shplayer.svPlayer == player) - { - if (player2.chatEnabled) - { - player2.chatEnabled = false; - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"Chat disabled."); - } - else - { - player2.chatEnabled = true; - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"Chat enabled."); - } - break; - } - } + PlayerList[player.player.ID].ChatEnabled = !PlayerList[player.player.ID].ChatEnabled; + player.SendChatMessage($"Chat {(PlayerList[player.player.ID].ChatEnabled ? "enabled" : "disabled")}."); } } } diff --git a/source/BP-Essentials/Chat/Commands/Everyone/TpaAccept.cs b/source/BP-Essentials/Chat/Commands/Everyone/TpaAccept.cs index 678a1307..273f9d7b 100644 --- a/source/BP-Essentials/Chat/Commands/Everyone/TpaAccept.cs +++ b/source/BP-Essentials/Chat/Commands/Everyone/TpaAccept.cs @@ -3,8 +3,8 @@ using System.Linq; using System.Text; using UnityEngine; -using static BP_Essentials.EssentialsVariablesPlugin; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.Variables; +using static BP_Essentials.HookMethods; namespace BP_Essentials.Commands { @@ -12,16 +12,16 @@ class TpaAccept { public static void Run(SvPlayer player, string message) { - var tpaUser = playerList[player.player.ID].TpaUser; + var tpaUser = PlayerList[player.player.ID].TpaUser; if (tpaUser == null || !IsOnline.Run(tpaUser)) { - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"There are no TPA accepts. (User could've went offline.)"); + player.SendChatMessage($"There are no TPA accepts. (User could've went offline.)"); return; } - tpaUser.svPlayer.SvReset(player.player.GetPosition(), player.player.GetRotation(), player.player.GetPlaceIndex()); - playerList[player.player.ID].TpaUser = null; - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"You accepted the TPA request of {tpaUser.username}."); - tpaUser.svPlayer.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"{player.player.username} Accepted your TPA request."); + tpaUser.svPlayer.ResetAndSavePosition(player.player.GetPosition(), player.player.GetRotation(), player.player.GetPlaceIndex()); + PlayerList[player.player.ID].TpaUser = null; + player.SendChatMessage($"You accepted the TPA request of {tpaUser.username}."); + tpaUser.svPlayer.SendChatMessage($"{player.player.username} Accepted your TPA request."); } } } diff --git a/source/BP-Essentials/Chat/Commands/Everyone/TpaDeny.cs b/source/BP-Essentials/Chat/Commands/Everyone/TpaDeny.cs index 4ad2b462..98eeba08 100644 --- a/source/BP-Essentials/Chat/Commands/Everyone/TpaDeny.cs +++ b/source/BP-Essentials/Chat/Commands/Everyone/TpaDeny.cs @@ -3,8 +3,8 @@ using System.Linq; using System.Text; using UnityEngine; -using static BP_Essentials.EssentialsVariablesPlugin; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.Variables; +using static BP_Essentials.HookMethods; namespace BP_Essentials.Commands { @@ -12,15 +12,15 @@ class TpaDeny { public static void Run(SvPlayer player, string message) { - var tpaUser = playerList[player.player.ID].TpaUser; + var tpaUser = PlayerList[player.player.ID].TpaUser; if (tpaUser == null || !IsOnline.Run(tpaUser)) { - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"There are no TPA accepts. (User could've went offline.)"); + player.SendChatMessage($"There are no TPA accepts. (User could've went offline.)"); return; } - playerList[player.player.ID].TpaUser = null; - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"You denied the TPA request of {tpaUser.username}."); - tpaUser.svPlayer.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"{player.player.username} Denied your TPA request."); + PlayerList[player.player.ID].TpaUser = null; + player.SendChatMessage($"You denied the TPA request of {tpaUser.username}."); + tpaUser.svPlayer.SendChatMessage($"{player.player.username} Denied your TPA request."); } } } diff --git a/source/BP-Essentials/Chat/Commands/Everyone/TpaUser.cs b/source/BP-Essentials/Chat/Commands/Everyone/TpaUser.cs index 98c237a5..dbbeaed9 100644 --- a/source/BP-Essentials/Chat/Commands/Everyone/TpaUser.cs +++ b/source/BP-Essentials/Chat/Commands/Everyone/TpaUser.cs @@ -3,8 +3,8 @@ using System.Linq; using System.Text; using UnityEngine; -using static BP_Essentials.EssentialsVariablesPlugin; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.Variables; +using static BP_Essentials.HookMethods; namespace BP_Essentials.Commands { @@ -15,18 +15,23 @@ public static void Run(SvPlayer player, string message) string arg1 = GetArgument.Run(1, false, true, message); if (string.IsNullOrEmpty(arg1)) { - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, ArgRequired); + player.SendChatMessage(ArgRequired); return; } var shPlayer = GetShByStr.Run(arg1); if (shPlayer == null) { - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, NotFoundOnline); + player.SendChatMessage(NotFoundOnline); return; } - playerList[shPlayer.ID].TpaUser = player.player; - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"Sent a TPA request to {shPlayer.username}."); - shPlayer.svPlayer.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"{player.player.username} sent you a tpa request. Type {CmdCommandCharacter}{CmdTpaaccept} to accept it."); + if (shPlayer == player.player) + { + player.SendChatMessage($"You cannot teleport to yourself."); + return; + } + PlayerList[shPlayer.ID].TpaUser = player.player; + player.SendChatMessage($"Sent a TPA request to {shPlayer.username}."); + shPlayer.svPlayer.SendChatMessage($"{player.player.username} sent you a tpa request. Type {CmdCommandCharacter}{CmdTpaaccept} to accept it."); } } } diff --git a/source/BP-Essentials/Chat/LangAndChatBlock.cs b/source/BP-Essentials/Chat/LangAndChatBlock.cs index 8f97ab29..53af6037 100644 --- a/source/BP-Essentials/Chat/LangAndChatBlock.cs +++ b/source/BP-Essentials/Chat/LangAndChatBlock.cs @@ -3,8 +3,8 @@ using System.Linq; using System.Text; using UnityEngine; -using static BP_Essentials.EssentialsVariablesPlugin; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.Variables; +using static BP_Essentials.HookMethods; using System.Text.RegularExpressions; namespace BP_Essentials.Chat @@ -13,6 +13,7 @@ class LangAndChatBlock { public static string Run(string message) { + // todo try { if (ChatBlock) diff --git a/source/BP-Essentials/Core.cs b/source/BP-Essentials/Core.cs new file mode 100644 index 00000000..c47288f9 --- /dev/null +++ b/source/BP-Essentials/Core.cs @@ -0,0 +1,84 @@ +/* + + + BP:Essentials + + Created by UserR00T, DBK, and BP. + Currently only being worked on by UserR00T unfortunately. :( + + License: GPLv3. + + +*/ + + +using System; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Threading; +using UnityEngine; +using static BP_Essentials.Variables; +namespace BP_Essentials +{ + public class Core + { + + //Initialization + [Hook("SvManager.StartServer")] + public static void StartServer(SvManager svManager) + { + Debug.Log("[INFO] Essentials - Starting up.."); + try + { + SvMan = svManager; + Methods.Utils.FunctionMenu.RegisterMenus(); + Reload.Run(true, null, true); + CheckAutoReloadFile.Run(AutoReloader); + if (Variables.Version != LocalVersion) + { + Debug.Log("[ERROR] Essentials - Versions do not match!"); + Debug.Log("[ERROR] Essentials - Essentials assembly version: " + Variables.Version); + Debug.Log("[ERROR] Essentials - Settings file version: " + LocalVersion); + Debug.Log(""); + Debug.Log(""); + Debug.Log("[ERROR] Essentials - Recreating settings file!"); + string date = DateTime.Now.ToString("yyyy_mm_dd_hh_mm_ss"); + if (File.Exists(SettingsFile + "." + date + ".OLD")) + File.Delete(SettingsFile + "." + date + ".OLD"); + File.Move(SettingsFile, $"{SettingsFile}.{date}.OLD"); + Reload.Run(true); + } + Save.StartSaveTimer(); + Variables.WarpHandler = new WarpHandler(); + Variables.WarpHandler.LoadAll(true); + Variables.KitsHandler = new KitsHandler(); + Variables.KitsHandler.LoadAll(true); + Debug.Log("-------------------------------------------------------------------------------"); + Debug.Log($"[INFO] Essentials - Version: {LocalVersion} {(IsPreRelease ? "[PRE-RELEASE] " : "")}Loaded in successfully!"); + Debug.Log("-------------------------------------------------------------------------------"); + } + catch (Exception ex) + { + Debug.Log("-------------------------------------------------------------------------------"); + Debug.Log(" "); + Debug.Log("[ERROR] Essentials - Whoopsie doopsie, something went wrong."); + Debug.Log("[ERROR] Essentials - Please check the error below for more info,"); + Debug.Log("[ERROR] Essentials - And it would be highly appreciated if you would send the error to the developers of this plugin!"); + Debug.Log(" "); + Debug.Log(ex); + Debug.Log(ex.ToString()); + Debug.Log("-------------------------------------------------------------------------------"); + + } + Debug.Log("[INFO] Essentials - Ready."); + + if (Variables.Announcer.Announcements.Count == 0) + { + Debug.Log($"{PlaceholderParser.ParseTimeStamp()} [WARNING] No announcements found in the file!"); + return; + } + Debug.Log($"{PlaceholderParser.ParseTimeStamp()} [INFO] Announcer started successfully!"); + } + } +} \ No newline at end of file diff --git a/source/BP-Essentials/ExtensionMethods.cs b/source/BP-Essentials/ExtensionMethods.cs new file mode 100644 index 00000000..4aafc9f5 --- /dev/null +++ b/source/BP-Essentials/ExtensionMethods.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading.Tasks; +using UnityEngine; +using static BP_Essentials.Variables; + +namespace BP_Essentials +{ + public static class ExtensionMethods + { + public static void SavePosition(this SvPlayer player) + { + player.SavePosition(player.player.GetPosition(), player.player.GetRotation(), player.player.GetPlaceIndex()); + } + public static void SavePosition(this SvPlayer player, Vector3 position, Quaternion rotation, int index) + { + if (!PlayerList.TryGetValue(player.player.ID, out var playerValue)) + return; + playerValue.LastLocation.Update(position, rotation, index); + } + public static void ResetAndSavePosition(this SvPlayer player, Vector3 position, Quaternion rotation, int index) + { + player.SavePosition(); + player.SvReset(position, rotation, index); + } + public static void ResetAndSavePosition(this SvPlayer player, SvPlayer targetPlayer) + { + player.SavePosition(); + player.SvReset(targetPlayer.player.GetPosition(), targetPlayer.player.GetRotation(), targetPlayer.player.GetPlaceIndex()); + } + + public static void SendChatMessage(this ShPlayer player, string message) => player.svPlayer.SendChatMessage(message); + public static void SendChatMessage(this SvPlayer player, string message) => player.SendGameMessage(SvSendType.Self, message); + public static void SendChatMessageToAll(this SvPlayer player, string message) => player.SendGameMessage(SvSendType.All, message); + public static void SendGameMessage(this SvPlayer player, SvSendType type, string message) => player.Send(type, Channel.Unsequenced, ClPacket.GameMessage, message); + + public static bool WillDieByDamage(this SvPlayer player, float damage) => (player.player.health - damage) <= 0; + + public static string FilterString(this string str) => new Regex("(<)").Replace(str, "<"); + + public static void CloseFunctionMenu(this SvPlayer player) => player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.CloseFunctionMenu); + public static void CloseAndResetFunctionMenu(this SvPlayer player) + { + player.CloseFunctionMenu(); + if (PlayerList.TryGetValue(player.player.ID, out var playerListItem)) + return; + playerListItem.LastMenu = CurrentMenu.None; + } + + } +} diff --git a/source/BP-Essentials/HookChat.cs b/source/BP-Essentials/HookChat.cs new file mode 100644 index 00000000..527a51b5 --- /dev/null +++ b/source/BP-Essentials/HookChat.cs @@ -0,0 +1,137 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.ComponentModel.Design.Serialization; +using System.Linq; +using System.Text.RegularExpressions; +using System.Threading; +using System.Threading.Tasks; +using UnityEngine; +using static BP_Essentials.HookMethods; +using static BP_Essentials.Variables; +namespace BP_Essentials +{ + public class HookChat + { + #region Event: ChatMessage | Global + //Chat Events + [Hook("SvPlayer.SvGlobalChatMessage")] + public static bool SvGlobalChatMessage(SvPlayer player, ref string message) + { + try + { + var tempMessage = message; + if (HandleSpam.Run(player, tempMessage)) + return true; + //Message Logging + if (!MutePlayers.Contains(player.playerData.username)) + LogMessage.Run(player, message); + + if (message.StartsWith(CmdCommandCharacter, StringComparison.CurrentCulture)) + if (OnCommand(player, ref message)) + return true; + + //Checks if the player is muted. + if (MutePlayers.Contains(player.playerData.username)) + { + player.SendChatMessage(SelfIsMuted); + return true; + } + //Checks if the message contains a username that is AFK. + if (AfkPlayers.Any(message.Contains)) + player.SendChatMessage(PlayerIsAFK); + + var shPlayer = player.player; + if (!PlayerList[shPlayer.ID].ChatEnabled) + { + player.SendChatMessage($"Please enable your chat again by typing {CmdCommandCharacter}{CmdToggleChat}."); + return true; + } + if (PlayerList[shPlayer.ID].StaffChatEnabled) + { + SendChatMessageToAdmins.Run(PlaceholderParser.ParseUserMessage(shPlayer, AdminChatMessage, message)); + return true; + } + foreach (var curr in Groups) + if (curr.Value.Users.Contains(player.playerData.username)) + { + SendChatMessage.Run(PlaceholderParser.ParseUserMessage(shPlayer, curr.Value.Message, message)); + return true; + } + if (player.player.admin) + { + SendChatMessage.Run(PlaceholderParser.ParseUserMessage(shPlayer, AdminMessage, message)); + return true; + } + SendChatMessage.Run(PlaceholderParser.ParseUserMessage(shPlayer, PlayerMessage, message)); + } + catch (Exception ex) + { + ErrorLogging.Run(ex); + } + return true; + } + #endregion + + #region Event OnCommand | Global + public static bool OnCommand(SvPlayer player, ref string message) + { + var tempMessage = message; + var command = GetArgument.Run(0, false, false, message); + // CustomCommands + var customCommand = CustomCommands.FirstOrDefault(x => tempMessage.StartsWith(CmdCommandCharacter + x.Command, StringComparison.CurrentCulture)); + if (customCommand != null) + { + foreach (string line in customCommand.Response.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None)) + player.SendChatMessage(PlaceholderParser.ParseUserMessage(player.player, line, message)); + PlayerList.Where(x => x.Value.SpyEnabled && x.Value.ShPlayer.svPlayer != player).ToList().ForEach(x => x.Value.ShPlayer.svPlayer.SendChatMessage($"[SPYCHAT] {player.playerData.username}: {tempMessage}")); + return true; + } + // Go through all registered commands and check if the command that the user entered matches + foreach (var cmd in CommandList.Values) + if (cmd.commandCmds.Contains(command)) + { + if (cmd.commandDisabled) + { + player.SendChatMessage(DisabledCommand); + return true; + } + if (HasPermission.Run(player, cmd.commandGroup, true, player.player.job.jobIndex) + && HasWantedLevel.Run(player, cmd.commandWantedAllowed) + && IsCuffed.Run(player, cmd.commandHandcuffedAllowed) + && IsJailed.Run(player, cmd.commandWhileJailedAllowed)) + { + PlayerList.Where(x => x.Value.SpyEnabled && x.Value.ShPlayer.svPlayer != player).ToList().ForEach(x => x.Value.ShPlayer.svPlayer.SendChatMessage($"[SPYCHAT] {player.playerData.username}: {tempMessage}")); + cmd.RunMethod.Invoke(player, message); + } + return true; + } + if (AfkPlayers.Contains(player.playerData.username)) + Commands.Afk.Run(player, message); + if (MsgUnknownCommand) + { + player.SendChatMessage($"Unknown command. Type {CmdCommandCharacter}essentials cmds for more info."); + return true; + } + return false; + } + #endregion + + #region Event: ChatMessage | Local + [Hook("SvPlayer.SvLocalChatMessage")] + public static bool SvLocalChatMessage(SvPlayer player, ref string message) + { + if (LocalChatMute && MutePlayers.Contains(player.playerData.username)) + { + player.SendChatMessage(SelfIsMuted); + return true; + } + LogMessage.LocalMessage(player, message); + if (!ProximityChat) + return false; + player.Send(SvSendType.LocalOthers, Channel.Unsequenced, ClPacket.GameMessage, $"[Local-Chat] {new Regex("(<)").Replace(player.player.username, "<")}: {new Regex("(<)").Replace(message, "<")}"); + return true; + } + #endregion + } +} \ No newline at end of file diff --git a/source/BP-Essentials/HookMethods.cs b/source/BP-Essentials/HookMethods.cs new file mode 100644 index 00000000..9ef55634 --- /dev/null +++ b/source/BP-Essentials/HookMethods.cs @@ -0,0 +1,308 @@ +using System; +using System.IO; +using System.Linq; +using System.Threading; +using UnityEngine; +using static BP_Essentials.Variables; +using System.Text.RegularExpressions; +using System.Collections.Generic; +using System.Text; +using System.Reflection; +using System.Threading.Tasks; + +namespace BP_Essentials +{ + public class HookMethods : Core + { + [Hook("SvPlayer.SvSellApartment")] + public static bool SvSellApartment(SvPlayer player) + { + player.SendChatMessage($"Are you sure you want to sell your apartment? Type '{CmdCommandCharacter}{CmdConfirm}' to confirm."); //softcode command + return true; + } + + [Hook("SvEntity.Initialize", true)] + public static void Initialize(SvEntity player) + { + if (player.serverside) + return; + var svPlayer = player as SvPlayer; + if (svPlayer == null) + return; + PlayerList.Add(svPlayer.player.ID, new PlayerListItem(svPlayer.player)); + Task.Run(() => + { + WriteIpToFile.Run(svPlayer); + CheckBanned.Run(svPlayer); + }); + } + + [Hook("SvPlayer.Destroy")] + public static void Destroy(SvPlayer player) + { + Debug.Log($"{PlaceholderParser.ParseTimeStamp()} [INFO] [LEAVE] {player.player.username}"); + if (!PlayerList.ContainsKey(player.player.ID)) + return; + PlayerList.Remove(player.player.ID); + } + + [Hook("SvPlayer.Damage")] + public static bool Damage(SvPlayer player, ref DamageIndex type, ref float amount, ref ShPlayer attacker, ref Collider collider) + { + if (CheckGodMode.Run(player, amount)) + return true; + if (player.WillDieByDamage(amount)) + OnDeath(player, ref type, ref amount, ref attacker, ref collider); + return false; + } + public static void OnDeath(SvPlayer player, ref DamageIndex type, ref float amount, ref ShPlayer attacker, ref Collider collider) + { + player.SavePosition(); + } + + [Hook("SvPlayer.SpawnBot")] + public static bool SpawnBot(SvPlayer player, ref Vector3 position, ref Quaternion rotation, ref Place place, ref Waypoint node, ref ShPlayer spawner, ref ShEntity mount, ref ShPlayer enemy) + { + return EnableBlockSpawnBot == true && BlockedSpawnIds.Contains(player.player.spawnJobIndex); + } + + [Hook("ShRestraint.HitEffect")] + public static bool HitEffect(ShRestraint player, ref ShEntity hitTarget, ref ShPlayer source, ref Collider collider) + { + if (!PlayerList.TryGetValue(hitTarget.ID, out var hitPlayer)) + return false; + if (!GodListPlayers.Contains(hitPlayer.ShPlayer.username)) + return false; + hitPlayer.ShPlayer.svPlayer.SendChatMessage("Being handcuffed Blocked!"); + return true; + } + + [Hook("SvPlayer.SvBan")] + public static bool SvBan(SvPlayer player, ref int otherID) + { + if (player.player.admin) + return true; + if (BlockBanButtonTabMenu) + { + player.SendChatMessage($"This button has been disabled. Please use the ban commands. ID: {otherID}"); + return true; + } + var targetPlayer = player.entity.manager.FindByID(otherID); + if (!targetPlayer || targetPlayer.svPlayer.serverside) + { + player.SendChatMessage("Cannot ban NPC"); + return true; + } + LogMessage.LogOther($"{PlaceholderParser.ParseTimeStamp()} [INFO] {targetPlayer.username} Got banned by {player.playerData.username}"); + player.Send(SvSendType.All, Channel.Unsequenced, ClPacket.GameMessage, $"{targetPlayer.username} Just got banned by {player.player.username}"); + SendDiscordMessage.BanMessage(targetPlayer.username, player.playerData.username); + player.svManager.AddBanned(targetPlayer); + player.svManager.Disconnect(targetPlayer.svPlayer.connection, DisconnectTypes.Banned); + return true; + } + + [Hook("SvPlayer.SvStartVote")] + public static bool SvStartVote(SvPlayer player, ref byte voteIndex, ref int ID) + { + switch (voteIndex) + { + case VoteIndex.Mission: + if (!BlockMissions) + return false; + player.SendChatMessage($"All missions have been disabled on this server."); + return true; + case VoteIndex.Kick: + if (VoteKickDisabled) + { + player.SendChatMessage($"Vote kicking has been disabled on this server."); + return true; + } + if (!PlayerList.TryGetValue(ID, out var shPlayer)) + return true; + if (player.svManager.vote != null || voteIndex >= player.player.manager.votes.Length || player.svManager.startedVote.OverLimit(player.player)) + return true; + player.svManager.startedVote.Add(player.player); + player.svManager.vote = player.player.manager.votes[voteIndex]; + if (!player.svManager.vote.CheckVote(ID)) + player.svManager.vote = null; + player.Send(SvSendType.All, Channel.Reliable, 60, voteIndex, ID); + player.svManager.StartCoroutine(player.svManager.StartVote()); + Debug.Log($"{PlaceholderParser.ParseTimeStamp()} [INFO] {player.playerData.username} Has issued a votekick against {player.player.username}"); + player.Send(SvSendType.All, Channel.Unsequenced, ClPacket.GameMessage, $"{player.playerData.username} Has issued a vote kick against {shPlayer.ShPlayer.username}"); + LatestVotePeople.Clear(); + return true; + default: + return false; + } + } + + [Hook("SvPlayer.SvVoteYes", true)] + public static void SvVoteYes(SvPlayer player) + { + LatestVotePeople.Add(player.playerData.username); + } + + [Hook("SvPlayer.SvFunctionKey")] + public static bool SvFunctionKey(SvPlayer player, ref byte key) + { + var lastMenu = PlayerList[player.player.ID].LastMenu; + if (lastMenu == CurrentMenu.Report && key > 1 && key < 11) + { + PlayerList[player.player.ID].LastMenu = Methods.Utils.FunctionMenu.ReportMenu(player, key); + return true; + } + if (key == 11) + { + player.CloseFunctionMenu(); + PlayerList[player.player.ID].LastMenu = CurrentMenu.None; + return true; + } + if (!FunctionMenuKeys.TryGetValue(key, lastMenu, out var method)) + return true; + PlayerList[player.player.ID].LastMenu = method.Invoke(player); + return true; + } + + [Hook("SvPlayer.SvSuicide")] + public static bool SvSuicide(SvPlayer player) + { + var shPlayer = player.player; + if (!BlockSuicide) + return false; + player.SendChatMessage($"You cannot suicide on this server because the server owner disabled it."); + return true; + } + [Hook("SvPlayer.SvGetJob")] + public static bool SvGetJob(SvPlayer player, ref int employerID) + { + try + { + var shPlayer = player.player; + var shEmployer = shPlayer.manager.FindByID(employerID); + if (!WhitelistedJobs.ContainsKey(shEmployer.job.jobIndex)) + return false; + if (HasPermission.Run(player, WhitelistedJobs[shEmployer.job.jobIndex], false, shPlayer.job.jobIndex)) + return false; + player.SendChatMessage(MsgNoPermJob); + return true; + } + catch (Exception ex) + { + ErrorLogging.Run(ex); + return false; + } + } + [Hook("SvPlayer.SvAddCrime")] + public static bool SvAddCrime(SvPlayer player, ref byte crimeIndex, ref ShEntity victim) + { + try + { + if (GodModeLevel >= 1 && CheckGodMode.Run(player, null, "Blocked crime and losing EXP!")) + return true; + } + catch (Exception ex) + { + ErrorLogging.Run(ex); + } + return false; + } + [Hook("ShPlayer.TransferItem")] + public static bool TransferItem(ShPlayer player, ref byte deltaType, ref int itemIndex, ref int amount, ref bool dispatch) + { + try + { + if (player != null && BlockedItems.Count > 0 && BlockedItems.Contains(itemIndex)) + { + player.svPlayer.SendChatMessage(BlockedItemMessage); + return true; + } + } + catch (Exception ex) + { + ErrorLogging.Run(ex); + } + return false; + } + + + [Hook("ShPlayer.RemoveItemsDeath")] + public static bool RemoveItemsDeath(ShPlayer player) + { + if (!blockLicenseRemoved) + return false; + foreach (InventoryItem inventoryItem in player.myItems.Values.ToArray()) + { + if (blockLicenseRemoved && inventoryItem.item.name.StartsWith("License", StringComparison.CurrentCulture)) + continue; + int extraCount = GetExtraCount.Run(player, inventoryItem); + if (extraCount > 0) + { + var shWearable = inventoryItem.item as ShWearable; + if (!shWearable || shWearable.illegal || player.curWearables[(int)shWearable.type].index != shWearable.index) + player.TransferItem(2, inventoryItem.item.index, extraCount, true); + } + } + if (blockLicenseRemoved) + player.svPlayer.SendChatMessage($"This server disabled losing licenses on death."); + return true; + } + [Hook("SvPlayer.SvPlaceInJail")] + public static bool SvPlaceInJail(SvPlayer player, ref int criminalID) + { + var shPlayer = player.player; + if (shPlayer.manager.jail && shPlayer.job is Police) + { + var crimShPlayer = player.entity.manager.FindByID(criminalID); + if (!crimShPlayer) + return true; + if ((player.serverside || crimShPlayer.DistanceSqr(player.player.manager.jail) < 14400f) && + crimShPlayer.IsRestrained() && !crimShPlayer.IsDead() && !(crimShPlayer.job is Prisoner)) + { + var jailTime = 0f; + var fine = 0; + foreach (var offense in crimShPlayer.offenses) + { + jailTime += offense.GetCrime().jailtime; + fine += offense.GetCrime().fine; + } + SendToJail.Run(crimShPlayer, jailTime); + if (fine > 0) + player.Reward(3, fine); + if (ShowJailMessage && !crimShPlayer.svPlayer.serverside && player.serverside) + player.Send(SvSendType.All, Channel.Unsequenced, ClPacket.GameMessage, $"{player.player.username} sent {crimShPlayer.username} to jail{(fine > 0 ? $" for a fine of ${fine}" : ".")}"); + return true; + } + player.SendChatMessage("Confirm criminal is cuffed and near jail"); + } + return true; + } + [Hook("SvPlayer.SvTimescale")] + public static bool SvTimescale(SvPlayer player, ref float timescale) + { + if (!player.player.admin) + return true; + if (TimescaleDisabled) + { + player.SendChatMessage($"You cannot set the timescale because the server owner disabled this."); + return true; + } + Debug.Log($"{PlaceholderParser.ParseTimeStamp()} [INFO] {player.player.username} set the timescale to {timescale}"); + return false; + } + /* + [Hook("ShFurniture.HitCheck")] + public static void HitCheck(ShFurniture shFurniture, ref RaycastHit hit) + { + if (!shFurniture.player.InOwnApartment()) + { + if (shFurniture.player.IsClientMain()) + { + shFurniture.manager.clManager.ShowGameMessage("Must place in your apartment lol sike"); + } + //return false; + } + //return shFurniture.HitCheck(ref hit); + } + */ + } +} \ No newline at end of file diff --git a/source/BP-Essentials/Methods/Check/CheckBanned.cs b/source/BP-Essentials/Methods/Check/CheckBanned.cs index d984973b..4c795445 100644 --- a/source/BP-Essentials/Methods/Check/CheckBanned.cs +++ b/source/BP-Essentials/Methods/Check/CheckBanned.cs @@ -3,35 +3,34 @@ using System.Linq; using System.Text; using UnityEngine; -using static BP_Essentials.EssentialsVariablesPlugin; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.Variables; +using static BP_Essentials.HookMethods; using System.Threading; using System.IO; namespace BP_Essentials { - class CheckBanned : EssentialsCorePlugin + class CheckBanned : Core { public static void Run(SvPlayer player) { if (CheckBannedEnabled) { - try - { - Thread.Sleep(3000); - if (!player.player.admin && !string.IsNullOrEmpty(player.connection.IP.Trim())) - foreach (var line in File.ReadAllLines(BansFile)) - if (line.StartsWith("# "+player.playerData.username)) - { - Debug.Log($"{SetTimeStamp.Run()}[WARNING] {player.player.username} Joined while banned! IP: {player.connection.IP}"); - player.svManager.AddBanned(player.player); - player.svManager.Disconnect(player.connection); - } - } - catch (Exception ex) - { - ErrorLogging.Run(ex); - } + try + { + if (player.player.admin || string.IsNullOrEmpty(player.connection.IP.Trim())) + return; + foreach (var line in File.ReadAllLines(BansFile)) + if (string.IsNullOrEmpty(line) || !line.StartsWith("# " + player.player.username, StringComparison.CurrentCulture)) + continue; + Debug.Log($"{PlaceholderParser.ParseTimeStamp()} [WARNING] {player.player.username} Joined while banned! IP: {player.connection.IP}"); + player.svManager.AddBanned(player.player); + player.svManager.Disconnect(player.connection, DisconnectTypes.Banned); + } + catch (Exception ex) + { + ErrorLogging.Run(ex); + } } } } diff --git a/source/BP-Essentials/Methods/Check/CheckGodMode.cs b/source/BP-Essentials/Methods/Check/CheckGodMode.cs index eb02ed3e..861ff6c9 100644 --- a/source/BP-Essentials/Methods/Check/CheckGodMode.cs +++ b/source/BP-Essentials/Methods/Check/CheckGodMode.cs @@ -3,12 +3,12 @@ using System.Linq; using System.Text; using UnityEngine; -using static BP_Essentials.EssentialsVariablesPlugin; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.Variables; +using static BP_Essentials.HookMethods; namespace BP_Essentials { - class CheckGodMode : EssentialsCorePlugin + class CheckGodMode : Core { public static bool Run(SvPlayer player, float? amount = null, string customMessage = null) { @@ -17,9 +17,9 @@ public static bool Run(SvPlayer player, float? amount = null, string customMessa if (GodListPlayers.Contains(player.playerData.username)) { if (amount != null && ShowDMGMessage) - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"{amount} DMG Blocked!"); + player.SendChatMessage($"{amount} DMG Blocked!"); if (customMessage != null) - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, customMessage); + player.SendChatMessage(customMessage); return true; } } diff --git a/source/BP-Essentials/Methods/FileHandler/CheckAutoReloadFile.cs b/source/BP-Essentials/Methods/FileHandler/CheckAutoReloadFile.cs index ba71412f..d9980aa0 100644 --- a/source/BP-Essentials/Methods/FileHandler/CheckAutoReloadFile.cs +++ b/source/BP-Essentials/Methods/FileHandler/CheckAutoReloadFile.cs @@ -21,12 +21,12 @@ public static void Run(string file) | NotifyFilters.FileName | NotifyFilters.DirectoryName, EnableRaisingEvents = true }; - watcher.Changed += new FileSystemEventHandler((sender, e) => - { - Debug.Log($"{SetTimeStamp.Run()}[INFO] Found a change in file {file}, reloading all files..."); - Debug.Log(" "); - Reload.Run(true); - }); + watcher.Changed += (sender, e) => + { + Debug.Log($"{PlaceholderParser.ParseTimeStamp()} [INFO] Found a change in file {file}, reloading all files..."); + Debug.Log(" "); + Reload.Run(true); + }; } catch (Exception ex) { diff --git a/source/BP-Essentials/Methods/FileHandler/CheckFiles.cs b/source/BP-Essentials/Methods/FileHandler/CheckFiles.cs index a2f63229..32e9be26 100644 --- a/source/BP-Essentials/Methods/FileHandler/CheckFiles.cs +++ b/source/BP-Essentials/Methods/FileHandler/CheckFiles.cs @@ -3,8 +3,8 @@ using System.Linq; using System.Text; using UnityEngine; -using static BP_Essentials.EssentialsVariablesPlugin; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.Variables; +using static BP_Essentials.HookMethods; using System.IO; namespace BP_Essentials @@ -15,10 +15,11 @@ public static void Run() { try { - // this really needs some improvement - // I don't know when I added that comment but seriously I should really redo this method.. whenever I have time - // Every time I have to change something in this file it reminds me again that I should change this somehow.. I just don't know how. - if (!Directory.Exists(FileDirectory)) + // this really needs some improvement + // I don't know when I added that comment but seriously I should really redo this method.. whenever I have time + // Every time I have to change something in this file it reminds me again that I should change this somehow.. I just don't know how. + // lol yup still here.. fuck. + if (!Directory.Exists(FileDirectory)) { Directory.CreateDirectory(FileDirectory); Debug.Log(FileDirectory + " Does not exist! Creating one."); diff --git a/source/BP-Essentials/Methods/FileHandler/CreateFile.cs b/source/BP-Essentials/Methods/FileHandler/CreateFile.cs index 30b6889f..429fceaa 100644 --- a/source/BP-Essentials/Methods/FileHandler/CreateFile.cs +++ b/source/BP-Essentials/Methods/FileHandler/CreateFile.cs @@ -3,8 +3,8 @@ using System.Linq; using System.Text; using UnityEngine; -using static BP_Essentials.EssentialsVariablesPlugin; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.Variables; +using static BP_Essentials.HookMethods; using System.IO; namespace BP_Essentials @@ -19,32 +19,30 @@ public static void Run(string fileName) { case SettingsFile: { - if (isPreRelease) - GetWebsiteContent.WriteToFile(SettingsFile, "http://www.UserR00T.com/dev/BPEssentials/settings_test.txt"); + if (IsPreRelease) + GetWebsiteContent.WriteToFile(SettingsFile, "http://www.UserR00T.com/dev/BPEssentials/settings_test.json"); else - GetWebsiteContent.WriteToFile(SettingsFile, "http://www.UserR00T.com/dev/BPEssentials/settings.txt"); + GetWebsiteContent.WriteToFile(SettingsFile, "http://www.UserR00T.com/dev/BPEssentials/settings.json"); break; } case ChatBlockFile: { - string[] content = { "nigger", "nigga", "nigg3r", "NIGGER", "NI99ER", "ni99er", "nigger.", "nigga.", "nigg3r.", "N199ER", "n1gger", "N1GGER", "NIGGA", "NIGGA." }; - File.WriteAllLines(ChatBlockFile, content); + File.WriteAllText(ChatBlockFile, ""); break; } case LanguageBlockFile: { - string[] content = { "bombas", "hola", "alguien", "habla", "espanol", "español", "estoy", "banco", "voy", "consegi", "donde", "quedamos", "banko", "afuera", "estas", "alguem", "donde", "nos", "vemos", "soy ", "vueno", "como", "carro", "cabros", "miren", "hacha", "laar", "corri", "sacame", "aqui", "policia", "trajo", "encerro", "bomba", "beuno", "pantalones", "dinero", "porque", "tengo", "escopetaa", "escopeta" }; - File.WriteAllLines(LanguageBlockFile, content); + File.WriteAllText(LanguageBlockFile, ""); break; } case CustomCommandsFile: { - GetWebsiteContent.WriteToFile(CustomCommandsFile, "http://www.UserR00T.com/dev/BPEssentials/customcommands.txt"); + GetWebsiteContent.WriteToFile(CustomCommandsFile, "http://www.UserR00T.com/dev/BPEssentials/customcommands.json"); break; } case CustomGroupsFile: { - GetWebsiteContent.WriteToFile(CustomGroupsFile, "http://www.UserR00T.com/dev/BPEssentials/customgroups.txt"); + GetWebsiteContent.WriteToFile(CustomGroupsFile, "http://www.UserR00T.com/dev/BPEssentials/customgroups.json"); break; } diff --git a/source/BP-Essentials/Methods/FileHandler/ExpandableFileHandler.cs b/source/BP-Essentials/Methods/FileHandler/ExpandableFileHandler.cs new file mode 100644 index 00000000..02f22ee8 --- /dev/null +++ b/source/BP-Essentials/Methods/FileHandler/ExpandableFileHandler.cs @@ -0,0 +1,132 @@ +using Newtonsoft.Json; +using System; +using System.Collections; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UnityEngine; +using static BP_Essentials.Variables; + +namespace BP_Essentials.Methods.FileHandler +{ + public interface IExpandableFile + { + string Name { get; set; } + string ExecutableBy { get; set; } + bool Disabled { get; set; } + } + public interface IExpandableFileDelayable + { + int Delay { get; set; } + Dictionary CurrentlyInCooldown { get; set; } + } + public interface IExpandableFileHasPrice + { + int Price { get; set; } + } + public abstract class ExpandableFileHandler where JsonType : class, IExpandableFile, new() + { + protected ExpandableFileHandler() + { + if (IsInitialized) + return; + StartTimer(); + IsInitialized = true; + } + public string FileExtension { get; set; } = "json"; + public string FilesDirectory { get; set; } + public bool IsInitialized { get; private set; } + public List List { get; private set; } = new List(); + public string Name { get; set; } + public System.Timers.Timer Timer { get; private set; } = new System.Timers.Timer(); + + public virtual void CreateNew(JsonType obj, string fileName) + { + var filePath = Path.Combine(FilesDirectory, $"{fileName}.{FileExtension}"); + File.WriteAllText(filePath, JsonConvert.SerializeObject(obj, Formatting.Indented)); + List.Add(obj); + } + public virtual void DeleteExisting(string fileName, string name = null) + { + var filePath = Path.Combine(FileDirectory, $"{fileName}.{FileExtension}"); + File.Delete(filePath); + List = List.Where(x => x.Name != (name ?? fileName)).ToList(); + } + public virtual void LoadAll(bool initCooldown = false) + { + if (DebugLevel >= 1) + Debug.Log($"{PlaceholderParser.ParseTimeStamp()} [INFO] Loading {Name}s.."); + List.Clear(); + foreach (string file in Directory.EnumerateFiles(FilesDirectory, $"*.{FileExtension}", SearchOption.AllDirectories)) + { + var obj = JsonConvert.DeserializeObject(FilterComments.Run(file)); + if (List.Any(x => x.Name == obj.Name)) + { + Debug.Log($"{PlaceholderParser.ParseTimeStamp()} [ERROR] Cannot add {Name} {obj.Name} because it already exists in the list!"); + continue; + } + List.Add(obj); + if (initCooldown) + SetupDelayable(obj); + if (DebugLevel >= 1) + Debug.Log($"{PlaceholderParser.ParseTimeStamp()} [INFO] Loaded {Name}: {obj.Name}"); + } + if (DebugLevel >= 1) + Debug.Log($"{PlaceholderParser.ParseTimeStamp()} [INFO] Loaded in {List.Count} {Name}(s)."); + } + public virtual IEnumerator StartCooldown(string username, JsonType obj, int _passedTime = 0) + { + if (!(obj is IExpandableFileDelayable objDelayable)) + yield break; + if (!objDelayable.CurrentlyInCooldown.ContainsKey(username)) + objDelayable.CurrentlyInCooldown.Add(username, objDelayable.Delay); + var path = Path.Combine(WarpDirectory, $"{obj.Name}.json"); + var passedTime = _passedTime; + while (passedTime < objDelayable.Delay) + { + ++passedTime; + --objDelayable.CurrentlyInCooldown[username]; + yield return new WaitForSecondsRealtime(1); + } + if (objDelayable.CurrentlyInCooldown.ContainsKey(username)) + objDelayable.CurrentlyInCooldown.Remove(username); + if (File.Exists(path)) + File.WriteAllText(path, JsonConvert.SerializeObject(obj, Formatting.Indented)); + } + + void SetupDelayable(JsonType obj) + { + if (!(obj is IExpandableFileDelayable objDelayable)) + return; + foreach (var player in objDelayable.CurrentlyInCooldown.ToList()) + { + if (player.Value <= 0) + continue; + SvMan.StartCoroutine(StartCooldown(player.Key, obj, player.Value)); + } + } + void StartTimer() + { + try + { + Timer.Elapsed += (sender, e) => + { + foreach (var item in List) + { + var path = Path.Combine(FilesDirectory, $"{item.Name}.json"); + if (File.Exists(path)) + File.WriteAllText(path, JsonConvert.SerializeObject(item, Formatting.Indented)); + } + }; + Timer.Interval = 10 * 60 * 1000; // Save every 10 minutes + Timer.Enabled = true; + } + catch (Exception ex) + { + ErrorLogging.Run(ex); + } + } + } +} diff --git a/source/BP-Essentials/Methods/FileHandler/KitsHandler.cs b/source/BP-Essentials/Methods/FileHandler/KitsHandler.cs new file mode 100644 index 00000000..f2b36e00 --- /dev/null +++ b/source/BP-Essentials/Methods/FileHandler/KitsHandler.cs @@ -0,0 +1,38 @@ +using BP_Essentials.Methods.FileHandler; +using Newtonsoft.Json; +using System; +using System.Collections; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using UnityEngine; +using static BP_Essentials.Variables; + +namespace BP_Essentials +{ + public class KitsHandler : ExpandableFileHandler + { + public KitsHandler() + { + Name = "kit"; + FileExtension = "json"; + FilesDirectory = KitDirectory; + } + public class JsonModel : IExpandableFile, IExpandableFileDelayable, IExpandableFileHasPrice + { + public string Name { get; set; } + public string ExecutableBy { get; set; } + public bool Disabled { get; set; } + public int Price { get; set; } + public int Delay { get; set; } + public List Items { get; set; } = new List(); + public Dictionary CurrentlyInCooldown { get; set; } = new Dictionary(); + } + public class Kits_Item + { + public int Id { get; set; } + public int Amount { get; set; } + } + } +} diff --git a/source/BP-Essentials/Methods/FileHandler/ReadCustomCommands.cs b/source/BP-Essentials/Methods/FileHandler/ReadCustomCommands.cs index 83b56bcb..5d9b832c 100644 --- a/source/BP-Essentials/Methods/FileHandler/ReadCustomCommands.cs +++ b/source/BP-Essentials/Methods/FileHandler/ReadCustomCommands.cs @@ -3,8 +3,8 @@ using System.Linq; using System.Text; using UnityEngine; -using static BP_Essentials.EssentialsVariablesPlugin; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.Variables; +using static BP_Essentials.HookMethods; using System.IO; using Newtonsoft.Json; diff --git a/source/BP-Essentials/Methods/FileHandler/ReadFile.cs b/source/BP-Essentials/Methods/FileHandler/ReadFile.cs index abe2f555..1cc3dfa6 100644 --- a/source/BP-Essentials/Methods/FileHandler/ReadFile.cs +++ b/source/BP-Essentials/Methods/FileHandler/ReadFile.cs @@ -3,10 +3,11 @@ using System.Linq; using System.Text; using UnityEngine; -using static BP_Essentials.EssentialsVariablesPlugin; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.Variables; +using static BP_Essentials.HookMethods; using System.IO; using Newtonsoft.Json; +using BP_Essentials.Chat; /* The biggest nonsense method is here. */ @@ -34,28 +35,31 @@ public class _General public bool BlockBanButtonTabMenu { get; set; } public bool BlockLicenseRemoved { get; set; } public int MessagesAllowedPerSecond { get; set; } - public string WipePassword { get; set; } + public int TimeBetweenDelay { get; set; } + public string WipePassword { get; set; } } - [Serializable] - public class _Messages - { - public string NoPerm { get; set; } - public string DisabledCommand { get; set; } - public string MsgSayPrefix { get; set; } - public string DiscordLink { get; set; } - public string PlayerIsAFK { get; set; } - public string SelfIsMuted { get; set; } - public string ArgRequired { get; set; } - public string NotFoundOnline { get; set; } - public string NotFoundOnlineIdOnly { get; set;} - public string AdminSearchingInv { get; set; } - public string PlayerMessage { get; set; } - public string AdminMessage { get; set; } - public string AdminChatMessage { get; set; } - public string MsgNoPermJob { get; set; } - public string BlockedItem { get; set; } - public string MsgNoWantedAllowed { get; set; } - public string MsgNoCuffedAllowed { get; set; } + [Serializable] + public class _Messages + { + public string NoPerm { get; set; } + public string DisabledCommand { get; set; } + public string MsgSayPrefix { get; set; } + public string DiscordLink { get; set; } + public string PlayerIsAFK { get; set; } + public string SelfIsMuted { get; set; } + public string ArgRequired { get; set; } + public string NotFoundOnline { get; set; } + public string NotFoundOnlineIdOnly { get; set; } + public string AdminSearchingInv { get; set; } + public string PlayerMessage { get; set; } + public string AdminMessage { get; set; } + public string AdminChatMessage { get; set; } + public string MsgNoPermJob { get; set; } + public string BlockedItem { get; set; } + public string MsgNoWantedAllowed { get; set; } + public string MsgNoCuffedAllowed { get; set; } + public string MsgNoJailAllowed { get; set; } + public string MeMessage { get; set; } } [Serializable] public class MessageColors @@ -109,7 +113,6 @@ public class _Misc { public bool EnableChatBlock { get; set; } public bool EnableLanguageBlock { get; set; } - public bool CheckForAlts { get; set; } public bool CheckBannedEnabled { get; set; } public int TimeBetweenAnnounce { get; set; } public string BlockSpawnBot { get; set; } @@ -120,7 +123,9 @@ public class _Misc public bool BlockMissions { get; set; } public bool ProximityChat { get; set; } public bool LocalChatMute { get; set; } - } + public bool LocalChatMe { get; set; } + public bool TimescaleDisabled { get; set; } + } [Serializable] public class WhitelistedJob { @@ -136,7 +141,8 @@ public class _Command public bool? Disabled { get; set; } public bool? AllowWithCrimes { get; set; } public bool? AllowWhileCuffed { get; set; } - } + public bool? AllowWhileJailed { get; set; } + } [Serializable] public class __RootObject { @@ -171,133 +177,137 @@ public static void Run(string fileName) try { IdListObject idlist; - switch (fileName) - { - case SettingsFile: - __RootObject m = JsonConvert.DeserializeObject<__RootObject>(FilterComments.Run(SettingsFile)); + switch (fileName) + { + case SettingsFile: + __RootObject m = JsonConvert.DeserializeObject<__RootObject>(FilterComments.Run(SettingsFile)); - LocalVersion = m.General.Version; - CmdCommandCharacter = m.General.CommandCharacter; - DownloadIdList = m.General.DownloadIDList; - TimestampFormat = m.General.TimestapFormat; - MsgSayColor = m.General.MsgSayColor; - MsgUnknownCommand = m.General.DisplayUnknownCommandMessage; - VoteKickDisabled = m.General.VoteKickDisabled; - ShowDMGMessage = m.General.ShowDMGMessage; - DebugLevel = m.General.DebugLevel; - EnableDiscordWebhook_Ban = m.General.EnableDiscordWebhook_Ban; - if (EnableDiscordWebhook_Ban && string.IsNullOrEmpty(m.General.DiscordWebhook_Ban.Trim())) - { - Debug.Log("[ERROR] Discord webhook_Ban is empty but EnableDiscordWebhook_Ban is true! Disabling webhook_Ban."); - EnableDiscordWebhook_Ban = false; - } - else - DiscordWebhook_Ban = m.General.DiscordWebhook_Ban; - EnableDiscordWebhook_Report = m.General.EnableDiscordWebhook_Report; - if (EnableDiscordWebhook_Report && string.IsNullOrEmpty(m.General.DiscordWebhook_Report.Trim())) - { - Debug.Log("[ERROR] Discord webhook_Report is empty but EnableDiscordWebhook_Report is true! Disabling webhook_Report."); - EnableDiscordWebhook_Report = false; - } - else - DiscordWebhook_Report = m.General.DiscordWebhook_Report; - BlockBanButtonTabMenu = m.General.BlockBanButtonTabMenu; - blockLicenseRemoved = m.General.BlockLicenseRemoved; - MessagesAllowedPerSecond = m.General.MessagesAllowedPerSecond; - WipePassword = m.General.WipePassword; + LocalVersion = m.General.Version; + CmdCommandCharacter = m.General.CommandCharacter; + DownloadIdList = m.General.DownloadIDList; + TimestampFormat = m.General.TimestapFormat; + MsgSayColor = m.General.MsgSayColor; + MsgUnknownCommand = m.General.DisplayUnknownCommandMessage; + VoteKickDisabled = m.General.VoteKickDisabled; + ShowDMGMessage = m.General.ShowDMGMessage; + DebugLevel = m.General.DebugLevel; + EnableDiscordWebhook_Ban = m.General.EnableDiscordWebhook_Ban; + if (EnableDiscordWebhook_Ban && string.IsNullOrEmpty(m.General.DiscordWebhook_Ban.Trim())) + { + Debug.Log("[ERROR] Discord webhook_Ban is empty but EnableDiscordWebhook_Ban is true! Disabling webhook_Ban."); + EnableDiscordWebhook_Ban = false; + } + else + DiscordWebhook_Ban = m.General.DiscordWebhook_Ban; + EnableDiscordWebhook_Report = m.General.EnableDiscordWebhook_Report; + if (EnableDiscordWebhook_Report && string.IsNullOrEmpty(m.General.DiscordWebhook_Report.Trim())) + { + Debug.Log("[ERROR] Discord webhook_Report is empty but EnableDiscordWebhook_Report is true! Disabling webhook_Report."); + EnableDiscordWebhook_Report = false; + } + else + DiscordWebhook_Report = m.General.DiscordWebhook_Report; + BlockBanButtonTabMenu = m.General.BlockBanButtonTabMenu; + blockLicenseRemoved = m.General.BlockLicenseRemoved; + MessagesAllowedPerSecond = m.General.MessagesAllowedPerSecond; + TimeBetweenDelay = m.General.TimeBetweenDelay; + WipePassword = m.General.WipePassword; - infoColor = m.MessageColors.Info; - errorColor = m.MessageColors.Error; - warningColor = m.MessageColors.Warning; - argColor = m.MessageColors.Arg; + infoColor = m.MessageColors.Info; + errorColor = m.MessageColors.Error; + warningColor = m.MessageColors.Warning; + argColor = m.MessageColors.Arg; - MsgNoPerm = m.Messages.NoPerm; - MsgDiscord = m.Messages.DiscordLink; - MsgSayPrefix = m.Messages.MsgSayPrefix; - DisabledCommand = $"{m.Messages.DisabledCommand}"; - PlayerIsAFK = $"{m.Messages.PlayerIsAFK}"; - SelfIsMuted = $"{m.Messages.SelfIsMuted}"; - ArgRequired = $"{m.Messages.ArgRequired}"; - NotFoundOnline = $"{m.Messages.NotFoundOnline}"; - NotFoundOnlineIdOnly = $"{m.Messages.NotFoundOnlineIdOnly}"; - AdminSearchingInv = $"{m.Messages.AdminSearchingInv}"; - PlayerMessage = m.Messages.PlayerMessage; - AdminMessage = m.Messages.AdminMessage; - AdminChatMessage = m.Messages.AdminChatMessage; - MsgNoPermJob = $"{m.Messages.MsgNoPermJob}"; - BlockedItemMessage = $"{m.Messages.BlockedItem}"; - MsgNoWantedAllowed = $"{m.Messages.MsgNoWantedAllowed}"; - MsgNoCuffedAllowed = $"{m.Messages.MsgNoCuffedAllowed}"; + MsgNoPerm = m.Messages.NoPerm; + MsgDiscord = m.Messages.DiscordLink; + MsgSayPrefix = m.Messages.MsgSayPrefix; + DisabledCommand = $"{m.Messages.DisabledCommand}"; + PlayerIsAFK = $"{m.Messages.PlayerIsAFK}"; + SelfIsMuted = $"{m.Messages.SelfIsMuted}"; + ArgRequired = $"{m.Messages.ArgRequired}"; + NotFoundOnline = $"{m.Messages.NotFoundOnline}"; + NotFoundOnlineIdOnly = $"{m.Messages.NotFoundOnlineIdOnly}"; + AdminSearchingInv = $"{m.Messages.AdminSearchingInv}"; + PlayerMessage = m.Messages.PlayerMessage; + AdminMessage = m.Messages.AdminMessage; + AdminChatMessage = m.Messages.AdminChatMessage; + MsgNoPermJob = $"{m.Messages.MsgNoPermJob}"; + BlockedItemMessage = $"{m.Messages.BlockedItem}"; + MsgNoWantedAllowed = $"{m.Messages.MsgNoWantedAllowed}"; + MsgNoCuffedAllowed = $"{m.Messages.MsgNoCuffedAllowed}"; + MsgNoJailAllowed = $"{m.Messages.MsgNoJailAllowed}"; + MeMessage = m.Messages.MeMessage; - AccessMoneyMenu = m.FunctionUI.AccessMoneyMenu; - AccessItemMenu = m.FunctionUI.AccessItemMenu; - AccessSetHPMenu = m.FunctionUI.AccessSetHPMenu; - AccessSetStatsMenu = m.FunctionUI.AccessSetStatsMenu; - AccessCWMenu = m.FunctionUI.AccessCWMenu; + AccessMoneyMenu = m.FunctionUI.AccessMoneyMenu; + AccessItemMenu = m.FunctionUI.AccessItemMenu; + AccessSetHPMenu = m.FunctionUI.AccessSetHPMenu; + AccessSetStatsMenu = m.FunctionUI.AccessSetStatsMenu; + AccessCWMenu = m.FunctionUI.AccessCWMenu; - ReportReasons = new string[] { m.ReportOptions.F2, m.ReportOptions.F3, m.ReportOptions.F4, m.ReportOptions.F5, m.ReportOptions.F6, m.ReportOptions.F7, m.ReportOptions.F8, m.ReportOptions.F9, m.ReportOptions.F10 }; + ReportReasons = new string[] { m.ReportOptions.F2, m.ReportOptions.F3, m.ReportOptions.F4, m.ReportOptions.F5, m.ReportOptions.F6, m.ReportOptions.F7, m.ReportOptions.F8, m.ReportOptions.F9, m.ReportOptions.F10 }; - // Softcode this someday - Jobs = new string[] { m.JobIndexArray.Citizen, m.JobIndexArray.Criminal, m.JobIndexArray.Prisoner, m.JobIndexArray.Police, m.JobIndexArray.Paramedic, m.JobIndexArray.Firefighter, m.JobIndexArray.Rojo_Loco, m.JobIndexArray.Green_St_Fam, m.JobIndexArray.Borgata_Blue, m.JobIndexArray.Mayor, m.JobIndexArray.DeliveryDriver, m.JobIndexArray.TaxiDriver, m.JobIndexArray.SpecOps }; + // Softcode this someday + Jobs = new string[] { m.JobIndexArray.Citizen, m.JobIndexArray.Criminal, m.JobIndexArray.Prisoner, m.JobIndexArray.Police, m.JobIndexArray.Paramedic, m.JobIndexArray.Firefighter, m.JobIndexArray.Rojo_Loco, m.JobIndexArray.Green_St_Fam, m.JobIndexArray.Borgata_Blue, m.JobIndexArray.Mayor, m.JobIndexArray.DeliveryDriver, m.JobIndexArray.TaxiDriver, m.JobIndexArray.SpecOps }; - BlockedItems = m.BlockedItems; + BlockedItems = m.BlockedItems; - EnableBlockSpawnBot = m.Misc.EnableBlockSpawnBot; - LanguageBlock = m.Misc.EnableLanguageBlock; - ChatBlock = m.Misc.EnableChatBlock; - CheckAlt = m.Misc.CheckForAlts; - CheckBannedEnabled = m.Misc.CheckBannedEnabled; - TimeBetweenAnnounce = m.Misc.TimeBetweenAnnounce; - if (_Timer.Enabled) - { - _Timer.Enabled = false; - _Timer.Interval = TimeBetweenAnnounce * 1000; - _Timer.Enabled = true; - } - if (m.Misc.EnableBlockSpawnBot) - BlockedSpawnIds = m.Misc.BlockSpawnBot.Split(',').Select(int.Parse).ToArray(); - GodModeLevel = m.Misc.GodModeLevel; - ShowJailMessage = m.Misc.ShowJailMessage; - BlockSuicide = m.Misc.BlockSuicide; - BlockMissions = m.Misc.BlockMissions; - ProximityChat = m.Misc.ProximityChat; - LocalChatMute = m.Misc.LocalChatMute; + EnableBlockSpawnBot = m.Misc.EnableBlockSpawnBot; + LanguageBlock = m.Misc.EnableLanguageBlock; + ChatBlock = m.Misc.EnableChatBlock; + CheckBannedEnabled = m.Misc.CheckBannedEnabled; + TimeBetweenAnnounce = m.Misc.TimeBetweenAnnounce; + Variables.Announcer.Interval = TimeBetweenAnnounce; + TimescaleDisabled = m.Misc.TimescaleDisabled; - foreach (var currJob in m.WhitelistedJobs) - { - if (!WhitelistedJobs.ContainsKey(currJob.JobIndex)) - WhitelistedJobs.Add(currJob.JobIndex, currJob.Whitelisted); - else - Debug.Log($"{SetTimeStamp.Run()}[WARNING] WhitelistedJobs already contains a item with the key '{currJob.JobIndex}'! (Did you make 2 objects with the same JobIndex?)"); - } - RegisterCommands.Run(m.Commands); - break; - case IdListItemsFile: - idlist = JsonConvert.DeserializeObject(FilterComments.Run(IdListItemsFile)); - IDs_Items = idlist.items.Select(x => x.gameid).ToArray(); - break; - case IdListVehicleFile: - idlist = JsonConvert.DeserializeObject(FilterComments.Run(IdListVehicleFile)); - IDs_Vehicles = idlist.items.Select(x => x.gameid).ToArray(); - break; - case AnnouncementsFile: - Announcements = File.ReadAllLines(fileName); - break; - case RulesFile: - Rules = File.ReadAllText(fileName); - break; - case GodListFile: - GodListPlayers = File.ReadAllLines(fileName).ToList(); - break; - case AfkListFile: - AfkPlayers = File.ReadAllLines(fileName).ToList(); - break; - case MuteListFile: - MutePlayers = File.ReadAllLines(fileName).ToList(); - break; - } - } + if (m.Misc.EnableBlockSpawnBot) + BlockedSpawnIds = m.Misc.BlockSpawnBot.Split(',').Select(int.Parse).ToArray(); + GodModeLevel = m.Misc.GodModeLevel; + ShowJailMessage = m.Misc.ShowJailMessage; + BlockSuicide = m.Misc.BlockSuicide; + BlockMissions = m.Misc.BlockMissions; + ProximityChat = m.Misc.ProximityChat; + LocalChatMute = m.Misc.LocalChatMute; + LocalChatMe = m.Misc.LocalChatMe; + + foreach (var currJob in m.WhitelistedJobs) + { + if (WhitelistedJobs.ContainsKey(currJob.JobIndex)) + { + Debug.Log($"{PlaceholderParser.ParseTimeStamp()} [WARNING] WhitelistedJobs already contains a item with the key '{currJob.JobIndex}'! (Did you make two objects with the same JobIndex?)"); + continue; + } + WhitelistedJobs.Add(currJob.JobIndex, currJob.Whitelisted); + } + RegisterCommands.Run(m.Commands); + break; + case IdListItemsFile: + idlist = JsonConvert.DeserializeObject(FilterComments.Run(IdListItemsFile)); + IDs_Items = idlist.items.Select(x => x.gameid).ToArray(); + break; + case IdListVehicleFile: + idlist = JsonConvert.DeserializeObject(FilterComments.Run(IdListVehicleFile)); + IDs_Vehicles = idlist.items.Select(x => x.gameid).ToArray(); + break; + case AnnouncementsFile: + Variables.Announcer.Announcements = File.ReadAllLines(fileName).ToList(); + break; + case RulesFile: + Rules = File.ReadAllText(fileName); + break; + case GodListFile: + GodListPlayers = File.ReadAllLines(fileName).ToList(); + break; + case AfkListFile: + AfkPlayers = File.ReadAllLines(fileName).ToList(); + break; + case MuteListFile: + MutePlayers = File.ReadAllLines(fileName).ToList(); + break; + default: + break; + } + } catch (Exception ex) { ErrorLogging.Run(ex); diff --git a/source/BP-Essentials/Methods/FileHandler/ReadFileStream.cs b/source/BP-Essentials/Methods/FileHandler/ReadFileStream.cs index d63ac15b..4abf80c2 100644 --- a/source/BP-Essentials/Methods/FileHandler/ReadFileStream.cs +++ b/source/BP-Essentials/Methods/FileHandler/ReadFileStream.cs @@ -3,8 +3,8 @@ using System.Linq; using System.Text; using UnityEngine; -using static BP_Essentials.EssentialsVariablesPlugin; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.Variables; +using static BP_Essentials.HookMethods; using System.IO; namespace BP_Essentials @@ -16,11 +16,12 @@ public static void Run(string fileName, List output) try { output.Clear(); - foreach (var line in File.ReadAllLines(fileName)) - if (line.StartsWith("#")) - continue; - else - output.Add(line); + foreach (var line in File.ReadAllLines(fileName)) + { + if (line.StartsWith("#", StringComparison.CurrentCulture)) + continue; + output.Add(line); + } } catch (Exception ex) { diff --git a/source/BP-Essentials/Methods/FileHandler/ReadGroups.cs b/source/BP-Essentials/Methods/FileHandler/ReadGroups.cs index d8ff0db1..d52b7843 100644 --- a/source/BP-Essentials/Methods/FileHandler/ReadGroups.cs +++ b/source/BP-Essentials/Methods/FileHandler/ReadGroups.cs @@ -3,8 +3,8 @@ using System.Linq; using System.Text; using UnityEngine; -using static BP_Essentials.EssentialsVariablesPlugin; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.Variables; +using static BP_Essentials.HookMethods; using Newtonsoft.Json; namespace BP_Essentials @@ -28,13 +28,15 @@ public static void Run() { Groups.Clear(); _RootObject m = JsonConvert.DeserializeObject<_RootObject>(FilterComments.Run(CustomGroupsFile)); - foreach (var group in m.Groups) - { - if (!Groups.ContainsKey(group.Name)) - Groups.Add(group.Name, new _Group { Message = group.Message, Name = group.Name, Users = group.Usernames }); - else - Debug.Log($"{SetTimeStamp.Run()}[ERROR] Cannot add group {group.Name} To dictionary because it already exists!"); - } + foreach (var group in m.Groups) + { + if (Groups.ContainsKey(group.Name)) + { + Debug.Log($"{PlaceholderParser.ParseTimeStamp()} [ERROR] Cannot add group {group.Name} To dictionary because it already exists!"); + continue; + } + Groups.Add(group.Name, new _Group { Message = group.Message, Name = group.Name, Users = group.Usernames }); + } } catch (Exception ex) { diff --git a/source/BP-Essentials/Methods/FileHandler/RegisterCommands.cs b/source/BP-Essentials/Methods/FileHandler/RegisterCommands.cs index 1d5053f3..efa3dff0 100644 --- a/source/BP-Essentials/Methods/FileHandler/RegisterCommands.cs +++ b/source/BP-Essentials/Methods/FileHandler/RegisterCommands.cs @@ -3,8 +3,8 @@ using System.Linq; using System.Text; using UnityEngine; -using static BP_Essentials.EssentialsVariablesPlugin; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.Variables; +using static BP_Essentials.HookMethods; using System.Reflection; namespace BP_Essentials @@ -13,12 +13,12 @@ class RegisterCommands { public static void Run(List<_Command> cmdlist) { - Debug.Log($"{SetTimeStamp.Run()}[INFO] Registering commands.."); + Debug.Log($"{PlaceholderParser.ParseTimeStamp()} [INFO] Registering commands.."); CommandList.Clear(); foreach (var command in cmdlist) { if (DebugLevel >= 1) - Debug.Log($"{SetTimeStamp.Run()}[INFO] Registering command: {command.CommandName}.."); + Debug.Log($"{PlaceholderParser.ParseTimeStamp()} [INFO] Registering command: {command.CommandName}.."); Action rMethod = null; try { @@ -47,10 +47,11 @@ public static void Run(List<_Command> cmdlist) commandCmds = command.Commands.Select(x=>$"{CmdCommandCharacter}{x}").ToList(), commandDisabled = command.Disabled ?? false, commandWantedAllowed = command.AllowWithCrimes ?? true, - commandHandcuffedAllowed = command.AllowWhileCuffed ?? true + commandHandcuffedAllowed = command.AllowWhileCuffed ?? true, + commandWhileJailedAllowed = command.AllowWhileJailed ?? true }); } - Debug.Log($"{SetTimeStamp.Run()}[INFO] Registered commands! ({CommandList.Count} commands loaded in.)"); + Debug.Log($"{PlaceholderParser.ParseTimeStamp()} [INFO] Registered commands! ({CommandList.Count} commands loaded in.)"); } } } diff --git a/source/BP-Essentials/Methods/FileHandler/RemoveStringFromFile.cs b/source/BP-Essentials/Methods/FileHandler/RemoveStringFromFile.cs index 7c74bb76..057bbd50 100644 --- a/source/BP-Essentials/Methods/FileHandler/RemoveStringFromFile.cs +++ b/source/BP-Essentials/Methods/FileHandler/RemoveStringFromFile.cs @@ -3,8 +3,8 @@ using System.Linq; using System.Text; using UnityEngine; -using static BP_Essentials.EssentialsVariablesPlugin; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.Variables; +using static BP_Essentials.HookMethods; using System.IO; namespace BP_Essentials diff --git a/source/BP-Essentials/Methods/FileHandler/WarpsHandler.cs b/source/BP-Essentials/Methods/FileHandler/WarpsHandler.cs new file mode 100644 index 00000000..f3360862 --- /dev/null +++ b/source/BP-Essentials/Methods/FileHandler/WarpsHandler.cs @@ -0,0 +1,50 @@ +using BP_Essentials.Methods.FileHandler; +using Newtonsoft.Json; +using System; +using System.Collections; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using UnityEngine; +using static BP_Essentials.Variables; + +namespace BP_Essentials +{ + public class WarpHandler : ExpandableFileHandler + { + public WarpHandler() + { + Name = "warp"; + FileExtension = "json"; + FilesDirectory = WarpDirectory; + } + public class JsonModel : IExpandableFile, IExpandableFileDelayable, IExpandableFileHasPrice + { + public string Name { get; set; } + public string ExecutableBy { get; set; } + public bool Disabled { get; set; } + public int Price { get; set; } + public int Delay { get; set; } + public Dictionary CurrentlyInCooldown { get; set; } = new Dictionary(); + + public Position Position { get; set; } + public Rotation Rotation { get; set; } + } + public class Position + { + public float X { get; set; } + public float Y { get; set; } + public float Z { get; set; } + public int PlaceIndex { get; set; } + } + + public class Rotation + { + public float X { get; set; } + public float Y { get; set; } + public float Z { get; set; } + public float W { get; set; } + } + } +} diff --git a/source/BP-Essentials/Methods/FileHandler/WriteIpToFile.cs b/source/BP-Essentials/Methods/FileHandler/WriteIpToFile.cs index dd8c148f..6b79af3a 100644 --- a/source/BP-Essentials/Methods/FileHandler/WriteIpToFile.cs +++ b/source/BP-Essentials/Methods/FileHandler/WriteIpToFile.cs @@ -3,32 +3,30 @@ using System.Linq; using System.Text; using UnityEngine; -using static BP_Essentials.EssentialsVariablesPlugin; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.Variables; +using static BP_Essentials.HookMethods; using System.IO; using System.Threading; namespace BP_Essentials { - class WriteIpToFile : EssentialsCorePlugin + class WriteIpToFile : Core { public static void Run(SvPlayer player) { try { - Thread.Sleep(500); - Debug.Log($"{SetTimeStamp.Run()}[INFO] [JOIN] {player.playerData.username} IP is: {player.connection.IP}"); + Debug.Log($"{PlaceholderParser.ParseTimeStamp()} [INFO] [JOIN] {player.player.username} IP is: {player.connection.IP}"); int tries = 0; while (tries < 2) try { - if (!File.ReadAllText(IpListFile).Contains(player.playerData.username + ": " + player.connection.IP)) - File.AppendAllText(IpListFile, player.playerData.username + ": " + player.connection.IP + Environment.NewLine); + if (!File.ReadAllText(IpListFile).Contains(player.player.username + ": " + player.connection.IP)) + File.AppendAllText(IpListFile, player.player.username + ": " + player.connection.IP + Environment.NewLine); break; } catch (IOException) { - Thread.Sleep(50); ++tries; } } diff --git a/source/BP-Essentials/Methods/GameMethods/CleanupApartment.cs b/source/BP-Essentials/Methods/GameMethods/CleanupApartment.cs index 11401861..783a8372 100644 --- a/source/BP-Essentials/Methods/GameMethods/CleanupApartment.cs +++ b/source/BP-Essentials/Methods/GameMethods/CleanupApartment.cs @@ -3,13 +3,13 @@ using System.Linq; using System.Text; using UnityEngine; -using static BP_Essentials.EssentialsVariablesPlugin; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.Variables; +using static BP_Essentials.HookMethods; using System.Reflection; namespace BP_Essentials { - class CleanupApartment : EssentialsVariablesPlugin + class CleanupApartment : Variables { public static void Run(ShPlayer shPlayer) { diff --git a/source/BP-Essentials/Methods/GameMethods/GetExtraCount.cs b/source/BP-Essentials/Methods/GameMethods/GetExtraCount.cs index cb12365e..1f6d3e78 100644 --- a/source/BP-Essentials/Methods/GameMethods/GetExtraCount.cs +++ b/source/BP-Essentials/Methods/GameMethods/GetExtraCount.cs @@ -3,13 +3,13 @@ using System.Linq; using System.Text; using UnityEngine; -using static BP_Essentials.EssentialsVariablesPlugin; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.Variables; +using static BP_Essentials.HookMethods; using System.Reflection; namespace BP_Essentials { - class GetExtraCount : EssentialsVariablesPlugin + class GetExtraCount : Variables { public static int Run(ShPlayer player, InventoryItem myItem) { diff --git a/source/BP-Essentials/Methods/GameMethods/SendToJail.cs b/source/BP-Essentials/Methods/GameMethods/SendToJail.cs index afdd3e59..22741437 100644 --- a/source/BP-Essentials/Methods/GameMethods/SendToJail.cs +++ b/source/BP-Essentials/Methods/GameMethods/SendToJail.cs @@ -3,8 +3,8 @@ using System.Linq; using System.Text; using UnityEngine; -using static BP_Essentials.EssentialsVariablesPlugin; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.Variables; +using static BP_Essentials.HookMethods; namespace BP_Essentials { @@ -16,7 +16,7 @@ public static bool Run(ShPlayer shPlayer, float time) return false; var jailSpawn = shPlayer.manager.jail.transform; SetJob.Run(shPlayer, 2, true, false); - shPlayer.svEntity.SvReset(jailSpawn.position, jailSpawn.rotation, 0); + shPlayer.svPlayer.ResetAndSavePosition(jailSpawn.position, jailSpawn.rotation, 0); shPlayer.StartCoroutine(shPlayer.svPlayer.JailTimer(time)); shPlayer.svPlayer.SvClearCrimes(); shPlayer.RemoveItemsJail(); diff --git a/source/BP-Essentials/Methods/GameMethods/SetJob.cs b/source/BP-Essentials/Methods/GameMethods/SetJob.cs index 7bdbc6b0..76d14b2a 100644 --- a/source/BP-Essentials/Methods/GameMethods/SetJob.cs +++ b/source/BP-Essentials/Methods/GameMethods/SetJob.cs @@ -3,13 +3,13 @@ using System.Linq; using System.Text; using UnityEngine; -using static BP_Essentials.EssentialsVariablesPlugin; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.Variables; +using static BP_Essentials.HookMethods; using System.Reflection; namespace BP_Essentials { - class SetJob : EssentialsVariablesPlugin + class SetJob : Variables { public static void Run(ShPlayer shPlayer, byte jobIndex, bool AddItems, bool CollectCost) { diff --git a/source/BP-Essentials/Methods/GameMethods/UnRestrain.cs b/source/BP-Essentials/Methods/GameMethods/UnRestrain.cs index 46a5221c..3539f938 100644 --- a/source/BP-Essentials/Methods/GameMethods/UnRestrain.cs +++ b/source/BP-Essentials/Methods/GameMethods/UnRestrain.cs @@ -3,13 +3,13 @@ using System.Linq; using System.Text; using UnityEngine; -using static BP_Essentials.EssentialsVariablesPlugin; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.Variables; +using static BP_Essentials.HookMethods; using System.Reflection; namespace BP_Essentials { - class UnRestrain : EssentialsVariablesPlugin + class UnRestrain : Variables { public static void Run(SvPlayer player) { diff --git a/source/BP-Essentials/Methods/Utils/ErrorLogging.cs b/source/BP-Essentials/Methods/Utils/ErrorLogging.cs index f3e286b0..7a3b0353 100644 --- a/source/BP-Essentials/Methods/Utils/ErrorLogging.cs +++ b/source/BP-Essentials/Methods/Utils/ErrorLogging.cs @@ -3,8 +3,8 @@ using System.Linq; using System.Text; using UnityEngine; -using static BP_Essentials.EssentialsVariablesPlugin; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.Variables; +using static BP_Essentials.HookMethods; using System.IO; using System.Threading; using System.Reflection; diff --git a/source/BP-Essentials/Methods/Utils/FilterComments.cs b/source/BP-Essentials/Methods/Utils/FilterComments.cs index e7b9a39c..4b94d41f 100644 --- a/source/BP-Essentials/Methods/Utils/FilterComments.cs +++ b/source/BP-Essentials/Methods/Utils/FilterComments.cs @@ -3,8 +3,8 @@ using System.Linq; using System.Text; using UnityEngine; -using static BP_Essentials.EssentialsVariablesPlugin; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.Variables; +using static BP_Essentials.HookMethods; using System.Text.RegularExpressions; using System.IO; diff --git a/source/BP-Essentials/Methods/Utils/FunctionMenu.cs b/source/BP-Essentials/Methods/Utils/FunctionMenu.cs new file mode 100644 index 00000000..c5f46129 --- /dev/null +++ b/source/BP-Essentials/Methods/Utils/FunctionMenu.cs @@ -0,0 +1,238 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UnityEngine; +using static BP_Essentials.Variables; + +namespace BP_Essentials.Methods.Utils +{ + public static class FunctionMenu + { + public static void RegisterMenus() + { + FunctionMenuKeys = new MultiDictionary> + { + [1, CurrentMenu.None] = MainMenu, + + [2, CurrentMenu.ServerInfo] = ServerInfo, + [2, CurrentMenu.Staff] = GiveMoneyMenu, + [2, CurrentMenu.GiveMoney] = Give1kMoney, + [2, CurrentMenu.GiveItems] = GivePistolAmmo, + [2, CurrentMenu.AdminReport] = AdminReportWindowTeleport, + + [3, CurrentMenu.Main] = ServerInfoMenu, + [3, CurrentMenu.ServerInfo] = ServerAdmins, + [3, CurrentMenu.Staff] = GiveItemsMenu, + [3, CurrentMenu.GiveMoney] = Give10kMoney, + [3, CurrentMenu.GiveItems] = Give20Handcuffs, + [3, CurrentMenu.AdminReport] = ResetWindow, + + [4, CurrentMenu.GiveMoney] = Give100kMoney, + [4, CurrentMenu.GiveItems] = Give10TaserAmmo, + [4, CurrentMenu.Staff] = Heal, + + [5, CurrentMenu.GiveItems] = GiveAllLicenses, + [5, CurrentMenu.Staff] = Feed, + + [6, CurrentMenu.Staff] = ClearWanted, + + [10, CurrentMenu.Main] = StaffMenu + }; + } + public static CurrentMenu ResetWindow(SvPlayer player) + { + player.CloseFunctionMenu(); + return CurrentMenu.None; + } + + #region Key | Any + public static CurrentMenu ReportMenu(SvPlayer player, byte key) + { + player.CloseFunctionMenu(); + if (!PlayerList.TryGetValue(player.player.ID, out var playerListItem)) + return CurrentMenu.None; + player.SendChatMessage($"Reported \"{playerListItem.ReportedPlayer.username}\" With the reason \"{ReportReasons[key - 2]}\"."); + playerListItem.ReportedReason = ReportReasons[key - 2]; + SendDiscordMessage.ReportMessage(playerListItem.ReportedPlayer.username, player.player.username, ReportReasons[key - 2]); + ReportPlayer.Run(player.player.username, ReportReasons[key - 2], playerListItem.ReportedPlayer); + return CurrentMenu.None; + } + #endregion + + #region Key | 1 + public static CurrentMenu MainMenu(SvPlayer player) + { + if (HasPermission.Run(player, AccessMoneyMenu) || HasPermission.Run(player, AccessItemMenu) || HasPermission.Run(player, AccessSetHPMenu) || HasPermission.Run(player, AccessSetStatsMenu) || HasPermission.Run(player, AccessCWMenu)) + { + player.Send(SvSendType.Self, Channel.Reliable, ClPacket.ShowFunctionMenu, "Main menu:\n\nF3: Server info menu\nF10: Extras menu\n\nPress F11 To close this (G)UI"); + return CurrentMenu.Main; + } + player.Send(SvSendType.Self, Channel.Reliable, ClPacket.ShowFunctionMenu, "Main menu:\n\nF3: Server info menu\n\nPress F11 To close this (G)UI"); + return CurrentMenu.Main; + } + #endregion + + #region Key | 2 + public static CurrentMenu ServerInfo(SvPlayer player) + { + player.CloseFunctionMenu(); + player.Send(SvSendType.Self, Channel.Fragmented, ClPacket.ServerInfo, File.ReadAllText("server_info.txt")); + return CurrentMenu.None; + } + public static CurrentMenu GiveMoneyMenu(SvPlayer player) + { + if (!HasPermission.Run(player, AccessMoneyMenu)) + return CurrentMenu.None; + player.Send(SvSendType.Self, Channel.Reliable, ClPacket.ShowFunctionMenu, "Give Money menu:\n\nF2: Give 1.000 dollars (1k)\nF3: Give 10.000 dollars (10k)\nF4: Give 100.000 dollars (100k)\n\nPress F11 To close this (G)UI"); + return CurrentMenu.GiveMoney; + } + public static CurrentMenu Give1kMoney(SvPlayer player) + { + player.player.TransferMoney(DeltaInv.AddToMe, 1000, true); + player.SendChatMessage($"You have given yourself 1.000 dollars."); + Debug.Log($"{PlaceholderParser.ParseTimeStamp()} [INFO] {player.player.username} Spawned in 1.000 dollars through the functionUI"); + return CurrentMenu.GiveMoney; + } + public static CurrentMenu GivePistolAmmo(SvPlayer player) + { + player.player.TransferItem(DeltaInv.AddToMe, CommonIDs[0], 500, true); + player.Send(SvSendType.Self, Channel.Reliable, ClPacket.GameMessage, $"You have given yourself 500 pistol ammo."); + Debug.Log($"{PlaceholderParser.ParseTimeStamp()} [INFO] {player.player.username} Spawned in 500 pistol ammo through the functionUI"); + return CurrentMenu.GiveItems; + } + public static CurrentMenu AdminReportWindowTeleport(SvPlayer player) + { + player.CloseFunctionMenu(); + if (!PlayerList.TryGetValue(player.player.ID, out var playerItem)) + return CurrentMenu.None; + playerItem.ReportedPlayer = null; + if (!IsOnline.Run(playerItem.ReportedPlayer)) + { + player.SendChatMessage("Player not online anymore."); + return CurrentMenu.None; + } + player.ResetAndSavePosition(playerItem.ReportedPlayer.GetPosition(), playerItem.ReportedPlayer.GetRotation(), playerItem.ReportedPlayer.GetPlaceIndex()); + player.SendChatMessage($"Teleported to \"{playerItem.ReportedPlayer.username}\"."); + return CurrentMenu.None; + } + #endregion + + #region Key | 3 + public static CurrentMenu GiveItemsMenu(SvPlayer player) + { + if (!HasPermission.Run(player, AccessItemMenu)) + return CurrentMenu.None; + player.Send(SvSendType.Self, Channel.Reliable, ClPacket.ShowFunctionMenu, "Give Items menu:\n\nF2: Give 500 Pistol Ammo\nF3: Give 20 Handcuffs\nF4: Give 10 Taser ammo\nF5: Give all Licenses\n\nPress F11 To close this (G)UI"); + return CurrentMenu.GiveItems; + } + public static CurrentMenu Give10kMoney(SvPlayer player) + { + player.player.TransferMoney(DeltaInv.AddToMe, 10000, true); + player.SendChatMessage($"You have given yourself 10.000 dollars."); + Debug.Log($"{PlaceholderParser.ParseTimeStamp()} [INFO] {player.player.username} Spawned in 10.000 dollars through the functionUI"); + return CurrentMenu.GiveMoney; + } + public static CurrentMenu Give20Handcuffs(SvPlayer player) + { + player.player.TransferItem(1, CommonIDs[1], 20, true); + player.SendChatMessage($"You have given yourself 20 handcuffs."); + Debug.Log($"{PlaceholderParser.ParseTimeStamp()} [INFO] {player.player.username} Spawned in 20 handcuffs through the functionUI"); + return CurrentMenu.GiveItems; + } + public static CurrentMenu ServerInfoMenu(SvPlayer player) + { + player.Send(SvSendType.Self, Channel.Reliable, ClPacket.ShowFunctionMenu, "Server info menu:\n\nF2: Show rules\nF3: Show admins\n\nPress F11 To close this (G)UI"); + return CurrentMenu.ServerInfo; + } + public static CurrentMenu ServerAdmins(SvPlayer player) + { + player.CloseFunctionMenu(); + var builder = new StringBuilder("All admins on this server:\n\n"); + foreach (var line in File.ReadAllLines("admin_list.txt")) + if (line.Trim() != null && !line.Trim().StartsWith("#", StringComparison.OrdinalIgnoreCase)) + builder.AppendLine(line); + player.Send(SvSendType.Self, Channel.Fragmented, ClPacket.ServerInfo, builder.ToString()); + return CurrentMenu.None; + } + #endregion + + #region Key | 4 + public static CurrentMenu Give100kMoney(SvPlayer player) + { + player.player.TransferMoney(DeltaInv.AddToMe, 100000, true); + player.SendChatMessage($"You have given yourself 100.000 dollars."); + Debug.Log($"{PlaceholderParser.ParseTimeStamp()} [INFO] {player.player.username} Spawned in 100.000 dollars through the functionUI"); + return CurrentMenu.GiveMoney; + } + public static CurrentMenu Heal(SvPlayer player) + { + if (!HasPermission.Run(player, AccessSetHPMenu)) + return CurrentMenu.None; + player.Heal(100); + player.SendChatMessage($"You've been healed."); + Debug.Log($"{PlaceholderParser.ParseTimeStamp()} [INFO] {player.player.username} healed himself through the functionUI"); + return CurrentMenu.Staff; + } + public static CurrentMenu Give10TaserAmmo(SvPlayer player) + { + player.player.TransferItem(1, CommonIDs[2], 10, true); + player.SendChatMessage($"You have given yourself 10 Taser ammo."); + Debug.Log($"{PlaceholderParser.ParseTimeStamp()} [INFO] {player.player.username} Spawned in 10 taser ammo through the functionUI"); + return CurrentMenu.GiveItems; + } + #endregion + + #region Key | 5 + public static CurrentMenu Feed(SvPlayer player) + { + if (!HasPermission.Run(player, AccessSetStatsMenu)) + return CurrentMenu.None; + player.UpdateStats(100F, 100F, 100F, 100F); + player.SendChatMessage($"Maxed out stats for yourself."); + Debug.Log($"{PlaceholderParser.ParseTimeStamp()} [INFO] {player.player.username} Maxed out stats through the functionUI"); + return CurrentMenu.Staff; + } + public static CurrentMenu GiveAllLicenses(SvPlayer player) + { + for (int i = 3; i < 7; i++) + player.player.TransferItem(DeltaInv.AddToMe, CommonIDs[i], 1, true); + player.SendChatMessage($"You have given yourself all licenses."); + Debug.Log($"{PlaceholderParser.ParseTimeStamp()} [INFO] {player.player.username} Spawned in all licenses through the functionUI"); + return CurrentMenu.GiveItems; + } + #endregion + + #region Key | 6 + public static CurrentMenu ClearWanted(SvPlayer player) + { + player.player.ClearCrimes(); + player.Send(SvSendType.Self, Channel.Reliable, ClPacket.ClearCrimes, player.player.ID); + player.Send(SvSendType.Self, Channel.Reliable, ClPacket.GameMessage, $"Cleared wanted level."); + Debug.Log($"{PlaceholderParser.ParseTimeStamp()} [INFO] {player.player.username} Removed his wantedlevel through the functionUI"); + return CurrentMenu.Staff; + } + #endregion + + #region Key | 10 + public static CurrentMenu StaffMenu(SvPlayer player) + { + var sb = new StringBuilder("Staff menu:\n\n"); + if (HasPermission.Run(player, AccessMoneyMenu)) + sb.Append("F2: Give Money\n"); + if (HasPermission.Run(player, AccessItemMenu)) + sb.Append("F3: Give Items\n"); + if (HasPermission.Run(player, AccessSetHPMenu)) + sb.Append("F4: Set HP to full\n"); + if (HasPermission.Run(player, AccessSetStatsMenu)) + sb.Append("F5: Set Stats to full\n"); + if (HasPermission.Run(player, AccessCWMenu)) + sb.Append("F6: Clear wanted level\n\n"); + player.Send(SvSendType.Self, Channel.Reliable, ClPacket.ShowFunctionMenu, $"{sb}Press F11 To close this (G)UI"); + return CurrentMenu.Staff; + } + #endregion + } +} diff --git a/source/BP-Essentials/Methods/Utils/GetArgument.cs b/source/BP-Essentials/Methods/Utils/GetArgument.cs index 70a33b9d..ffbecc05 100644 --- a/source/BP-Essentials/Methods/Utils/GetArgument.cs +++ b/source/BP-Essentials/Methods/Utils/GetArgument.cs @@ -3,13 +3,13 @@ using System.Linq; using System.Text; using UnityEngine; -using static BP_Essentials.EssentialsVariablesPlugin; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.Variables; +using static BP_Essentials.HookMethods; using System.Text.RegularExpressions; namespace BP_Essentials { - class GetArgument : EssentialsCorePlugin + class GetArgument : Core { // redo? public static string Run(int nr, bool UseRegex, bool IncludeSpaces, string message) diff --git a/source/BP-Essentials/Methods/Utils/GetShByStr.cs b/source/BP-Essentials/Methods/Utils/GetShByStr.cs index 2a726256..65c83b36 100644 --- a/source/BP-Essentials/Methods/Utils/GetShByStr.cs +++ b/source/BP-Essentials/Methods/Utils/GetShByStr.cs @@ -3,12 +3,12 @@ using System.Linq; using System.Text; using UnityEngine; -using static BP_Essentials.EssentialsVariablesPlugin; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.Variables; +using static BP_Essentials.HookMethods; namespace BP_Essentials { - class GetShByStr : EssentialsCorePlugin + class GetShByStr : Core { public static ShPlayer Run(string player, bool idOnly = false) { diff --git a/source/BP-Essentials/Methods/Utils/GetWebsiteContent.cs b/source/BP-Essentials/Methods/Utils/GetWebsiteContent.cs index 955821e7..eabe5d60 100644 --- a/source/BP-Essentials/Methods/Utils/GetWebsiteContent.cs +++ b/source/BP-Essentials/Methods/Utils/GetWebsiteContent.cs @@ -7,7 +7,7 @@ using System.Text; using System.Threading.Tasks; using UnityEngine; -using static BP_Essentials.EssentialsVariablesPlugin; +using static BP_Essentials.Variables; namespace BP_Essentials { @@ -44,7 +44,7 @@ public static IEnumerator GetContentWWW(string link, Action callback) yield return www; if (www.error != null) { - Debug.Log($"{SetTimeStamp.Run()}[ERROR] {link} responded with HTTP error code: {www.error}!"); + Debug.Log($"{PlaceholderParser.ParseTimeStamp()} [ERROR] {link} responded with HTTP error code: {www.error}!"); callback?.Invoke(null); yield break; } diff --git a/source/BP-Essentials/Methods/Utils/HandleSpam.cs b/source/BP-Essentials/Methods/Utils/HandleSpam.cs new file mode 100644 index 00000000..63f897c9 --- /dev/null +++ b/source/BP-Essentials/Methods/Utils/HandleSpam.cs @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UnityEngine; +using static BP_Essentials.Variables; + +namespace BP_Essentials +{ + class HandleSpam + { + public static bool Run(SvPlayer player, string message) + { + if (MessagesAllowedPerSecond != -1 && MessagesAllowedPerSecond < 50) + { + if (PlayerList.TryGetValue(player.player.ID, out var currObj)) + { + if (currObj.MessagesSent >= MessagesAllowedPerSecond) + { + Debug.Log($"{PlaceholderParser.ParseTimeStamp()} [WARNING] {player.player.username} got kicked for spamming! {currObj.MessagesSent}/s (max: {MessagesAllowedPerSecond}) messages sent."); + player.svManager.Kick(player.connection); + return true; + } + PlayerList[player.player.ID].MessagesSent++; + if (!currObj.IsCurrentlyAwaiting) + { + PlayerList[player.player.ID].IsCurrentlyAwaiting = true; + Task.Factory.StartNew(async () => + { + await Task.Delay(TimeBetweenDelay); + if (PlayerList.ContainsKey(player.player.ID)) + { + PlayerList[player.player.ID].MessagesSent = 0; + PlayerList[player.player.ID].IsCurrentlyAwaiting = false; + } + }); + } + } + } + return false; + } + } +} diff --git a/source/BP-Essentials/Methods/Utils/HasPermission.cs b/source/BP-Essentials/Methods/Utils/HasPermission.cs index 9b7a1989..6b6b07d2 100644 --- a/source/BP-Essentials/Methods/Utils/HasPermission.cs +++ b/source/BP-Essentials/Methods/Utils/HasPermission.cs @@ -3,8 +3,8 @@ using System.Linq; using System.Text; using UnityEngine; -using static BP_Essentials.EssentialsVariablesPlugin; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.Variables; +using static BP_Essentials.HookMethods; namespace BP_Essentials { @@ -12,7 +12,7 @@ class HasPermission { public static bool Run(SvPlayer player, string ExeBy, bool ShowNoPermMessage = false, byte? jobIndex = null) { - if (player.player.admin && ExeBy.Contains("admins") || ExeBy.Contains("everyone")) + if ((player.player.admin && ExeBy.Contains("admins")) || ExeBy.Contains("everyone") || ExeBy.Contains($"username:{player.player.username}")) return true; string[] GroupsSplit = ExeBy.Split(','); foreach (string name in GroupsSplit) @@ -25,7 +25,7 @@ public static bool Run(SvPlayer player, string ExeBy, bool ShowNoPermMessage = f if (Groups.Any(curr => $"group:{curr.Value.Name}".Equals(name.Trim()) && curr.Value.Users.Contains(player.playerData.username))) return true; if (ShowNoPermMessage) - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"{MsgNoPerm}"); + player.SendChatMessage($"{MsgNoPerm}"); return false; } } diff --git a/source/BP-Essentials/Methods/Utils/HasWantedLevel.cs b/source/BP-Essentials/Methods/Utils/HasWantedLevel.cs index 255d605e..79dfce67 100644 --- a/source/BP-Essentials/Methods/Utils/HasWantedLevel.cs +++ b/source/BP-Essentials/Methods/Utils/HasWantedLevel.cs @@ -3,8 +3,8 @@ using System.Linq; using System.Text; using UnityEngine; -using static BP_Essentials.EssentialsVariablesPlugin; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.Variables; +using static BP_Essentials.HookMethods; namespace BP_Essentials { @@ -14,7 +14,7 @@ public static bool Run(SvPlayer player, bool allow = true) { if (allow || player.player.wantedLevel <= 0) return true; - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"{MsgNoWantedAllowed}"); + player.SendChatMessage($"{MsgNoWantedAllowed}"); return false; } } diff --git a/source/BP-Essentials/Methods/Utils/IsCuffed.cs b/source/BP-Essentials/Methods/Utils/IsCuffed.cs index ecbec096..0a85210e 100644 --- a/source/BP-Essentials/Methods/Utils/IsCuffed.cs +++ b/source/BP-Essentials/Methods/Utils/IsCuffed.cs @@ -3,8 +3,8 @@ using System.Linq; using System.Text; using UnityEngine; -using static BP_Essentials.EssentialsVariablesPlugin; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.Variables; +using static BP_Essentials.HookMethods; namespace BP_Essentials { @@ -14,7 +14,7 @@ public static bool Run(SvPlayer player, bool allow = true) { if (allow || !player.player.IsRestrained()) return true; - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"{MsgNoCuffedAllowed}"); + player.SendChatMessage($"{MsgNoCuffedAllowed}"); return false; } } diff --git a/source/BP-Essentials/Methods/Utils/IsJailed.cs b/source/BP-Essentials/Methods/Utils/IsJailed.cs new file mode 100644 index 00000000..483b28dd --- /dev/null +++ b/source/BP-Essentials/Methods/Utils/IsJailed.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using UnityEngine; +using static BP_Essentials.Variables; +using static BP_Essentials.HookMethods; + +namespace BP_Essentials +{ + class IsJailed + { + public static bool Run(SvPlayer player, bool allow = true) + { + if (allow || !(player.player.job is Prisoner)) + return true; + player.SendChatMessage($"{MsgNoJailAllowed}"); + return false; + } + } +} diff --git a/source/BP-Essentials/Methods/Utils/LogMessage.cs b/source/BP-Essentials/Methods/Utils/LogMessage.cs index 13abd04d..05b5c681 100644 --- a/source/BP-Essentials/Methods/Utils/LogMessage.cs +++ b/source/BP-Essentials/Methods/Utils/LogMessage.cs @@ -3,8 +3,8 @@ using System.Linq; using System.Text; using UnityEngine; -using static BP_Essentials.EssentialsVariablesPlugin; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.Variables; +using static BP_Essentials.HookMethods; using System.IO; using System.Threading; @@ -20,13 +20,13 @@ public static void Run(SvPlayer player, string message, string prefix = "") { try { - var mssge = $"{SetTimeStamp.Run()}{prefix}[{(message.StartsWith(CmdCommandCharacter) ? "COMMAND" : "MESSAGE")}] {player.playerData.username}: {message}"; + var mssge = $"{PlaceholderParser.ParseTimeStamp()} {prefix}[{(message.StartsWith(CmdCommandCharacter, StringComparison.CurrentCulture) ? "COMMAND" : "MESSAGE")}] {player.playerData.username}: {message}"; Debug.Log(mssge); int tries = 0; while (tries < 2) try { - if (!message.StartsWith(CmdCommandCharacter)) + if (!message.StartsWith(CmdCommandCharacter, StringComparison.CurrentCulture)) File.AppendAllText(ChatLogFile, mssge + Environment.NewLine); else File.AppendAllText(CommandLogFile, mssge + Environment.NewLine); diff --git a/source/BP-Essentials/Methods/Utils/MultiDictionary.cs b/source/BP-Essentials/Methods/Utils/MultiDictionary.cs new file mode 100644 index 00000000..94b32c69 --- /dev/null +++ b/source/BP-Essentials/Methods/Utils/MultiDictionary.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BP_Essentials.Methods.Utils +{ + public class MultiDictionary : Dictionary, TValue>, IDictionary, TValue> + { + public TValue this[TKey1 key1, TKey2 key2] + { + get { return base[Tuple.Create(key1, key2)]; } + set { base[Tuple.Create(key1, key2)] = value; } + } + public bool TryGetValue(TKey1 key1, TKey2 key2, out TValue value) + { + return base.TryGetValue(Tuple.Create(key1, key2), out value); + } + public void Add(TKey1 key1, TKey2 key2, TValue value) + { + base.Add(Tuple.Create(key1, key2), value); + } + + public bool ContainsKey(TKey1 key1, TKey2 key2) + { + return base.ContainsKey(Tuple.Create(key1, key2)); + } + } +} diff --git a/source/BP-Essentials/Methods/Utils/PlaceholderParser.cs b/source/BP-Essentials/Methods/Utils/PlaceholderParser.cs new file mode 100644 index 00000000..2e3a958f --- /dev/null +++ b/source/BP-Essentials/Methods/Utils/PlaceholderParser.cs @@ -0,0 +1,84 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading.Tasks; +using UnityEngine; +using static BP_Essentials.Variables; + +namespace BP_Essentials +{ + public static class PlaceholderParser + { + public static string ParseString(string str) + { + var src = DateTime.Now; + var hm = new DateTime(src.Year, src.Month, src.Day, src.Hour, src.Minute, src.Second); + var minutes = hm.ToString("mm"); + var seconds = hm.ToString("ss"); + return str + .Replace("{YYYY}", hm.ToString("yyyy")) + .Replace("{DD}", hm.ToString("dd")) + .Replace("{DDDD}", hm.ToString("dddd")) + .Replace("{MMMM}", hm.ToString("MMMM")) + .Replace("{MM}", hm.ToString("MM")) + .Replace("{H}", hm.ToString("HH")) + .Replace("{h}", hm.ToString("hh")) + .Replace("{M}", minutes) + .Replace("{S}", seconds) + .Replace("{T}", hm.ToString("t")); + } + public static string ParseTimeStamp() => ParseTimeStamp(TimestampFormat); + public static string ParseTimeStamp(string Timestamp) + { + try + { + return ParseString(Timestamp); + } + catch (Exception) + { + return "[Failed] "; + } + } + public static string ParseUserMessage(ShPlayer shplayer, string message, string playerMessage) + { + try + { + var src = DateTime.Now; + var hm = new DateTime(src.Year, src.Month, src.Day, src.Hour, src.Minute, src.Second); + var minutes = hm.ToString("mm"); + var seconds = hm.ToString("ss"); + // Improve this mess + return message + .Replace("{YYYY}", hm.ToString("yyyy")) + .Replace("{DD}", hm.ToString("dd")) + .Replace("{DDDD}", hm.ToString("dddd")) + .Replace("{MMMM}", hm.ToString("MMMM")) + .Replace("{MM}", hm.ToString("MM")) + .Replace("{H}", hm.ToString("HH")) + .Replace("{h}", hm.ToString("hh")) + .Replace("{M}", minutes) + .Replace("{S}", seconds) + .Replace("{T}", hm.ToString("tt")) + .Replace("{username}", new Regex("(<)").Replace(shplayer.username, "<")) + .Replace("{id}", $"{shplayer.ID}") + .Replace("{jobname}", Jobs[shplayer.job.jobIndex]) + .Replace("{jobnameofficial}", shplayer.job.info.jobName) + .Replace("{jobindex}", $"{shplayer.job.jobIndex}") + .Replace("{jobcolor}", $"#{ColorUtility.ToHtmlStringRGB(shplayer.job.info.jobColor)}") + .Replace("{discordlink}", MsgDiscord) + .Replace("{infocolor}", infoColor) + .Replace("{warningcolor}", warningColor) + .Replace("{errorcolor}", errorColor) + .Replace("{argcolor}", argColor) + .Replace("{message}", new Regex("(<)").Replace(Chat.LangAndChatBlock.Run(playerMessage), "<")); + } + catch (Exception ex) + { + ErrorLogging.Run(ex); + } + return null; + } + } +} diff --git a/source/BP-Essentials/Methods/Utils/SendDiscordMessage.cs b/source/BP-Essentials/Methods/Utils/SendDiscordMessage.cs index a24c62c6..3acb7f85 100644 --- a/source/BP-Essentials/Methods/Utils/SendDiscordMessage.cs +++ b/source/BP-Essentials/Methods/Utils/SendDiscordMessage.cs @@ -3,8 +3,8 @@ using System.Linq; using System.Text; using UnityEngine; -using static BP_Essentials.EssentialsVariablesPlugin; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.Variables; +using static BP_Essentials.HookMethods; using System.IO; using System.Threading.Tasks; using System.Net; @@ -23,12 +23,12 @@ public static void Run(string json, string link, bool enabled) if (!enabled) return; if (DebugLevel >= 2) - Debug.Log($"{SetTimeStamp.Run()}[INFO] Creating POST request to {link}"); + Debug.Log($"{PlaceholderParser.ParseTimeStamp()} [INFO] Creating POST request to {link}"); var formData = Encoding.UTF8.GetBytes(json); var www = new WWW(link, formData); SvMan.StartCoroutine(WaitForRequest(www)); if (DebugLevel >= 2) - Debug.Log($"{SetTimeStamp.Run()}[INFO] Post request sent!"); + Debug.Log($"{PlaceholderParser.ParseTimeStamp()} [INFO] Post request sent!"); } catch (Exception ex) { @@ -57,7 +57,7 @@ static IEnumerator WaitForRequest(WWW www) { yield return www; if (DebugLevel >= 2) - Debug.Log($"{SetTimeStamp.Run()}[INFO] Post request response received: {(www.text ?? $"[HTTP-ERROR] {www.error}")}"); + Debug.Log($"{PlaceholderParser.ParseTimeStamp()} [INFO] Post request response received: {(www.text ?? $"[HTTP-ERROR] {www.error}")}"); www.Dispose(); } } diff --git a/source/BP-Essentials/Methods/misc/GetIdList.cs b/source/BP-Essentials/Methods/misc/GetIdList.cs index 8b533b97..0282058f 100644 --- a/source/BP-Essentials/Methods/misc/GetIdList.cs +++ b/source/BP-Essentials/Methods/misc/GetIdList.cs @@ -3,8 +3,8 @@ using System.Linq; using System.Text; using UnityEngine; -using static BP_Essentials.EssentialsVariablesPlugin; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.Variables; +using static BP_Essentials.HookMethods; using System.IO; namespace BP_Essentials diff --git a/source/BP-Essentials/Methods/misc/IsOnline.cs b/source/BP-Essentials/Methods/misc/IsOnline.cs index 5ee30e33..2bb91caf 100644 --- a/source/BP-Essentials/Methods/misc/IsOnline.cs +++ b/source/BP-Essentials/Methods/misc/IsOnline.cs @@ -1,5 +1,5 @@ using System; -using static BP_Essentials.EssentialsVariablesPlugin; +using static BP_Essentials.Variables; namespace BP_Essentials { class IsOnline diff --git a/source/BP-Essentials/Methods/misc/Reload.cs b/source/BP-Essentials/Methods/misc/Reload.cs index bcc92cf9..59c31e4f 100644 --- a/source/BP-Essentials/Methods/misc/Reload.cs +++ b/source/BP-Essentials/Methods/misc/Reload.cs @@ -3,8 +3,8 @@ using System.Linq; using System.Text; using UnityEngine; -using static BP_Essentials.EssentialsVariablesPlugin; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.Variables; +using static BP_Essentials.HookMethods; using System.Threading; namespace BP_Essentials @@ -15,55 +15,31 @@ public static void Run(bool silentExecution, SvPlayer player = null, bool IsFirs { try { - if (!silentExecution) - { - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, "[WAIT] Reloading all files.."); - CheckFiles.Run(); - ReadFile.Run(SettingsFile); - ReadCustomCommands.Run(); - ReadGroups.Run(); - Kits.LoadAllKits(); - Warps.LoadAllWarps(); - ReadStream.Run(LanguageBlockFile, LanguageBlockWords); - ReadStream.Run(ChatBlockFile, ChatBlockWords); - ReadStream.Run(AdminListFile, AdminsListPlayers); - LanguageBlockWords = LanguageBlockWords.ConvertAll(d => d.ToLower()); - ChatBlockWords = ChatBlockWords.ConvertAll(d => d.ToLower()); - ReadFile.Run(IdListItemsFile); - ReadFile.Run(IdListVehicleFile); - ReadFile.Run(AnnouncementsFile); - ReadFile.Run(GodListFile); - ReadFile.Run(MuteListFile); - ReadFile.Run(AfkListFile); - ReadFile.Run(RulesFile); - player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, "[OK] Critical .txt files reloaded"); - } - else - { - CheckFiles.Run(); - ReadFile.Run(SettingsFile); - ReadStream.Run(LanguageBlockFile, LanguageBlockWords); - ReadStream.Run(ChatBlockFile, ChatBlockWords); - ReadStream.Run(AdminListFile, AdminsListPlayers); - ReadCustomCommands.Run(); - ReadGroups.Run(); - Kits.LoadAllKits(IsFirstReload); - Warps.LoadAllWarps(IsFirstReload); - LanguageBlockWords = LanguageBlockWords.ConvertAll(d => d.ToLower()); - ChatBlockWords = ChatBlockWords.ConvertAll(d => d.ToLower()); - if (DownloadIdList) - GetIdList.Run(false); - else - { - ReadFile.Run(IdListItemsFile); - ReadFile.Run(IdListVehicleFile); - } - ReadFile.Run(AnnouncementsFile); - ReadFile.Run(GodListFile); - ReadFile.Run(MuteListFile); - ReadFile.Run(AfkListFile); - ReadFile.Run(RulesFile); - } + if (!silentExecution && player != null) + player.SendChatMessage("[WAIT] Reloading all files.."); + CheckFiles.Run(); + ReadFile.Run(SettingsFile); + ReadStream.Run(LanguageBlockFile, LanguageBlockWords); + ReadStream.Run(ChatBlockFile, ChatBlockWords); + ReadStream.Run(AdminListFile, AdminsListPlayers); + ReadCustomCommands.Run(); + ReadGroups.Run(); + LanguageBlockWords = LanguageBlockWords.ConvertAll(d => d.ToLower()); + ChatBlockWords = ChatBlockWords.ConvertAll(d => d.ToLower()); + if (DownloadIdList && player == null) // do not download every time a player /reloads + GetIdList.Run(false); + else + { + ReadFile.Run(IdListItemsFile); + ReadFile.Run(IdListVehicleFile); + } + ReadFile.Run(AnnouncementsFile); + ReadFile.Run(GodListFile); + ReadFile.Run(MuteListFile); + ReadFile.Run(AfkListFile); + ReadFile.Run(RulesFile); + if (!silentExecution && player != null) + player.SendChatMessage("[OK] Critical config files reloaded"); } catch (Exception ex) { diff --git a/source/BP-Essentials/Methods/misc/ReportPlayer.cs b/source/BP-Essentials/Methods/misc/ReportPlayer.cs index 1d589adf..a408b4ce 100644 --- a/source/BP-Essentials/Methods/misc/ReportPlayer.cs +++ b/source/BP-Essentials/Methods/misc/ReportPlayer.cs @@ -5,20 +5,20 @@ namespace BP_Essentials { - class ReportPlayer : EssentialsVariablesPlugin + class ReportPlayer : Variables { public static void Run(string Reporter, string ReportReason, ShPlayer ReportedPlayer) { try { - foreach (var currItem in playerList.Values) + foreach (var currItem in PlayerList.Values) { - if (currItem.Shplayer.admin) + if (currItem.ShPlayer.admin) { if (currItem.LastMenu == CurrentMenu.Main) { - currItem.Shplayer.svPlayer.Send(SvSendType.Self, Channel.Reliable, ClPacket.CloseFunctionMenu); - currItem.Shplayer.svPlayer.Send(SvSendType.Self, Channel.Reliable, ClPacket.ShowFunctionMenu, "New report:\nUsername: " + ReportedPlayer.username + "\nReporter: " + Reporter + "\nReason: " + ReportReason + "\n\nF2: Teleport to player\nF3-11: Close menu\n\nPress F11 To close this (G)UI"); + currItem.ShPlayer.svPlayer.Send(SvSendType.Self, Channel.Reliable, ClPacket.CloseFunctionMenu); + currItem.ShPlayer.svPlayer.Send(SvSendType.Self, Channel.Reliable, ClPacket.ShowFunctionMenu, "New report:\nUsername: " + ReportedPlayer.username + "\nReporter: " + Reporter + "\nReason: " + ReportReason + "\n\nF2: Teleport to player\nF3-11: Close menu\n\nPress F11 To close this (G)UI"); currItem.LastMenu = CurrentMenu.AdminReport; currItem.ReportedPlayer = ReportedPlayer; } diff --git a/source/BP-Essentials/Methods/misc/Save.cs b/source/BP-Essentials/Methods/misc/Save.cs index 0f8c0bed..2affd9b7 100644 --- a/source/BP-Essentials/Methods/misc/Save.cs +++ b/source/BP-Essentials/Methods/misc/Save.cs @@ -3,8 +3,8 @@ using System.Linq; using System.Text; using UnityEngine; -using static BP_Essentials.EssentialsVariablesPlugin; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.Variables; +using static BP_Essentials.HookMethods; namespace BP_Essentials { @@ -28,11 +28,11 @@ public static void Run() { try { - Debug.Log(SetTimeStamp.Run() + "[INFO] Saving game.."); - foreach (var shPlayer in SvMan.players.Values) + Debug.Log($"{PlaceholderParser.ParseTimeStamp()} [INFO] Saving game.."); + foreach (var shPlayer in SvMan.players.Values.ToList()) if (!shPlayer.svPlayer.serverside) { - shPlayer.svPlayer.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, "Saving game.. This can take up to 5 seconds."); + shPlayer.svPlayer.SendChatMessage("Saving game.. This can take up to 5 seconds."); shPlayer.svPlayer.Save(); } } diff --git a/source/BP-Essentials/Methods/misc/SendChatMessage.cs b/source/BP-Essentials/Methods/misc/SendChatMessage.cs index 7b55c651..3556b980 100644 --- a/source/BP-Essentials/Methods/misc/SendChatMessage.cs +++ b/source/BP-Essentials/Methods/misc/SendChatMessage.cs @@ -3,8 +3,8 @@ using System.Linq; using System.Text; using UnityEngine; -using static BP_Essentials.EssentialsVariablesPlugin; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.Variables; +using static BP_Essentials.HookMethods; using System.IO; using System.Threading; using System.Reflection; @@ -15,8 +15,8 @@ class SendChatMessage { public static void Run(string message) { - foreach (var player in playerList.Where(x => x.Value.chatEnabled)) - player.Value.Shplayer.svPlayer.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, message); + foreach (var player in PlayerList.Where(x => x.Value.ChatEnabled)) + player.Value.ShPlayer.svPlayer.SendChatMessage(message); } } } diff --git a/source/BP-Essentials/Methods/misc/SendChatMessageToAdmins.cs b/source/BP-Essentials/Methods/misc/SendChatMessageToAdmins.cs index f66446d9..95691aba 100644 --- a/source/BP-Essentials/Methods/misc/SendChatMessageToAdmins.cs +++ b/source/BP-Essentials/Methods/misc/SendChatMessageToAdmins.cs @@ -3,8 +3,8 @@ using System.Linq; using System.Text; using UnityEngine; -using static BP_Essentials.EssentialsVariablesPlugin; -using static BP_Essentials.EssentialsMethodsPlugin; +using static BP_Essentials.Variables; +using static BP_Essentials.HookMethods; using System.IO; using System.Threading; using System.Reflection; @@ -15,8 +15,8 @@ class SendChatMessageToAdmins { public static void Run(string message) { - foreach (var player in playerList.Where(x =>x.Value.receiveStaffChat && HasPermission.Run(x.Value.Shplayer.svPlayer, CmdStaffChatExecutableBy))) - player.Value.Shplayer.svPlayer.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, message); + foreach (var player in PlayerList.Where(x =>x.Value.ReceiveStaffChat && HasPermission.Run(x.Value.ShPlayer.svPlayer, CmdStaffChatExecutableBy))) + player.Value.ShPlayer.svPlayer.SendChatMessage(message); } } } diff --git a/source/BP-Essentials/Properties/AssemblyInfo.cs b/source/BP-Essentials/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..51051ca7 --- /dev/null +++ b/source/BP-Essentials/Properties/AssemblyInfo.cs @@ -0,0 +1,18 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +[assembly: AssemblyTitle("BP-Essentials")] +[assembly: AssemblyDescription("Basic commands for powerful moderation.")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("BPE - https://userr00t.github.io/BP-Essentials/")] +[assembly: AssemblyCopyright("(c) BP-Essentials.")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] +[assembly: ComVisible(false)] +[assembly: Guid("6898544b-a280-4866-ba6f-9d0dc8f62ca8")] + + + +// Change BPE Version here +[assembly: AssemblyFileVersion("2.6.3")] diff --git a/source/BP-Essentials/Variables.cs b/source/BP-Essentials/Variables.cs new file mode 100644 index 00000000..49dec741 --- /dev/null +++ b/source/BP-Essentials/Variables.cs @@ -0,0 +1,319 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Reflection; +using UnityEngine; + +namespace BP_Essentials +{ + public class Variables : Core + { + public static string Version { get; private set; } = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).FileVersion; + public static bool IsPreRelease => Version.Contains("pre"); + + // Generic Constants + public const string FileDirectory = "Essentials/"; + + public static string LogDirectory = Path.Combine(FileDirectory, "logs/"); + public static string KitDirectory = Path.Combine(FileDirectory, "kits/"); + public static string WarpDirectory = Path.Combine(FileDirectory, "warps/"); + + public const string SettingsFile = FileDirectory + "settings.json"; + public const string LanguageBlockFile = FileDirectory + "languageblock.txt"; + public const string ChatBlockFile = FileDirectory + "chatblock.txt"; + public const string AnnouncementsFile = FileDirectory + "announcements.txt"; + public const string IpListFile = FileDirectory + "ip_list.txt"; + public const string GodListFile = FileDirectory + "godlist.txt"; + public const string AfkListFile = FileDirectory + "afklist.txt"; + public const string MuteListFile = FileDirectory + "mutelist.txt"; + public const string ExceptionFile = FileDirectory + "exceptions.txt"; + public const string CustomCommandsFile = FileDirectory + "CustomCommands.json"; + public const string CustomGroupsFile = FileDirectory + "CustomGroups.json"; + public const string IdListItemsFile = FileDirectory + "ID_list-Items.txt"; + public const string IdListVehicleFile = FileDirectory + "ID_list-Vehicles.txt"; + + public const string AutoReloader = FileDirectory + "autoReloader.txt"; + + public const string AdminListFile = "admin_list.txt"; + public const string RulesFile = "server_info.txt"; + public const string BansFile = "ban_list.txt"; + public static readonly string LogFile = Path.Combine(LogDirectory, "all.txt"); + public static readonly string ChatLogFile = Path.Combine(LogDirectory, "chat.txt"); + public static readonly string CommandLogFile = Path.Combine(LogDirectory, "commands.txt"); + + // Singletons + public static WarpHandler WarpHandler { get; set; } + public static KitsHandler KitsHandler { get; set; } + public static Announcer Announcer { get; set; } = new Announcer(); + + // Bools + public static bool MsgUnknownCommand; + + public static bool ChatBlock; + public static bool LanguageBlock; + public static bool All; + public static bool Unmute; + public static bool MessageToLower; + public static bool EnableAtmCommand; + public static bool Confirmed; + public static bool? EnableBlockSpawnBot; + public static bool ShowDMGMessage; + public static bool VoteKickDisabled; + public static bool DownloadIdList; + public static bool EnableDiscordWebhook_Ban; + public static bool EnableDiscordWebhook_Report; + public static bool BlockBanButtonTabMenu; + public static bool CheckBannedEnabled; + public static bool blockLicenseRemoved; + public static bool ShowJailMessage; + public static bool BlockSuicide; + public static bool BlockMissions; + public static bool ProximityChat; + public static bool LocalChatMute; + public static bool LocalChatMe; + public static bool TimescaleDisabled; + + // Lists + public static List CustomCommands = new List(); + + public static List Responses = new List(); + public static List ChatBlockWords = new List(); + public static List LanguageBlockWords = new List(); + public static List AdminsListPlayers = new List(); + public static List GodListPlayers = new List(); + public static List AfkPlayers = new List(); + public static List MutePlayers = new List(); + public static List LatestVotePeople = new List(); + + public static List BlockedItems = new List(); + + // Dictionary + public static Dictionary PlayerList { get; set; } = new Dictionary(); + public static Dictionary Groups { get; set; } = new Dictionary(); + public static Dictionary CommandList { get; set; } = new Dictionary(); + public static Dictionary WhitelistedJobs { get; set; } = new Dictionary(); + + // MultiDictonary + public static Methods.Utils.MultiDictionary> FunctionMenuKeys { get; set; } = new Methods.Utils.MultiDictionary>(); + + // Arrays + public static string[] Jobs = { + // default values + "Citizen", + "Criminal", + "Prisoner", + "Police", + "Paramedic", + "Firefighter", + "Gangster: Red", + "Gangster: Green", + "Gangster: Blue", + "Mayor", + "DeliveryDriver", + "TaxiDriver", + "Special Forces" + }; + + // Messages + public static string MsgSayPrefix; + + public static string MsgNoPerm; + public static string MsgNoPermJob; + public static string MsgDiscord; + public static string DisabledCommand; + public static string ArgRequired; + public static string PlayerIsAFK; + public static string SelfIsMuted; + public static string NotFoundOnline; + public static string NotFoundOnlineIdOnly; + public static string AdminSearchingInv; + public static string PlayerMessage; + public static string AdminMessage; + public static string AdminChatMessage; + public static string BlockedItemMessage; + public static string MsgNoWantedAllowed; + public static string MsgNoCuffedAllowed; + public static string MsgNoJailAllowed; + public static string MeMessage; + + public static string infoColor, errorColor, warningColor, argColor; + + // Strings + public static string Rules; + + public static string DisabledSpawnBots; + public static string LocalVersion; + public static string MsgSayColor; + public static string AccessMoneyMenu; + public static string AccessItemMenu; + public static string AccessCWMenu; + public static string AccessSetHPMenu; + public static string AccessSetStatsMenu; + public static string CmdCommandCharacter; + + // Commands, still a few needed for easy access + public static string CmdStaffChatExecutableBy; + public static string CmdConfirm; + public static string CmdToggleChat; + public static string CmdTpaaccept; + + + public static string DiscordWebhook_Ban; + public static string DiscordWebhook_Report; + public static string WipePassword; + + public static string NotValidArg = $"Error: Is that a valid number you provided as argument?"; + // Ints + public const int SaveTime = 5 * 60; + + public static int AnnounceIndex; + public static int TimeBetweenAnnounce; + public static int[] BlockedSpawnIds; + public static int DebugLevel; + public static int GodModeLevel; + public static int MessagesAllowedPerSecond; + public static int TimeBetweenDelay; + + // Misc. + public static string _msg; + + public static string username; + public static string TimestampFormat; + public const string CensoredText = "******"; + public const string PatternTemplate = @"\b({0})(s?)\b"; + + public static SvManager SvMan; + + [Obsolete("Maps can be custom now, so should be removed in future update or manually added by server owners.")] + public static Dictionary PlaceDictionary = new Dictionary + { + { new[] { "1", "PoliceStation", "Police Station" }, new Vector3(-17.0F, 0.0F, 46.0F) }, + { new[] { "2", "FireStation", "Fire Station" }, new Vector3(173.0F, 0.0F, 237.0F)}, + { new[] { "3", "Hospital", "Ambulance Station" }, new Vector3(111.0F, 0.0F, 148.0F)}, + { new[] { "4", "GunShop", "Gun Shop", "ammunition" }, new Vector3(55.0F, 0.0F, 112.0F) }, + { new[] { "5", "ElectronicsShop", "Electronics Shop" }, new Vector3(567.0F, 0.0F, -92.0F) }, + { new[] { "6", "PawnShop", "Pawn Shop" }, new Vector3(448.0F, 0.0F, -203.0F) }, + { new[] { "7", "FastFoodShop", "Fast Food Shop" }, new Vector3(645.0F, 0.0F, -168.0F) }, + { new[] { "8", "CoffeeShop", "Coffee Shop" }, new Vector3(618.0F, 0.0F, 148.0F) }, + { new[] { "9", "ClothingShop", "Clothing Shop" }, new Vector3(595.0F, 0.0F, 81.0F) }, + { new[] { "10", "GreenGang", "Green St. Fam Boss" }, new Vector3(32.0F, 0.0F, -202.0F) }, + { new[] { "11", "BlueGang", "Borgata Blue Boss" }, new Vector3(504.0F, 0.0F, 23.0F) }, + { new[] { "12", "RedGang", "Rojo Loco Boss" }, new Vector3(521.0F, 0.0F, 199.0F) }, + { new[] { "13", "10k", "Large Apartment" }, new Vector3(2.0F, 0.0F, -92.0F) }, + { new[] { "14", "5k", "Medium Apartment" }, new Vector3(519.0F, 0.0F, -125.0F) }, + { new[] { "15", "1.2k", "Small Apartment" }, new Vector3(643.0F, 0.0F, -61.0F) }, + { new[] { "16", "DeliveryJob", "Delivery Job" }, new Vector3(64.0F, 0.0F, -92.0F) }, + { new[] { "17", "TaxiJob", "Taxi Job" }, new Vector3(-232.0F, 0.0F, 87.0F) }, + { new[] { "18", "TownHall", "Town Hall", "Mayor", "MayorOffice" }, new Vector3(127.0F, 0.0F, -56.0F) }, + { new[] { "19", "Bank" }, new Vector3(447.0F, 0.0F, -23.0F) }, + { new[] { "20", "DrugDealer", "Drug Dealer" }, new Vector3(288.0F, 0.0F, -236.0F) }, + { new[] { "21", "SpecOps", "Spec Ops Job", "MilitaryBase", "Military Base" }, new Vector3(654.0F, 0.0F, 278.0F) }, + { new[] { "22", "Bomb", "BombLocation", "Bomb Location" }, new Vector3(1010.0F, 0.0F, 401.0F) } + }; + + public static string[] ReportReasons = + { + // default values + "Random Vote Kick", + "Committing suicide/Disconnecting while arrested", + "Hacks/Exploits/Cheats", + "Pretending to be an admin", + "RDM as cop", + "RDA as cop", + "Bad username", + "Bullying, Harrasing, or Discriminating someone", + "Alternative account's (alts)" + }; + + public static int[] CommonIDs = + { + // need a better way of doing this + 493970259, // Pistol Ammo + -479434394, // Handcuffs + -906852676, // Taser Ammo + -700261193, //License Boating + 1695812550, //License Drivers + 499504400, //License Gun + 607710552 //License Pilots + }; + public static int[] IDs_Vehicles; + public static int[] IDs_Items; + } + public class LastLocation + { + public Vector3 Position { get; private set; } + public Quaternion Rotation { get; private set; } + public int PlaceIndex { get; private set; } + public void Update(Vector3 position, Quaternion rotation, int index) + { + Position = position; + Rotation = rotation; + PlaceIndex = index; + } + public bool HasPositionSet() + { + return Position != default(Vector3) && Rotation != default(Quaternion); + } + public LastLocation(Vector3 position, Quaternion rotation, int index) + { + Update(position, rotation, index); + } + public LastLocation() + { + + } + } + public class _CommandList + { + public Action RunMethod; + public List commandCmds; + public bool commandDisabled; + public string commandGroup; + public string commandName; + public bool commandWantedAllowed; + public bool commandHandcuffedAllowed; + public bool commandWhileJailedAllowed; + } + + public class PlayerListItem + { + public PlayerListItem(ShPlayer player) + { + ShPlayer = player; + } + public ShPlayer ShPlayer { get; set; } + public CurrentMenu LastMenu { get; set; } + public ShPlayer ReportedPlayer { get; set; } + public string ReportedReason { get; set; } + public bool ChatEnabled { get; set; } = true; + public bool StaffChatEnabled { get; set; } + public bool ReceiveStaffChat { get; set; } = true; + public bool SpyEnabled { get; set; } + public int MessagesSent { get; set; } + public bool IsCurrentlyAwaiting { get; set; } + public ShPlayer ReplyToUser { get; set; } + public ShPlayer TpaUser { get; set; } + public LastLocation LastLocation { get; set; } = new LastLocation(); + } + + public class _Group + { + public string Name; + public string Message; + public List Users = new List(); + } + + public enum CurrentMenu + { + None, + Main, + Help, + Staff, + GiveMoney, + GiveItems, + ServerInfo, + Report, + AdminReport + } +} \ No newline at end of file