Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Component#replaceText() does not match across component boundaries #1133

Open
kangarko opened this issue Nov 24, 2024 · 1 comment
Open

Component#replaceText() does not match across component boundaries #1133

kangarko opened this issue Nov 24, 2024 · 1 comment

Comments

@kangarko
Copy link

Code:

// MiniMessage NOT required to reproduce but used for readability
final Component component = MiniMessage.miniMessage().deserialize("<gradient:red:blue>This is a test, {player}").replaceText(b -> b.matchLiteral("{player}").replacement("Demo"));

System.out.println("Demo: " + PlainTextComponentSerializer.plainText().serialize(component));

The way this is implemented (by the way, MiniMessage is NOT required to reproduce, simply chain letters with different colors to do so) the Component turns into {"extra":[{"color":"red","text":"T"},{"color":"#F8555C","text":"h"},{"color":"#F05564","text":"i"},{"color":"#E9556B","text":"s"},{"color":"#E15573","text":" "},{"color":"#DA557A","text":"i"},{"color":"#D35581","text":"s"},{"color":"#CB5589","text":" "},{"color":"#C45590","text":"a"},{"color":"#BC5598","text":" "},{"color":"#B5559F","text":"t"},{"color":"#AE55A6","text":"e"},{"color":"#A655AE","text":"s"},{"color":"#9F55B5","text":"t"},{"color":"#9855BC","text":","},{"color":"#9055C4","text":" "},{"color":"#8955CB","text":"{"},{"color":"#8155D3","text":"p"},{"color":"#7A55DA","text":"l"},{"color":"#7355E1","text":"a"},{"color":"#6B55E9","text":"y"},{"color":"#6455F0","text":"e"},{"color":"#5C55F8","text":"r"},{"color":"blue","text":"}"}],"text":""} and the replaceText() method is unable to find the letters.

The only way we "fixed" it so far is to replace variables on the raw message before parsing it.

Thanks
Matej

@zml2008
Copy link
Member

zml2008 commented Dec 1, 2024

Unfortunately this is a limitation of replaceText, it doesn't look for matches across component boundaries. It's possible to redesign the replacement logic to not have this limitation, but we haven't figured out a way to do it without significantly increasing the complexity of the API.

@zml2008 zml2008 changed the title Gradients break Component#replaceText() Component#replaceText() does not match across component boundaries Dec 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants