diff --git a/BetterChat.cs b/BetterChat.cs index 3ca7287..ef81841 100644 --- a/BetterChat.cs +++ b/BetterChat.cs @@ -39,7 +39,7 @@ internal class BetterChat : CovalencePlugin }; #endif - #endregion + #endregion #region Classes @@ -69,6 +69,23 @@ public ChatGroup.FormatSettings GetOutput() ["Date"] = DateTime.Now.ToString() }; + foreach (var thirdPartyTitle in ThirdPartyTitles) + { + try + { + string title = thirdPartyTitle.Value(Player); + + if (!string.IsNullOrEmpty(title)) + replacements.Add(thirdPartyTitle.Key.Name, title); + else + replacements.Add(thirdPartyTitle.Key.Name, ""); + } + catch (Exception ex) + { + Instance.PrintError($"Error when trying to get third-party title from plugin '{thirdPartyTitle.Key}'{Environment.NewLine}{ex}"); + } + } + output.Chat = Format.Chat; output.Console = Format.Console; @@ -78,11 +95,11 @@ public ChatGroup.FormatSettings GetOutput() output.Chat = Instance.covalence.FormatText(output.Chat.Replace($"{{{replacement.Key}}}", replacement.Value)); } - if (output.Chat.StartsWith(" ")) - output.Chat = output.Chat.Remove(0, 1); + output.Chat = Regex.Replace(output.Chat, "[ ]{2,}"," "); + output.Chat = output.Chat.Trim(); - if (output.Console.StartsWith(" ")) - output.Console = output.Console.Remove(0, 1); + output.Console = Regex.Replace(output.Console, "[ ]{2,}"," "); + output.Console = output.Console.Trim(); return output; } @@ -222,21 +239,6 @@ public static BetterChatMessage FormatMessage(IPlayer player, string message) titles = titles.GetRange(0, Math.Min(Configuration.MaxTitles, titles.Count)); - foreach (var thirdPartyTitle in ThirdPartyTitles) - { - try - { - string title = thirdPartyTitle.Value(player); - - if (!string.IsNullOrEmpty(title)) - titles.Add(title); - } - catch (Exception ex) - { - Instance.PrintError($"Error when trying to get third-party title from plugin '{thirdPartyTitle.Key}'{Environment.NewLine}{ex}"); - } - } - return new BetterChatMessage { Player = player, @@ -316,7 +318,7 @@ public class FormatSettings public string Chat = "{Title} {Username}: {Message}"; public string Console = "{Title} {Username}: {Message}"; } - + public class Field { public Func Getter { get; } diff --git a/README.md b/README.md index 3a38442..7ce1b99 100644 --- a/README.md +++ b/README.md @@ -47,9 +47,12 @@ You can do a lot with the formatting of a group. You can customize it with: - **{Date}** = Date Stamp - **{Time}** = Time Stamp - **{Group}** = Primary Group +- **{PluginName}** = Titles added by third party plugins* ... but also just add words, letters, numbers, and symbols to it. You could just put the Title behind the name for example. +\* Third party titles are registered using the build in BetterChat API. An example for one of those titles is `{Clans}` when the [Clans](https://umod.org/plugins/clans) plugin is installed. + ## Chat Group Setup For setting groups up, use the command 'chat'. If you want to set it up in the chat, you need to grant yourself the permission `betterchat.admin` and prefix the command with a forward slash (/). You can grant yourself the permission by typing the following command into the server console where you replace `` with your username or ID *(Steam ID for most games)*: `oxide.grant user betterchat.admin` Now you can use the command '/chat' in the chat. @@ -192,7 +195,7 @@ To get chat groups a player is in: private List API_GetUserGroups(IPlayer player) ``` -To register a title for players: +To register a title for players: (One per plugin, the plugin name is used as replacement tag in the config) ```csharp private void API_RegisterThirdPartyTitle(Plugin plugin, Func titleGetter) ```