From 22d2cd33883c5969b3b6c49c1fb77258fefc6041 Mon Sep 17 00:00:00 2001 From: BlackHole Date: Sun, 12 Jan 2020 22:23:11 +0100 Subject: [PATCH] #2747: Fix TranslatableComponent.deserialize() --- .../bungee/chat/TranslatableComponentSerializer.java | 2 +- .../bungee/api/chat/TranslatableComponentTest.java | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/chat/src/main/java/net/md_5/bungee/chat/TranslatableComponentSerializer.java b/chat/src/main/java/net/md_5/bungee/chat/TranslatableComponentSerializer.java index b2e88ffb..c6057e3a 100644 --- a/chat/src/main/java/net/md_5/bungee/chat/TranslatableComponentSerializer.java +++ b/chat/src/main/java/net/md_5/bungee/chat/TranslatableComponentSerializer.java @@ -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.deserialize( object.get( "with" ), BaseComponent[].class ) ) ); + component.setWith( Arrays.asList( context.deserialize( object.get( "with" ), BaseComponent[].class ) ) ); } return component; } diff --git a/chat/src/test/java/net/md_5/bungee/api/chat/TranslatableComponentTest.java b/chat/src/test/java/net/md_5/bungee/api/chat/TranslatableComponentTest.java index 7e63488c..9e37eed0 100644 --- a/chat/src/test/java/net/md_5/bungee/api/chat/TranslatableComponentTest.java +++ b/chat/src/test/java/net/md_5/bungee/api/chat/TranslatableComponentTest.java @@ -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 ) ); + } }