-
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
Add TextComponent#fromLegacy() as compact alternative to #fromLegacyText() #3540
Conversation
We could leave it undeprecated until components are finalized in Spigot :) |
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). |
What do you mean its not clearly read? |
@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. |
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 |
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. |
@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). |
1049cd7
to
d195ea5
Compare
d195ea5
to
aaaae41
Compare
Thanks |
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. UnlikeComponentSerializer#parse()
however, the individual components parsed from#fromLegacyText()
are inserted as individual elements in the array and does not use theextra
field of aTextComponent
.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 asextra
values of an emptyTextComponent
. Unlike the previous PR whereComponentSerializer#parse()
was not deprecated (because it does have genuine uses), the#fromLegacyText()
methods have been deprecated to encourage use of single object alternatives.