BungeeTabListPlus icon indicating copy to clipboard operation
BungeeTabListPlus copied to clipboard

[Suggestion] Add !regex selection option for customPlaceholders

Open Sir-Will opened this issue 4 years ago • 4 comments

It would be great to have an option which allows to use a regex on existing placeholders.

My use case would be to get the first or last two letters of ${player vault_prefix} to then use them in the afk_tag placeholder.

Sir-Will avatar Aug 27 '20 15:08 Sir-Will

Sorry for the late response.

I am a bit in the unclear as to how this would work. There are two ways of using regular expressions to transform text that I can think of off the top of my head. On is search and replace, which is not what you're looking for and the other is to match the text and then extract a specific group of characters. For the latter option one needs to think of what happens when the text doesn't match, and which group to extract. So more details would be welcome.

Something you are probably not aware of is that there is a mechanism in the plugin to extract the first x characters of a placeholder. E.g. ${player vault_prefix 2} will give you the first two characters of the prefix. This is not very intuitive, that's why it is not documented.

CodeCrafter47 avatar Sep 13 '20 09:09 CodeCrafter47

I was looking for match but implementing replace too would probably be not that much more work.

Here is a draft of what the config could look like which might help with understanding it better.

pattern is being applied to match, which it's placeholders are replaced first. Then depending on if there is a match true or false will be the result. In true you can reference the extracted groups with $<group number>

customPlaceholders:
  afk_tag_with_short_prefix:
    !regex
    match: ${player vault_prefix}
    pattern: /(..$)/
    true: "${afk_tag}$1"
    false: ""

Something you are probably not aware of is that there is a mechanism in the plugin to extract the first x characters of a placeholder. E.g. ${player vault_prefix 2} will give you the first two characters of the prefix. This is not very intuitive, that's why it is not documented.

Oh, thank you. That should already help.

Sir-Will avatar Sep 13 '20 09:09 Sir-Will

Thanks for the explanations. So it would be like a conditional, but instead of a condition, there is a pattern that is matched to some text. This looks like something I can implement.

CodeCrafter47 avatar Sep 13 '20 15:09 CodeCrafter47

Yes and the regex groups can be used in the output.

Sir-Will avatar Sep 13 '20 16:09 Sir-Will