#2747: Fix TranslatableComponent.deserialize()

This commit is contained in:
BlackHole 2020-01-12 22:23:11 +01:00 committed by md_5
parent d8c222ae79
commit 22d2cd3388
2 changed files with 13 additions and 1 deletions

View File

@ -24,7 +24,7 @@ public class TranslatableComponentSerializer extends BaseComponentSerializer imp
component.setTranslate( object.get( "translate" ).getAsString() );
if ( object.has( "with" ) )
{
component.setWith( Arrays.asList( context.<BaseComponent>deserialize( object.get( "with" ), BaseComponent[].class ) ) );
component.setWith( Arrays.asList( context.<BaseComponent[]>deserialize( object.get( "with" ), BaseComponent[].class ) ) );
}
return component;
}

View File

@ -1,5 +1,6 @@
package net.md_5.bungee.api.chat;
import net.md_5.bungee.chat.ComponentSerializer;
import org.junit.Assert;
import org.junit.Test;
@ -13,4 +14,15 @@ public class TranslatableComponentTest
Assert.assertEquals( "Test string with 2 placeholders: aoeu", testComponent.toPlainText() );
Assert.assertEquals( "§fTest string with §f2§f placeholders: §faoeu", testComponent.toLegacyText() );
}
@Test
public void testJsonSerialisation()
{
TranslatableComponent testComponent = new TranslatableComponent( "Test string with %s placeholder", "a" );
String jsonString = ComponentSerializer.toString( testComponent );
BaseComponent[] baseComponents = ComponentSerializer.parse( jsonString );
Assert.assertEquals( "Test string with a placeholder", TextComponent.toPlainText( baseComponents ) );
Assert.assertEquals( "§fTest string with §fa§f placeholder", TextComponent.toLegacyText( baseComponents ) );
}
}