From 765858f17c0554a9e2e2d64479d6125b7b1c0362 Mon Sep 17 00:00:00 2001 From: Janmm14 Date: Sun, 14 Apr 2024 02:53:32 +0200 Subject: [PATCH] Fix #3623: Do not add white (default) color if its unset when converting to legacy. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In Tests: Add static ChatColor import, replace all usages of '§' with ChatColor. Co-authored-by: bob7l # Conflicts: # chat/src/test/java/net/md_5/bungee/api/chat/ComponentsTest.java # chat/src/test/java/net/md_5/bungee/api/chat/TranslatableComponentTest.java --- .../md_5/bungee/api/chat/BaseComponent.java | 5 +- .../md_5/bungee/api/chat/ComponentsTest.java | 140 +++++++++--------- .../api/chat/TranslatableComponentTest.java | 13 +- 3 files changed, 83 insertions(+), 75 deletions(-) diff --git a/chat/src/main/java/net/md_5/bungee/api/chat/BaseComponent.java b/chat/src/main/java/net/md_5/bungee/api/chat/BaseComponent.java index 558343c3380..17af2508ac5 100644 --- a/chat/src/main/java/net/md_5/bungee/api/chat/BaseComponent.java +++ b/chat/src/main/java/net/md_5/bungee/api/chat/BaseComponent.java @@ -668,7 +668,10 @@ void toLegacyText(StringBuilder builder) void addFormat(StringBuilder builder) { - builder.append( getColor() ); + if ( style.hasColor() || parent != null ) + { + builder.append( getColor() ); + } if ( isBold() ) { builder.append( ChatColor.BOLD ); diff --git a/chat/src/test/java/net/md_5/bungee/api/chat/ComponentsTest.java b/chat/src/test/java/net/md_5/bungee/api/chat/ComponentsTest.java index 7e14484b62a..595e4ae231a 100644 --- a/chat/src/test/java/net/md_5/bungee/api/chat/ComponentsTest.java +++ b/chat/src/test/java/net/md_5/bungee/api/chat/ComponentsTest.java @@ -1,5 +1,6 @@ package net.md_5.bungee.api.chat; +import static net.md_5.bungee.api.ChatColor.*; import static org.junit.jupiter.api.Assertions.*; import java.awt.Color; import java.util.function.BiFunction; @@ -7,7 +8,6 @@ import java.util.function.Function; import java.util.function.ObjIntConsumer; import java.util.function.Supplier; -import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.chat.hover.content.Entity; import net.md_5.bungee.api.chat.hover.content.Text; import net.md_5.bungee.chat.ComponentSerializer; @@ -137,9 +137,9 @@ public void testDummyRetaining() { ComponentBuilder builder = new ComponentBuilder(); assertNotNull( builder.getCurrentComponent() ); - builder.color( ChatColor.GREEN ); + builder.color( GREEN ); builder.append( "test ", ComponentBuilder.FormatRetention.ALL ); - assertEquals( builder.getCurrentComponent().getColor(), ChatColor.GREEN ); + assertEquals( builder.getCurrentComponent().getColor(), GREEN ); } @Test @@ -158,7 +158,7 @@ public void testComponentGettingExceptions() @Test public void testFormatNotColor() { - BaseComponent[] component = new ComponentBuilder().color( ChatColor.BOLD ).append( "Test" ).create(); + BaseComponent[] component = new ComponentBuilder().color( BOLD ).append( "Test" ).create(); String json = ComponentSerializer.toString( component ); BaseComponent[] parsed = ComponentSerializer.parse( json ); @@ -187,10 +187,18 @@ public void testComponentParting() @Test public void testToLegacyFromLegacy() { - String text = "§a§lHello §f§kworld§7!"; + String text = "" + GREEN + BOLD + "Hello " + WHITE + MAGIC + "world" + GRAY + "!"; assertEquals( text, BaseComponent.toLegacyText( TextComponent.fromLegacyText( text ) ) ); } + @Test + public void testNoColorComponent() + { + String json = "{\"text\":\"Hello World\"}"; + BaseComponent[] components = ComponentSerializer.parse( json ); + assertEquals( "Hello World", BaseComponent.toLegacyText( components ) ); + } + @Test public void testComponentBuilderCursorInvalidPos() { @@ -229,7 +237,7 @@ public void testComponentBuilderCursor() @Test public void testLegacyComponentBuilderAppend() { - String text = "§a§lHello §r§kworld§7!"; + String text = "" + GREEN + BOLD + "Hello " + RESET + MAGIC + "world" + GRAY + "!"; BaseComponent[] components = TextComponent.fromLegacyText( text ); BaseComponent[] builderComponents = new ComponentBuilder().append( components ).create(); assertArrayEquals( components, builderComponents ); @@ -348,7 +356,7 @@ private void testHoverEventContents(HoverEvent hoverEvent, Function new HoverEvent( HoverEvent.Action.SHOW_TEXT, new ComponentBuilder( "Test" ).create() ) ); + testFormatRetentionCopyFormatting( () -> new HoverEvent( HoverEvent.Action.SHOW_TEXT, new ComponentBuilder( "Test" ).create() ) ); } @Test @@ -361,7 +369,7 @@ private static void testFormatRetentionCopyFormatting(Supplier hover { TextComponent first = new TextComponent( "Hello" ); first.setBold( true ); - first.setColor( ChatColor.RED ); + first.setColor( RED ); first.setClickEvent( new ClickEvent( ClickEvent.Action.RUN_COMMAND, "test" ) ); first.setHoverEvent( hoverEventSupplier.get() ); @@ -387,7 +395,7 @@ public void testBuilderCloneBuild() private static void testBuilderClone(Function legacyTextFunction) { - ComponentBuilder builder = new ComponentBuilder( "Hello " ).color( ChatColor.RED ).append( "world" ).color( ChatColor.DARK_RED ); + ComponentBuilder builder = new ComponentBuilder( "Hello " ).color( RED ).append( "world" ).color( DARK_RED ); ComponentBuilder cloned = new ComponentBuilder( builder ); assertEquals( legacyTextFunction.apply( builder ), legacyTextFunction.apply( cloned ) ); @@ -459,7 +467,7 @@ public void testBuilderAppendCreate() ComponentBuilder::create, (components, index) -> components[index], BaseComponent::toPlainText, - ChatColor.YELLOW + "Hello " + ChatColor.GREEN + "world!", + YELLOW + "Hello " + GREEN + "world!", BaseComponent::toLegacyText ); } @@ -472,8 +480,7 @@ public void testBuilderAppendBuild() ComponentBuilder::build, (component, index) -> component.getExtra().get( index ), (component) -> BaseComponent.toPlainText( component ), - // An extra format code is appended to the beginning because there is an empty TextComponent at the start of every component - ChatColor.WHITE.toString() + ChatColor.YELLOW + "Hello " + ChatColor.GREEN + "world!", + YELLOW + "Hello " + GREEN + "world!", (component) -> BaseComponent.toLegacyText( component ) ); } @@ -483,8 +490,9 @@ private static void testBuilderAppend(Supplier hoverEventSupplie ClickEvent clickEvent = new ClickEvent( ClickEvent.Action.RUN_COMMAND, "/help " ); HoverEvent hoverEvent = hoverEventSupplier.get(); - ComponentBuilder builder = new ComponentBuilder( "Hello " ).color( ChatColor.YELLOW ); - builder.append( new ComponentBuilder( "world!" ).color( ChatColor.GREEN ).event( hoverEvent ).event( clickEvent ).create() ); // Intentionally using create() to append multiple individual components + ComponentBuilder builder = new ComponentBuilder( "Hello " ).color( YELLOW ); + // Intentionally using create() to append multiple individual components + builder.append( new ComponentBuilder( "world!" ).color( GREEN ).event( hoverEvent ).event( clickEvent ).create() ); T component = componentBuilder.apply( builder ); @@ -500,7 +508,7 @@ public void testBuilderAppendLegacyCreate() testBuilderAppendLegacy( ComponentBuilder::create, BaseComponent::toPlainText, - ChatColor.YELLOW + "Hello " + ChatColor.GREEN + "world!", + YELLOW + "Hello " + GREEN + "world!", BaseComponent::toLegacyText ); } @@ -511,16 +519,15 @@ public void testBuilderAppendLegacyBuild() testBuilderAppendLegacy( ComponentBuilder::build, (component) -> BaseComponent.toPlainText( component ), - // An extra format code is appended to the beginning because there is an empty TextComponent at the start of every component - ChatColor.WHITE.toString() + ChatColor.YELLOW + "Hello " + ChatColor.GREEN + "world!", + YELLOW + "Hello " + GREEN + "world!", (component) -> BaseComponent.toLegacyText( component ) ); } private static void testBuilderAppendLegacy(Function componentBuilder, Function toPlainTextFunction, String expectedLegacyString, Function toLegacyTextFunction) { - ComponentBuilder builder = new ComponentBuilder( "Hello " ).color( ChatColor.YELLOW ); - builder.appendLegacy( "§aworld!" ); + ComponentBuilder builder = new ComponentBuilder( "Hello " ).color( YELLOW ); + builder.appendLegacy( GREEN + "world!" ); T component = componentBuilder.apply( builder ); @@ -532,26 +539,25 @@ private static void testBuilderAppendLegacy(Function co public void testBasicComponent() { TextComponent textComponent = new TextComponent( "Hello world" ); - textComponent.setColor( ChatColor.RED ); + textComponent.setColor( RED ); assertEquals( "Hello world", textComponent.toPlainText() ); - assertEquals( ChatColor.RED + "Hello world", textComponent.toLegacyText() ); + assertEquals( RED + "Hello world", textComponent.toLegacyText() ); } @Test public void testLegacyConverter() { - BaseComponent[] test1 = TextComponent.fromLegacyText( ChatColor.AQUA + "Aqua " + ChatColor.RED + ChatColor.BOLD + "RedBold" ); + BaseComponent[] test1 = TextComponent.fromLegacyText( AQUA + "Aqua " + RED + BOLD + "RedBold" ); assertEquals( "Aqua RedBold", BaseComponent.toPlainText( test1 ) ); - assertEquals( ChatColor.AQUA + "Aqua " + ChatColor.RED + ChatColor.BOLD + "RedBold", BaseComponent.toLegacyText( test1 ) ); + assertEquals( AQUA + "Aqua " + RED + BOLD + "RedBold", BaseComponent.toLegacyText( test1 ) ); - BaseComponent[] test2 = TextComponent.fromLegacyText( "Text http://spigotmc.org " + ChatColor.GREEN + "google.com/test" ); + BaseComponent[] test2 = TextComponent.fromLegacyText( "Text http://spigotmc.org " + GREEN + "google.com/test" ); assertEquals( "Text http://spigotmc.org google.com/test", BaseComponent.toPlainText( test2 ) ); //The extra ChatColor instances are sometimes inserted when not needed but it doesn't change the result - assertEquals( ChatColor.WHITE + "Text " + ChatColor.WHITE + "http://spigotmc.org" + ChatColor.WHITE - + " " + ChatColor.GREEN + "google.com/test" + ChatColor.GREEN, BaseComponent.toLegacyText( test2 ) ); + assertEquals( "Text http://spigotmc.org " + GREEN + "google.com/test" + GREEN, BaseComponent.toLegacyText( test2 ) ); ClickEvent url1 = test2[1].getClickEvent(); assertNotNull( url1 ); @@ -568,20 +574,21 @@ public void testLegacyConverter() public void testTranslateComponent() { TranslatableComponent item = new TranslatableComponent( "item.swordGold.name" ); - item.setColor( ChatColor.AQUA ); - TranslatableComponent translatableComponent = new TranslatableComponent( "commands.give.success", - item, "5", + item.setColor( AQUA ); + TranslatableComponent component = new TranslatableComponent( "commands.give.success", item, "5", "thinkofdeath" ); - assertEquals( "Given Golden Sword * 5 to thinkofdeath", translatableComponent.toPlainText() ); - assertEquals( ChatColor.WHITE + "Given " + ChatColor.AQUA + "Golden Sword" + ChatColor.WHITE - + " * " + ChatColor.WHITE + "5" + ChatColor.WHITE + " to " + ChatColor.WHITE + "thinkofdeath", - translatableComponent.toLegacyText() ); + assertEquals( "Given Golden Sword * 5 to thinkofdeath", component.toPlainText() ); + assertEquals( "Given " + AQUA + "Golden Sword * " + WHITE + "5 to " + WHITE + "thinkofdeath", component.toLegacyText() ); + + BaseComponent legacyColorTest = new ComponentBuilder( "Test " ).color( RED ).append( component ).build(); + assertEquals( RED + "Test " + RED + "Given " + AQUA + "Golden Sword" + RED + " * " + RED + "5" + RED + " to " + + RED + "thinkofdeath", legacyColorTest.toLegacyText() ); TranslatableComponent positional = new TranslatableComponent( "book.pageIndicator", "5", "50" ); assertEquals( "Page 5 of 50", positional.toPlainText() ); - assertEquals( ChatColor.WHITE + "Page " + ChatColor.WHITE + "5" + ChatColor.WHITE + " of " + ChatColor.WHITE + "50", positional.toLegacyText() ); + assertEquals( "Page " + WHITE + "5 of " + WHITE + "50", positional.toLegacyText() ); TranslatableComponent one_four_two = new TranslatableComponent( "filled_map.buried_treasure" ); assertEquals( "Buried Treasure Map", one_four_two.toPlainText() ); @@ -593,7 +600,7 @@ public void testBuilderCreate() testBuilder( ComponentBuilder::create, BaseComponent::toPlainText, - ChatColor.RED + "Hello " + ChatColor.BLUE + ChatColor.BOLD + "World" + ChatColor.YELLOW + ChatColor.BOLD + "!", + RED + "Hello " + BLUE + BOLD + "World" + YELLOW + BOLD + "!", BaseComponent::toLegacyText ); } @@ -604,17 +611,15 @@ public void testBuilderBuild() testBuilder( ComponentBuilder::build, (component) -> BaseComponent.toPlainText( component ), - // An extra format code is appended to the beginning because there is an empty TextComponent at the start of every component - ChatColor.WHITE.toString() + ChatColor.RED + "Hello " + ChatColor.BLUE + ChatColor.BOLD + "World" + ChatColor.YELLOW + ChatColor.BOLD + "!", + RED + "Hello " + BLUE + BOLD + "World" + YELLOW + BOLD + "!", (component) -> BaseComponent.toLegacyText( component ) ); } private static void testBuilder(Function componentBuilder, Function toPlainTextFunction, String expectedLegacyString, Function toLegacyTextFunction) { - T component = componentBuilder.apply( new ComponentBuilder( "Hello " ).color( ChatColor.RED ). - append( "World" ).bold( true ).color( ChatColor.BLUE ). - append( "!" ).color( ChatColor.YELLOW ) ); + T component = componentBuilder.apply( new ComponentBuilder( "Hello " ).color( RED ).append( "World" ) + .bold( true ).color( BLUE ).append( "!" ).color( YELLOW ) ); assertEquals( "Hello World!", toPlainTextFunction.apply( component ) ); assertEquals( expectedLegacyString, toLegacyTextFunction.apply( component ) ); @@ -640,11 +645,10 @@ public void testBuilderBuildReset() private static void testBuilderReset(Function componentBuilder, BiFunction extraGetter) { - T component = componentBuilder.apply( new ComponentBuilder( "Hello " ).color( ChatColor.RED ) - .append( "World" ).reset() ); + T component = componentBuilder.apply( new ComponentBuilder( "Hello " ).color( RED ).append( "World" ).reset() ); - assertEquals( ChatColor.RED, extraGetter.apply( component, 0 ).getColor() ); - assertEquals( ChatColor.WHITE, extraGetter.apply( component, 1 ).getColor() ); + assertEquals( RED, extraGetter.apply( component, 0 ).getColor() ); + assertEquals( WHITE, extraGetter.apply( component, 1 ).getColor() ); } @Test @@ -667,31 +671,31 @@ public void testBuilderBuildFormatRetention() private static void testBuilderFormatRetention(Function componentBuilder, BiFunction extraGetter) { - T noneRetention = componentBuilder.apply( new ComponentBuilder( "Hello " ).color( ChatColor.RED ) + T noneRetention = componentBuilder.apply( new ComponentBuilder( "Hello " ).color( RED ) .append( "World", ComponentBuilder.FormatRetention.NONE ) ); - assertEquals( ChatColor.RED, extraGetter.apply( noneRetention, 0 ).getColor() ); - assertEquals( ChatColor.WHITE, extraGetter.apply( noneRetention, 1 ).getColor() ); + assertEquals( RED, extraGetter.apply( noneRetention, 0 ).getColor() ); + assertEquals( WHITE, extraGetter.apply( noneRetention, 1 ).getColor() ); HoverEvent testEvent = new HoverEvent( HoverEvent.Action.SHOW_TEXT, new Text( new ComponentBuilder( "test" ).build() ) ); - T formattingRetention = componentBuilder.apply( new ComponentBuilder( "Hello " ).color( ChatColor.RED ) - .event( testEvent ).append( "World", ComponentBuilder.FormatRetention.FORMATTING ) ); + T formattingRetention = componentBuilder.apply( new ComponentBuilder( "Hello " ).color( RED ).event( testEvent ) + .append( "World", ComponentBuilder.FormatRetention.FORMATTING ) ); - assertEquals( ChatColor.RED, extraGetter.apply( formattingRetention, 0 ).getColor() ); + assertEquals( RED, extraGetter.apply( formattingRetention, 0 ).getColor() ); assertEquals( testEvent, extraGetter.apply( formattingRetention, 0 ).getHoverEvent() ); - assertEquals( ChatColor.RED, extraGetter.apply( formattingRetention, 1 ).getColor() ); + assertEquals( RED, extraGetter.apply( formattingRetention, 1 ).getColor() ); assertNull( extraGetter.apply( formattingRetention, 1 ).getHoverEvent() ); ClickEvent testClickEvent = new ClickEvent( ClickEvent.Action.OPEN_URL, "http://www.example.com" ); - T eventRetention = componentBuilder.apply( new ComponentBuilder( "Hello " ).color( ChatColor.RED ) - .event( testEvent ).event( testClickEvent ).append( "World", ComponentBuilder.FormatRetention.EVENTS ) ); + T eventRetention = componentBuilder.apply( new ComponentBuilder( "Hello " ).color( RED ).event( testEvent ) + .event( testClickEvent ).append( "World", ComponentBuilder.FormatRetention.EVENTS ) ); - assertEquals( ChatColor.RED, extraGetter.apply( eventRetention, 0 ).getColor() ); + assertEquals( RED, extraGetter.apply( eventRetention, 0 ).getColor() ); assertEquals( testEvent, extraGetter.apply( eventRetention, 0 ).getHoverEvent() ); assertEquals( testClickEvent, extraGetter.apply( eventRetention, 0 ).getClickEvent() ); - assertEquals( ChatColor.WHITE, extraGetter.apply( eventRetention, 1 ).getColor() ); + assertEquals( WHITE, extraGetter.apply( eventRetention, 1 ).getColor() ); assertEquals( testEvent, extraGetter.apply( eventRetention, 1 ).getHoverEvent() ); assertEquals( testClickEvent, extraGetter.apply( eventRetention, 1 ).getClickEvent() ); } @@ -709,9 +713,9 @@ public void testLoopComplex() { TextComponent a = new TextComponent( "A" ); TextComponent b = new TextComponent( "B" ); - b.setColor( ChatColor.AQUA ); + b.setColor( AQUA ); TextComponent c = new TextComponent( "C" ); - c.setColor( ChatColor.RED ); + c.setColor( RED ); a.addExtra( b ); b.addExtra( c ); c.addExtra( a ); @@ -723,7 +727,7 @@ public void testRepeated() { TextComponent a = new TextComponent( "A" ); TextComponent b = new TextComponent( "B" ); - b.setColor( ChatColor.AQUA ); + b.setColor( AQUA ); a.addExtra( b ); a.addExtra( b ); ComponentSerializer.toString( a ); @@ -734,9 +738,9 @@ public void testRepeatedError() { TextComponent a = new TextComponent( "A" ); TextComponent b = new TextComponent( "B" ); - b.setColor( ChatColor.AQUA ); + b.setColor( AQUA ); TextComponent c = new TextComponent( "C" ); - c.setColor( ChatColor.RED ); + c.setColor( RED ); a.addExtra( b ); a.addExtra( c ); c.addExtra( a ); @@ -752,15 +756,15 @@ public void testInvalidColorCodes() // collect all invalid color codes (e.g. §z, §g, ...) for ( char alphChar : "0123456789abcdefghijklmnopqrstuvwxyz".toCharArray() ) { - if ( ChatColor.ALL_CODES.indexOf( alphChar ) == -1 ) + if ( ALL_CODES.indexOf( alphChar ) == -1 ) { - allInvalidColorCodes.append( ChatColor.COLOR_CHAR ); + allInvalidColorCodes.append( COLOR_CHAR ); allInvalidColorCodes.append( alphChar ); } } // last char is a single '§' - allInvalidColorCodes.append( ChatColor.COLOR_CHAR ); + allInvalidColorCodes.append( COLOR_CHAR ); String invalidColorCodesLegacyText = fromAndToLegacyText( allInvalidColorCodes.toString() ); String emptyLegacyText = fromAndToLegacyText( "" ); @@ -772,10 +776,10 @@ public void testInvalidColorCodes() @Test public void testFormattingOnlyTextConversion() { - String text = "§a"; + String text = GREEN.toString(); BaseComponent[] converted = TextComponent.fromLegacyText( text ); - assertEquals( ChatColor.GREEN, converted[0].getColor() ); + assertEquals( GREEN, converted[0].getColor() ); String roundtripLegacyText = BaseComponent.toLegacyText( converted ); @@ -810,7 +814,7 @@ public void testNotEquals() @Test public void testLegacyHack() { - BaseComponent[] hexColored = new ComponentBuilder().color( ChatColor.of( Color.GRAY ) ).append( "Test" ).create(); + BaseComponent[] hexColored = new ComponentBuilder().color( of( Color.GRAY ) ).append( "Test" ).create(); String legacy = BaseComponent.toLegacyText( hexColored ); BaseComponent[] reColored = TextComponent.fromLegacyText( legacy ); @@ -865,7 +869,7 @@ public void testStyleIsEmpty() private static void testLegacyResetInBuilder(Function componentBuilder, Function componentSerializer) { ComponentBuilder builder = new ComponentBuilder(); - BaseComponent[] a = TextComponent.fromLegacyText( "§4§n44444§rdd§6§l6666" ); + BaseComponent[] a = TextComponent.fromLegacyText( "" + DARK_RED + UNDERLINE + "44444" + RESET + "dd" + GOLD + BOLD + "6666" ); String expected = "{\"extra\":[{\"underlined\":true,\"color\":\"dark_red\",\"text\":\"44444\"},{\"color\":" + "\"white\",\"text\":\"dd\"},{\"bold\":true,\"color\":\"gold\",\"text\":\"6666\"}],\"text\":\"\"}"; @@ -876,7 +880,7 @@ private static void testLegacyResetInBuilder(Function c String test1 = componentSerializer.apply( componentBuilder.apply( builder ) ); assertEquals( expected, test1 ); - BaseComponent[] b = TextComponent.fromLegacyText( "§rrrrr" ); + BaseComponent[] b = TextComponent.fromLegacyText( RESET + "rrrr" ); builder.append( b ); String test2 = componentSerializer.apply( componentBuilder.apply( builder ) ); 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 47c06baafcf..83db3a7d878 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 static net.md_5.bungee.api.ChatColor.*; import static org.junit.jupiter.api.Assertions.*; import net.md_5.bungee.chat.ComponentSerializer; import org.junit.jupiter.api.Test; @@ -12,17 +13,17 @@ public void testMissingPlaceholdersAdded() { TranslatableComponent testComponent = new TranslatableComponent( "Test string with %s placeholders: %s", 2, "aoeu" ); assertEquals( "Test string with 2 placeholders: aoeu", testComponent.toPlainText() ); - assertEquals( "§fTest string with §f2§f placeholders: §faoeu", testComponent.toLegacyText() ); + assertEquals( "Test string with " + WHITE + "2 placeholders: " + WHITE + "aoeu", 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 ); + TranslatableComponent translatable = new TranslatableComponent( "Test string with %s placeholder", "a" ); + String jsonString = ComponentSerializer.toString( translatable ); + BaseComponent[] parsed = ComponentSerializer.parse( jsonString ); - assertEquals( "Test string with a placeholder", BaseComponent.toPlainText( baseComponents ) ); - assertEquals( "§fTest string with §fa§f placeholder", BaseComponent.toLegacyText( baseComponents ) ); + assertEquals( "Test string with a placeholder", BaseComponent.toPlainText( parsed ) ); + assertEquals( "Test string with " + WHITE + "a placeholder", BaseComponent.toLegacyText( parsed ) ); } }