How do I make the GroupName prefix come after the Clan tag?Solved

For anyone using BetterChat with the Clans or ClansReborn plugin, were you able to swap the position of the BetterChat GroupName prefix and the Clan Tags? This is what I have right now:

img

I would like them to show up in this order instead:

[Team] [ABC] [VIP] PolarKC: test

Any help or advice is really appreciated! I've considered going into the source and mucking around because I haven't found a way to handle this in either plugin's configuration natively.

I see in the BetterChat.json data file that the format is:

      "Chat": "{Title} {Username}: {Message}",

The fact that the clan tag is coming after {title} makes me think the Clans plugin might be inserting the tag inbetween the {title} and {username}
I'll keep digging and post an answer to this if I find one. Otherwise, any help is still appreciated!


Merged post

Learning more...

      "Chat": "{Username} {Title}: {Message}",

C54MQ7xfgV3dikS.png

It appears {Title} includes the GroupName prefix and the clan tag. Originally I thought {Username} included a player's name and clan tag, but that isn't the case.



Merged post

I've determined a solution by looking through the BetterChat.cs code.
The title reverse happens in the BetterChatMessage FormatMessage method on lines 797-799.
The title reverse happens before titles from third party plugins are added to the dictionary of titles in lines 802-815.

if (_instance._config.ReverseTitleOrder)
{
    titles.Reverse();
}   

foreach (var thirdPartyTitle in _instance._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}");
    }
}


A potential solution to _my problem_ is simply to have the titles.Reverse() call come after the foreach loop that adds third party titles, like so:

foreach (var thirdPartyTitle in _instance._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}");
    }
}

if (_instance._config.ReverseTitleOrder)
{
    titles.Reverse();
}   

Here is the result of the code change. Setting "Reverse Title Order" to true or false in the BetterChat.json file now impacts the order with third party applications.

v0a8bTRaPdh5IUI.png

 

We can make this solution more nuanced by introducing a new configuration option to BetterChat, something like "Include Third Party Titles in Reverse" that can be set to true or false. When false the current functionality is used (reverse is called before adding 3rd party titles), and when set to true the new functionality is used (reverse is called after adding 3rd party titles).



Merged post

For anyone that wants to drop in the new code, here is a fork of BetterChat. This may or may not get merged into the main plugin, so hopefully this is helpful to someone.

https://github.com/PolarKC/BetterChat

https://github.com/PolarKC/BetterChat/commit/2abfa2f830f3beb1edc52754d97457b08dfc9123

 



Merged post

Pull request to main plugin repo:
https://github.com/LaserHydra/BetterChat/pull/3

Locked automatically