diff --git a/RespawnTimer/API/Features/TimerView.cs b/RespawnTimer/API/Features/TimerView.cs index 41c1c50..624e4d1 100644 --- a/RespawnTimer/API/Features/TimerView.cs +++ b/RespawnTimer/API/Features/TimerView.cs @@ -10,6 +10,7 @@ #if EXILED using Exiled.API.Features; using Exiled.Loader; + using System; #else using PluginAPI.Core; #endif @@ -69,6 +70,19 @@ public static void AddTimer(string name) CachedTimers.Add(name, timerView); } + public static void AddReplaceHelper(string name, Func action) + { + ReplaceHelper.Add(name, action); + } + + public static void RemoveReplaceHelper(string name) + { + if (!ReplaceHelper.ContainsKey(name)) + return; + + ReplaceHelper.Remove(name); + } + public static bool TryGetTimerForPlayer(Player player, out TimerView timerView) { string groupName = !ServerStatic.PermissionsHandler._members.TryGetValue(player.UserId, out string str) ? null : str; @@ -100,7 +114,7 @@ public static bool TryGetTimerForPlayer(Player player, out TimerView timerView) return false; } - public string GetText(int? spectatorCount = null) + public string GetText(Player player, int? spectatorCount = null) { StringBuilder.Clear(); StringBuilder.Append( @@ -108,8 +122,14 @@ RespawnManager.Singleton._curSequence is not RespawnManager.RespawnSequencePhase ? BeforeRespawnString : DuringRespawnString); + foreach (KeyValuePair> data in ReplaceHelper) + { + StringBuilder.Replace("{" + data.Key + "}", data.Value(player)); + } + SetAllProperties(spectatorCount); - StringBuilder.Replace("{RANDOM_COLOR}", $"#{Random.Range(0x0, 0xFFFFFF):X6}"); + + StringBuilder.Replace("{RANDOM_COLOR}", $"#{UnityEngine.Random.Range(0x0, 0xFFFFFF):X6}"); StringBuilder.Replace('{', '[').Replace('}', ']'); return StringBuilder.ToString(); @@ -149,5 +169,7 @@ private TimerView(string beforeRespawnString, string duringRespawnString, Proper public List Hints { get; } private readonly StringBuilder StringBuilder = new(1024); + + public static Dictionary> ReplaceHelper { get; } = new(); } } \ No newline at end of file diff --git a/RespawnTimer/EventHandler.cs b/RespawnTimer/EventHandler.cs index cd5047e..f24a52b 100644 --- a/RespawnTimer/EventHandler.cs +++ b/RespawnTimer/EventHandler.cs @@ -138,7 +138,7 @@ private IEnumerator TimerCoroutine() if (!TimerView.TryGetTimerForPlayer(player, out TimerView timerView)) continue; - string text = timerView.GetText(specNum); + string text = timerView.GetText(player, specNum); #if EXILED player.ShowHint(text, 1.25f);