#2584: Add ComponentBuilder#appendLegacy
This commit is contained in:
parent
3889f8683d
commit
7496b0a2c8
@ -146,6 +146,19 @@ public final class ComponentBuilder
|
||||
return append( text, FormatRetention.ALL );
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse text to BaseComponent[] with colors and format, appends the text to
|
||||
* the builder and makes it the current target for formatting. The component
|
||||
* will have all the formatting from previous part.
|
||||
*
|
||||
* @param text the text to append
|
||||
* @return this ComponentBuilder for chaining
|
||||
*/
|
||||
public ComponentBuilder appendLegacy(String text)
|
||||
{
|
||||
return append( TextComponent.fromLegacyText( text ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends the text to the builder and makes it the current target for
|
||||
* formatting. You can specify the amount of formatting retained from
|
||||
|
@ -92,6 +92,18 @@ public class ComponentsTest
|
||||
Assert.assertEquals( ChatColor.YELLOW + "Hello " + ChatColor.GREEN + "world!", BaseComponent.toLegacyText( components ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuilderAppendLegacy()
|
||||
{
|
||||
ComponentBuilder builder = new ComponentBuilder( "Hello " ).color( ChatColor.YELLOW );
|
||||
builder.appendLegacy( "§aworld!" );
|
||||
|
||||
BaseComponent[] components = builder.create();
|
||||
|
||||
Assert.assertEquals( "Hello world!", BaseComponent.toPlainText( components ) );
|
||||
Assert.assertEquals( ChatColor.YELLOW + "Hello " + ChatColor.GREEN + "world!", BaseComponent.toLegacyText( components ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasicComponent()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user