From 77b0a38c2673769372cb7329ce7f4c9eb129b89a Mon Sep 17 00:00:00 2001 From: Simon Chuu Date: Mon, 9 Jul 2018 03:20:11 -0400 Subject: [PATCH] #2457: Allow objects in `with` to be translated into a string (for integer, float, etc.) --- .../net/md_5/bungee/api/chat/TranslatableComponent.java | 8 ++++---- .../md_5/bungee/api/chat/TranslatableComponentTest.java | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/chat/src/main/java/net/md_5/bungee/api/chat/TranslatableComponent.java b/chat/src/main/java/net/md_5/bungee/api/chat/TranslatableComponent.java index 53ee9b0da..16e8d2a46 100644 --- a/chat/src/main/java/net/md_5/bungee/api/chat/TranslatableComponent.java +++ b/chat/src/main/java/net/md_5/bungee/api/chat/TranslatableComponent.java @@ -71,12 +71,12 @@ public final class TranslatableComponent extends BaseComponent List temp = new ArrayList(); for ( Object w : with ) { - if ( w instanceof String ) - { - temp.add( new TextComponent( (String) w ) ); - } else + if ( w instanceof BaseComponent ) { temp.add( (BaseComponent) w ); + } else + { + temp.add( new TextComponent( String.valueOf( w ) ) ); } } setWith( temp ); 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 0837c6729..2391c22f7 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 @@ -9,7 +9,7 @@ public class TranslatableComponentTest @Test public void testMissingPlaceholdersAdded() { - TranslatableComponent testComponent = new TranslatableComponent( "Test string with %s placeholders: %s", "2", "aoeu" ); + 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() ); }