#3844: Fix parsing nested array chat components

This commit is contained in:
Outfluencer 2025-06-05 21:03:24 +10:00 committed by md_5
parent b60c1bdb37
commit 5348aad094
No known key found for this signature in database
GPG Key ID: E8E901AC7C617C11
2 changed files with 19 additions and 0 deletions

View File

@ -261,6 +261,18 @@ public class VersionedComponentSerializer implements JsonDeserializer<BaseCompon
{
return new TextComponent( json.getAsString() );
}
if ( json.isJsonArray() )
{
JsonArray arr = json.getAsJsonArray();
BaseComponent[] components = new BaseComponent[arr.size()];
for ( int i = 0; i < arr.size(); i++ )
{
components[i] = deserialize( arr.get( i ), BaseComponent.class, context );
}
return TextComponent.fromArray( components );
}
JsonObject object = json.getAsJsonObject();
if ( object.has( "translate" ) )
{

View File

@ -877,4 +877,11 @@ public class ComponentsTest
{
return BaseComponent.toLegacyText( TextComponent.fromLegacyText( legacyText ) );
}
@Test
public void testArrayParsing()
{
assertEquals( "Outfluencer is very cool bdfg28dhzcathisisacoolcomponent",
ComponentSerializer.deserialize( "[Outfluencer,[\" \",is,[\" very\",\" cool \",[b,dfg28dhz,[c,[a,thisisacoolcomponent]]]]]]" ).toPlainText() );
}
}