-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Improve chat api toLegacy conversion #3625
base: master
Are you sure you want to change the base?
Conversation
@@ -665,7 +665,10 @@ void toLegacyText(StringBuilder builder) | |||
|
|||
void addFormat(StringBuilder builder) | |||
{ | |||
builder.append( getColor() ); | |||
if ( style.hasColor() || parent != null ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is the parent check required?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Otherwise a constellation like {"extra":[{"text":"b","color":"red"},{"text":"c"}], "text":"a", "color":"blue"}
would show the c
in red instead of blue. Similar with arguments of translatables.
Unfortunaly this introduces another bug in conversion of BaseComponent array.
In new commit I added overhaul of toLegacy conversion, making it context-aware.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another test added for this in dc7fecd
b2fe975
to
0bbe3e6
Compare
Please do another review. |
… converting to legacy. In Tests: - add bunch of tests including a failing test - change expected results as unneccessary white color codes got less Co-authored-by: bob7l <[email protected]>
dc7fecd
to
5b1e75c
Compare
The target is to output less redundant legacy codes, this has been achieved by using context-aware toLegacy conversion which keeps track of the current end-of-string style. Fixes behaviour change introduced in f4144eb8c2e83f43f41b24b4ea8b03b0f4c9c44e of array toLegacy conversion where the next array element would no longer reset to white color.
5b1e75c
to
32dfedc
Compare
This PR introduces the suggested change in #3623 and improves test case code and changes the test cases affected by this change of removing unneccessary color codes in legacy output.
Additionally it improves all the componenets toString methods by not showing null methods, integrating style toString and using shorter names.moved to separate PRThis PR has a slight unwanted side effect when converting uncolored translatable components with styled parameters to legacy - in these cases the style of the parameter will stay after the styled parameter ends.Should we fix that with special casing in transable component somehow and what would be the best way of doing so?This PR overhauls toLegacy conversion with context-aware algorithm which only adds formatting codes if needed in most cases.