diff --git a/Config.cs b/Config.cs index ec0a77df..d190834d 100644 --- a/Config.cs +++ b/Config.cs @@ -1,11 +1,29 @@ -using CounterStrikeSharp.API.Core; +using CounterStrikeSharp.API.Core; using System.Text.Json.Serialization; namespace WeaponPaints { + public class Messages + { + [JsonPropertyName("WebsiteMessageCommand")] + public string WebsiteMessageCommand { get; set; } = "Visit {WEBSITE} where you can change skins."; + [JsonPropertyName("SynchronizeMessageCommand")] + public string SynchronizeMessageCommand { get; set; } = "Type !wp to synchronize chosen skins."; + [JsonPropertyName("KnifeMessageCommand")] + public string KnifeMessageCommand { get; set; } = "Type !knife to open knife menu."; + [JsonPropertyName("CooldownRefreshCommand")] + public string CooldownRefreshCommand { get; set; } = "You can't refresh weapon paints right now."; + [JsonPropertyName("SuccessRefreshCommand")] + public string SuccessRefreshCommand { get; set; } = "Refreshing weapon paints."; + [JsonPropertyName("ChosenKnifeMenu")] + public string ChosenKnifeMenu { get; set; } = "You have chosen {KNIFE} as your knife."; + [JsonPropertyName("KnifeMenuTitle")] + public string KnifeMenuTitle { get; set; } = "Knife Menu."; + } + public class WeaponPaintsConfig : BasePluginConfig { - public override int Version { get; set; } = 1; + public override int Version { get; set; } = 2; [JsonPropertyName("DatabaseHost")] public string DatabaseHost { get; set; } = ""; @@ -25,8 +43,14 @@ public class WeaponPaintsConfig : BasePluginConfig [JsonPropertyName("CmdRefreshCooldownSeconds")] public int CmdRefreshCooldownSeconds { get; set; } = 60; - [JsonPropertyName("WebSite")] - public string WebSite { get; set; } = "http://wp.example.com"; - + [JsonPropertyName("Prefix")] + public string Prefix { get; set; } = "[WeaponPaints]"; + + [JsonPropertyName("Website")] + public string Website { get; set; } = "example.com/skins"; + + [JsonPropertyName("Messages")] + public Messages Messages { get; set; } = new Messages(); } + } diff --git a/WeaponPaints.cs b/WeaponPaints.cs index da86bad2..3f270885 100644 --- a/WeaponPaints.cs +++ b/WeaponPaints.cs @@ -9,6 +9,8 @@ using Nexd.MySQL; using System.Runtime.ExceptionServices; using static CounterStrikeSharp.API.Core.Listeners; +using System.Reflection; + namespace WeaponPaints; public class WeaponPaints : BasePlugin, IPluginConfig @@ -22,7 +24,6 @@ public class WeaponPaints : BasePlugin, IPluginConfig MySqlDb? MySql = null; private DateTime[] commandCooldown = new DateTime[Server.MaxPlayers]; - private static string PluginPrefix = $" {ChatColors.Green}[WeaponPaints]{ChatColors.White}"; private Dictionary> gPlayerWeaponPaints = new(); private Dictionary> gPlayerWeaponSeed = new(); private Dictionary> gPlayerWeaponWear = new(); @@ -243,14 +244,17 @@ public static bool PlayerHasKnife(CCSPlayerController player) } private void SetupMenus() { - var giveItemMenu = new ChatMenu("Knife Menu"); + var giveItemMenu = new ChatMenu(ReplaceTags(Config.Messages.KnifeMenuTitle)); var handleGive = (CCSPlayerController player, ChatMenuOption option) => { if (knifeTypes.TryGetValue(option.Text, out var knife)) { Task.Run(() => SyncKnifeToDatabase((int)player.EntityIndex!.Value.Value, knife)); g_playersKnife[(int)player.EntityIndex!.Value.Value] = knifeTypes[option.Text]; - player.PrintToChat($"You have chosen {option.Text} as your knife."); + if (!string.IsNullOrEmpty(Config.Messages.ChosenKnifeMenu)) { + string temp = $"{Config.Prefix} {Config.Messages.ChosenKnifeMenu}".Replace("{KNIFE}", option.Text); + player.PrintToChat(ReplaceTags(temp)); + } RemoveKnifeFromPlayer(player); } }; @@ -264,23 +268,42 @@ private void SetupMenus() public void OnCommandRefresh(CCSPlayerController? player, CommandInfo command) { if (player == null) return; + string temp = ""; int playerIndex = (int)player.EntityIndex!.Value.Value; if (DateTime.UtcNow >= commandCooldown[playerIndex].AddSeconds(Config.CmdRefreshCooldownSeconds)) { commandCooldown[playerIndex] = DateTime.UtcNow; Task.Run(async () => await GetWeaponPaintsFromDatabase(playerIndex)); - player.PrintToChat($"{PluginPrefix} Refreshing weapon paints."); + if (!string.IsNullOrEmpty(Config.Messages.SuccessRefreshCommand)) { + temp = $"{Config.Prefix} {Config.Messages.SuccessRefreshCommand}"; + player.PrintToChat(ReplaceTags(temp)); + } return; } - player.PrintToChat($"{PluginPrefix} You can't refresh weapon paints right now."); + if (!string.IsNullOrEmpty(Config.Messages.CooldownRefreshCommand)) { + temp = $"{Config.Prefix} {Config.Messages.CooldownRefreshCommand}"; + player.PrintToChat(ReplaceTags(temp)); + } } [ConsoleCommand("css_ws", "weaponskins")] public void OnCommandWS(CCSPlayerController? player, CommandInfo command) { if (player == null) return; - player.PrintToChat($"{PluginPrefix} Visit {ChatColors.Purple}{Config.WebSite} {ChatColors.White}where you can change skins."); - player.PrintToChat($"{PluginPrefix} Type {ChatColors.Purple}!wp {ChatColors.White}in chat to synchronize chosen skins."); - player.PrintToChat($"{PluginPrefix} Type {ChatColors.Purple}!knife {ChatColors.White}in chat to open knife menu."); + + string temp = ""; + + if (!string.IsNullOrEmpty(Config.Messages.WebsiteMessageCommand)) { + temp = $"{Config.Prefix} {Config.Messages.WebsiteMessageCommand}"; + player.PrintToChat(ReplaceTags(temp)); + } + if (!string.IsNullOrEmpty(Config.Messages.SynchronizeMessageCommand)) { + temp = $"{Config.Prefix} {Config.Messages.SynchronizeMessageCommand}"; + player.PrintToChat(ReplaceTags(temp)); + } + if (!string.IsNullOrEmpty(Config.Messages.KnifeMessageCommand)) { + temp = $"{Config.Prefix} {Config.Messages.KnifeMessageCommand}"; + player.PrintToChat(ReplaceTags(temp)); + } } public static CSkeletonInstance GetSkeletonInstance(CGameSceneNode node) { @@ -377,6 +400,27 @@ private async Task SyncKnifeToDatabase(int playerIndex, string knife) return; } } + + private string ReplaceTags(string message) + { + if (message.Contains('{')) + { + string modifiedValue = message; + modifiedValue = modifiedValue.Replace("{WEBSITE}", Config.Website); + foreach (FieldInfo field in typeof(ChatColors).GetFields()) + { + string pattern = $"{{{field.Name}}}"; + if (message.Contains(pattern, StringComparison.OrdinalIgnoreCase)) + { + modifiedValue = modifiedValue.Replace(pattern, field.GetValue(null)!.ToString(), StringComparison.OrdinalIgnoreCase); + } + } + return modifiedValue; + } + + return message; + } + private static void Log(string message) { Console.BackgroundColor = ConsoleColor.DarkGray; @@ -384,4 +428,4 @@ private static void Log(string message) Console.WriteLine(message); Console.ResetColor(); } -} \ No newline at end of file +}