From 3a3f18667331ed1e5e080f442561bf5520b1eb55 Mon Sep 17 00:00:00 2001 From: Dawid Bepierszcz <41084667+daffyyyy@users.noreply.github.com> Date: Wed, 15 Nov 2023 12:51:01 +0100 Subject: [PATCH 1/3] Update Config.cs --- Config.cs | 42 +++++++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/Config.cs b/Config.cs index ec0a77df..fee6e764 100644 --- a/Config.cs +++ b/Config.cs @@ -1,32 +1,56 @@ -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; } = ""; + public string DatabaseHost { get; set; } = "localhost"; [JsonPropertyName("DatabasePort")] public int DatabasePort { get; set; } = 3306; [JsonPropertyName("DatabaseUser")] - public string DatabaseUser { get; set; } = ""; + public string DatabaseUser { get; set; } = "DBUSER"; [JsonPropertyName("DatabasePassword")] - public string DatabasePassword { get; set; } = ""; + public string DatabasePassword { get; set; } = "DBPASSWORD"; [JsonPropertyName("DatabaseName")] - public string DatabaseName { get; set; } = ""; + public string DatabaseName { get; set; } = "DBDATABASE"; [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(); } + } From f01d4b0bf04611c6f7ea1512c470eba472424d81 Mon Sep 17 00:00:00 2001 From: Dawid Bepierszcz <41084667+daffyyyy@users.noreply.github.com> Date: Wed, 15 Nov 2023 12:52:07 +0100 Subject: [PATCH 2/3] Update WeaponPaints.cs --- WeaponPaints.cs | 62 ++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 53 insertions(+), 9 deletions(-) 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 +} From 9f982d1e63e9298c67a262d0e038649d3b6c0373 Mon Sep 17 00:00:00 2001 From: Dawid Bepierszcz <41084667+daffyyyy@users.noreply.github.com> Date: Wed, 15 Nov 2023 13:03:16 +0100 Subject: [PATCH 3/3] Update Config.cs --- Config.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Config.cs b/Config.cs index fee6e764..d190834d 100644 --- a/Config.cs +++ b/Config.cs @@ -26,19 +26,19 @@ public class WeaponPaintsConfig : BasePluginConfig public override int Version { get; set; } = 2; [JsonPropertyName("DatabaseHost")] - public string DatabaseHost { get; set; } = "localhost"; + public string DatabaseHost { get; set; } = ""; [JsonPropertyName("DatabasePort")] public int DatabasePort { get; set; } = 3306; [JsonPropertyName("DatabaseUser")] - public string DatabaseUser { get; set; } = "DBUSER"; + public string DatabaseUser { get; set; } = ""; [JsonPropertyName("DatabasePassword")] - public string DatabasePassword { get; set; } = "DBPASSWORD"; + public string DatabasePassword { get; set; } = ""; [JsonPropertyName("DatabaseName")] - public string DatabaseName { get; set; } = "DBDATABASE"; + public string DatabaseName { get; set; } = ""; [JsonPropertyName("CmdRefreshCooldownSeconds")] public int CmdRefreshCooldownSeconds { get; set; } = 60;