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

Improve chat api toLegacy conversion #3625

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Janmm14
Copy link
Contributor

@Janmm14 Janmm14 commented Feb 27, 2024

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 PR

This 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.

@@ -665,7 +665,10 @@ void toLegacyText(StringBuilder builder)

void addFormat(StringBuilder builder)
{
builder.append( getColor() );
if ( style.hasColor() || parent != null )
Copy link
Member

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?

Copy link
Contributor Author

@Janmm14 Janmm14 Apr 14, 2024

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.

Copy link
Contributor Author

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

@Janmm14 Janmm14 force-pushed the keep-chatcolor-unset-in-legacy branch from b2fe975 to 0bbe3e6 Compare April 14, 2024 06:15
@Janmm14 Janmm14 changed the title Keep ChatColor unset in conversion to legacy Keep ChatColor unset in conversion to legacy, improve Component toString Apr 14, 2024
@Janmm14
Copy link
Contributor Author

Janmm14 commented Apr 18, 2024

Please do another review.

Janmm14 and others added 2 commits April 21, 2024 16:17
… 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 <bob7lbob7l@yahoo.com>
@Janmm14 Janmm14 force-pushed the keep-chatcolor-unset-in-legacy branch from dc7fecd to 5b1e75c Compare April 21, 2024 14:24
@Janmm14 Janmm14 changed the title Keep ChatColor unset in conversion to legacy, improve Component toString Keep ChatColor unset in conversion to legacy Apr 21, 2024
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.
@Janmm14 Janmm14 changed the title Keep ChatColor unset in conversion to legacy Improve chat api toLegacy conversion Apr 21, 2024
@Janmm14 Janmm14 force-pushed the keep-chatcolor-unset-in-legacy branch from 5b1e75c to 32dfedc Compare April 21, 2024 17:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants