Skript icon indicating copy to clipboard operation
Skript copied to clipboard

Fix for Colored String Case

Open hotpocket184 opened this issue 3 years ago • 2 comments

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

hotpocket184 avatar Jul 10 '22 17:07 hotpocket184

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

AyhamAl-Ali avatar Jul 15 '22 17:07 AyhamAl-Ali

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

TheLimeGlass avatar Jul 29 '22 23:07 TheLimeGlass

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

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.

hotpocket184 avatar Sep 30 '22 01:09 hotpocket184

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!

Moderocky avatar Sep 18 '23 09:09 Moderocky