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

Add TextComponent#fromLegacy() as compact alternative to #fromLegacyText() #3540

Closed

Conversation

2008Choco
Copy link
Contributor

Following cfe00fa47c (ComponentBuilder#build() et. al.), this PR adds some API that was missed to further encourage consolidating components into single objects as opposed to arrays, TextComponent#fromLegacyText(). While use of this method is discouraged, it is still used occasionally in Spigot to convert legacy text arguments into components. Unlike ComponentSerializer#parse() however, the individual components parsed from #fromLegacyText() are inserted as individual elements in the array and does not use the extra field of a TextComponent.

This PR adds TextComponent#fromLegacy() to resolve this. It does not change the behaviour of #fromLegacyText() and in fact invokes this method and just assigns the resulting array as extra values of an empty TextComponent. Unlike the previous PR where ComponentSerializer#parse() was not deprecated (because it does have genuine uses), the #fromLegacyText() methods have been deprecated to encourage use of single object alternatives.

@2008Choco
Copy link
Contributor Author

2008Choco commented Sep 28, 2023

I can confirm that this does in fact work as well
image
(the text at the end of this message being represented as a BaseComponent after having been passed through the new TextComponent#fromLegacy())

@md-5
Copy link
Member

md-5 commented Oct 6, 2023

lgtm, although I wonder if deprecation at least immediately is a bit aggressive given how much this method is used in practice and in documentation

cc @Janmm14 @ItsLaivy

@2008Choco
Copy link
Contributor Author

We could leave it undeprecated until components are finalized in Spigot :)

@ItsLaivy
Copy link

ItsLaivy commented Oct 6, 2023

I don't support the idea of a single object with extras for BaseComponents because the "extra" field of BaseComponents is not clearly read by ComponentSerializer#parse itself. In fact, I've already created a commit to remove it from #serialize (#3463).

@md-5
Copy link
Member

md-5 commented Oct 7, 2023

What do you mean its not clearly read?

@Janmm14
Copy link
Contributor

Janmm14 commented Oct 13, 2023

@ItsLaivy Please provide details and an example of the alleged problem ("not clearly read"?).

All I see in your PR is a "beauty" improvement of the resulting json.

@md-5
Copy link
Member

md-5 commented Oct 14, 2023

We need a way to parse an array into a single component like mojang.

Context, 1.20.3 serializes components and NBT I am aligning Bungee with Vanilla in using a single component across the protocol. I think @ItsLaivy your preference unfortunately loses since it would then be wrapped

@ItsLaivy
Copy link

ItsLaivy commented Oct 14, 2023

@ItsLaivy Please provide details and an example of the alleged problem ("not clearly read"?).

All I see in your PR is a "beauty" improvement of the resulting json.

My pull request mainly removes the extra dependency from the parser and serializer, multiples components are serialized as a json array, not a json object, and fixed an issue on blank base components serialization

@Janmm14
Copy link
Contributor

Janmm14 commented Oct 14, 2023

@ItsLaivy Please provide details and an example of the alleged problem ("not clearly read"?).
All I see in your PR is a "beauty" improvement of the resulting json.

My pull request mainly removes the extra dependency from the parser and serializer, multiples components are serialized as a json array, not a json object, and fixed an issue on blank base components serialization

Your PR introduces arrays as root for chat content, while md_5 wants to achieve the opposite.

@md-5
Copy link
Member

md-5 commented Oct 21, 2023

@2008Choco perhaps you'd like to look at #3553 and integrate into that branch? That branch tries to switch everything to single components, but right now for legacy text it converts to array and then wraps that in a single component with componentbuilder.

Ultimately it should be safe to merge this change/conversion to single components in now, because there is no guarantee or canonical form for a BaseComponent (which is part of what makes them so annoying to deal with for plugins compared to strings).

@2008Choco 2008Choco changed the base branch from master to version/1.20.3 October 26, 2023 00:15
md-5 pushed a commit that referenced this pull request Oct 28, 2023
@md-5
Copy link
Member

md-5 commented Oct 28, 2023

Thanks

@md-5 md-5 closed this Oct 28, 2023
@2008Choco 2008Choco deleted the compact-fromlegacy branch October 28, 2023 02:30
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.

4 participants