From 5ebc51705dd4f8e084a0a736ebff5aac9f1d14e5 Mon Sep 17 00:00:00 2001 From: K4ryuu <104531589+K4ryuu@users.noreply.github.com> Date: Fri, 17 May 2024 10:03:53 +0200 Subject: [PATCH] fix: Connect/Disconnect message parentheses --- K4-System/src/Module/Utils/UtilsEvents.cs | 2 +- K4-System/src/Plugin/PluginConfig.cs | 7 ------- K4-System/src/Plugin/PluginDatabase.cs | 2 +- K4-System/src/Plugin/PluginStock.cs | 23 ++++++++++++++--------- K4-System/src/lang/en.json | 5 ++++- 5 files changed, 20 insertions(+), 19 deletions(-) diff --git a/K4-System/src/Module/Utils/UtilsEvents.cs b/K4-System/src/Module/Utils/UtilsEvents.cs index 17dfab6..59ee0ae 100644 --- a/K4-System/src/Module/Utils/UtilsEvents.cs +++ b/K4-System/src/Module/Utils/UtilsEvents.cs @@ -18,7 +18,7 @@ public void Initialize_Events() if (k4player is null || !k4player.IsValid || !k4player.IsPlayer) return HookResult.Continue; - Server.PrintToChatAll(plugin.ReplacePlaceholders(k4player, plugin.ApplyPrefixColors(Config.UtilSettings.DisconnectMessage))); + Server.PrintToChatAll(plugin.ReplacePlaceholders(k4player, plugin.Localizer["k4.announcement.disconnect"])); return HookResult.Continue; }); } diff --git a/K4-System/src/Plugin/PluginConfig.cs b/K4-System/src/Plugin/PluginConfig.cs index 7e550c8..fd424ff 100644 --- a/K4-System/src/Plugin/PluginConfig.cs +++ b/K4-System/src/Plugin/PluginConfig.cs @@ -75,15 +75,8 @@ public sealed class UtilSettings [JsonPropertyName("connect-message-enable")] public bool ConnectMessageEnable { get; set; } = true; - [JsonPropertyName("connect-message")] - public string ConnectMessage { get; set; } = "» {green}{rank} {name} {orange}has joined the server from {lightred}{country}"; - [JsonPropertyName("disconnect-message-enable")] public bool DisconnectMessageEnable { get; set; } = true; - - [JsonPropertyName("disconnect-message")] - public string DisconnectMessage { get; set; } = "» {green}{rank} {name} {orange}has left the server with {lightred}{points} points"; - } public sealed class CommandSettings diff --git a/K4-System/src/Plugin/PluginDatabase.cs b/K4-System/src/Plugin/PluginDatabase.cs index 0b11d28..6b94166 100644 --- a/K4-System/src/Plugin/PluginDatabase.cs +++ b/K4-System/src/Plugin/PluginDatabase.cs @@ -555,7 +555,7 @@ public void LoadPlayerRowToCache(K4Player k4player, dynamic row, bool all) if (!all) { K4Players.Add(k4player); - Server.NextWorldUpdate(() => Server.PrintToChatAll(ReplacePlaceholders(k4player, ApplyPrefixColors(Config.UtilSettings.ConnectMessage)))); + Server.NextWorldUpdate(() => Server.PrintToChatAll(ReplacePlaceholders(k4player, Localizer["k4.announcement.connect"]))); } } } \ No newline at end of file diff --git a/K4-System/src/Plugin/PluginStock.cs b/K4-System/src/Plugin/PluginStock.cs index d6dcde0..ad14082 100644 --- a/K4-System/src/Plugin/PluginStock.cs +++ b/K4-System/src/Plugin/PluginStock.cs @@ -10,9 +10,14 @@ namespace K4System using MaxMind.GeoIP2; using Microsoft.Extensions.Logging; using MaxMind.GeoIP2.Exceptions; + using System.Reflection; public sealed partial class Plugin : BasePlugin { + private static readonly Dictionary PredefinedColors = typeof(ChatColors) + .GetFields(BindingFlags.Public | BindingFlags.Static) + .ToDictionary(field => $"{{{field.Name}}}", field => (char)(field.GetValue(null) ?? '\x01')); + public string ApplyPrefixColors(string msg) { var chatColors = typeof(ChatColors).GetFields().Select(f => (f.Name, Value: f.GetValue(null)?.ToString())); @@ -134,19 +139,19 @@ public string ReplacePlaceholders(K4Player k4player, string text) { Dictionary placeholders = new Dictionary { - { "{name}", k4player.PlayerName }, - { "{steamid}", k4player.SteamID.ToString() }, - { "{clantag}", k4player.ClanTag }, - { "{rank}", k4player.rankData?.Rank.Name ?? "Unranked" }, - { "{country}", GetPlayerCountryCode(k4player.Controller) }, - { "{points}", k4player.rankData?.Points.ToString() ?? "0" }, - { "{topplacement}", k4player.rankData?.TopPlacement.ToString() ?? "0" }, - { "{playtime}", k4player.timeData?.TimeFields["all"].ToString() ?? "0" }, + { "name", k4player.PlayerName }, + { "steamid", k4player.SteamID.ToString() }, + { "clantag", k4player.ClanTag }, + { "rank", k4player.rankData?.Rank.Name ?? "Unranked" }, + { "country", GetPlayerCountryCode(k4player.Controller) }, + { "points", k4player.rankData?.Points.ToString() ?? "0" }, + { "topplacement", k4player.rankData?.TopPlacement.ToString() ?? "0" }, + { "playtime", k4player.timeData?.TimeFields["all"].ToString() ?? "0" }, }; foreach (var placeholder in placeholders) { - text = text.Replace(placeholder.Key, placeholder.Value); + text = text.Replace($"{{{placeholder.Key}}}", placeholder.Value); } return text; diff --git a/K4-System/src/lang/en.json b/K4-System/src/lang/en.json index 39547ed..498bca5 100644 --- a/K4-System/src/lang/en.json +++ b/K4-System/src/lang/en.json @@ -121,5 +121,8 @@ "k4.phrases.shortday": "d", "k4.phrases.shorthour": "h", "k4.phrases.shortminute": "m", - "k4.phrases.shortsecond": "s" + "k4.phrases.shortsecond": "s", + + "k4.announcement.connect": "» {green}{rank} {name} {orange}has joined the server from {lightred}{country}", + "k4.announcement.disconnect": "» {green}{rank} {name} {orange}has left the server with {lightred}{points} points" }