Fix for Colored String Case
Description
This PR fixes an issue when using the string case expression with colored strings. Not exactly sure why it's showing commits from a different branch, sorry about that.
Target Minecraft Versions: any Requirements: none Related Issues: https://github.com/SkriptLang/Skript/issues/4602
Proposal
I had an idea about this, probably easier and cleaner here how it goes:
- You make a little parser (something like this) to walk each character from last to beginning (important) and find chat colors/tags/hex codes by:
- Read first > and go to next < then regex check the inside of it
- Read & and chacter on its right and do regex heck
- Read # and the 3-6 characters on its right and do regex heck
Then cut them from the text, save it with its first character position (most left character) in a map and move on
Once the text is filtered, to restore it you do this:
- Inverse the map (related to important above)
- Loop the map then insert each block at its position in the filtered text
If you think you can do that and it's easier go ahead otherwise it's just an idea
Notes
If you wanted to keep your current code, make sure to compile all regex patterns outside the methods and assign them to their own fields
There is ch.njol.skript.util.chat.ChatMessages#stripStyles(String) for removing the colour formats, it may also be better to put your utility methods inside ch.njol.skript.util.chat.ChatMessages
There is
ch.njol.skript.util.chat.ChatMessages#stripStyles(String)for removing the colour formats, it may also be better to put your utility methods insidech.njol.skript.util.chat.ChatMessages
The only problem with the strip styles is that it throws an index out of bounds exception. I will add it to ch.njol.skript.util.chat.ChatMessages though, thanks for the suggestion.
I'm closing this because more than six months have elapsed without the changes being addressed or any input from the creator.
Please let me know if you'd like me to re-open it in future!