Skip to content

Commit

Permalink
fix: Connect/Disconnect message parentheses
Browse files Browse the repository at this point in the history
  • Loading branch information
K4ryuu committed May 17, 2024
1 parent 92a558c commit 5ebc517
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 19 deletions.
2 changes: 1 addition & 1 deletion K4-System/src/Module/Utils/UtilsEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
}
Expand Down
7 changes: 0 additions & 7 deletions K4-System/src/Plugin/PluginConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion K4-System/src/Plugin/PluginDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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"])));
}
}
}
23 changes: 14 additions & 9 deletions K4-System/src/Plugin/PluginStock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, char> 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()));
Expand Down Expand Up @@ -134,19 +139,19 @@ public string ReplacePlaceholders(K4Player k4player, string text)
{
Dictionary<string, string> placeholders = new Dictionary<string, string>
{
{ "{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;
Expand Down
5 changes: 4 additions & 1 deletion K4-System/src/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

0 comments on commit 5ebc517

Please sign in to comment.