KyoriPowered / adventure

A user-interface library, formerly known as text, for Minecraft: Java Edition
https://docs.advntr.dev/
MIT License
679 stars 104 forks source link

Component compacting does not fully compact #1018

Open diogotcorreia opened 6 months ago

diogotcorreia commented 6 months ago

Given the following component, I have to compact it twice to get a fully compacted component.

Component.text()
    .content("")
    .color(NamedTextColor.GREEN)
    .append(
        Component.text()
            .decorate(TextDecoration.ITALIC),
        Component.text("consectetur adipiscing elit")
            .color(TextColor.color(0x123456))
    )
    .asComponent()

Without compacting:

{"color":"green","extra":[{"italic":true,"text":""},{"color":"#123456","text":"consectetur adipiscing elit"}],"text":""}

After compacting once:

{"color":"green","extra":[{"color":"#123456","text":"consectetur adipiscing elit"}],"text":""}

After compacting twice:

{"color":"#123456","text":"consectetur adipiscing elit"}

After compacting three times (does not change):

{"color":"#123456","text":"consectetur adipiscing elit"}

As you can see, the first time I compact the component, it does not fully compact. I'm not sure if this is intended or not. I'm also unsure if this is related to #483.

As per my use-case, I'm using this in unit tests where I just care if the components are equivalent, so I just compact both the result and the expected component and see if they match - however, compacting once isn't working, I have to compact twice.

Note: In the examples above, the components were serialized to JSON with GsonComponentSerializer.gson().serialize(component).

I'm using Adventure 4.15.0.