#3621: Warn about use of valid chat colors and add test

This commit is contained in:
md_5 2024-03-31 09:51:05 +11:00
parent f224787222
commit 6ab0f5eba7
No known key found for this signature in database
GPG Key ID: E8E901AC7C617C11
3 changed files with 17 additions and 0 deletions

View File

@ -253,6 +253,9 @@ public abstract class BaseComponent
/**
* Set this component's color.
* <p>
* <b>Warning: This should be a color, not formatting code (ie,
* {@link ChatColor#getColor()} should not be null).</b>
*
* @param color the component color, or null to use the default
*/

View File

@ -18,6 +18,9 @@ public final class ComponentStyle implements Cloneable
/**
* The color of this style.
* <p>
* <b>Warning: This should be a color, not formatting code (ie,
* {@link ChatColor#getColor()} should not be null).</b>
*/
private ChatColor color;
/**

View File

@ -155,6 +155,17 @@ public class ComponentsTest
assertThrows( IndexOutOfBoundsException.class, () -> builder.getComponent( 1 ) );
}
@Test
public void testFormatNotColor()
{
BaseComponent[] component = new ComponentBuilder().color( ChatColor.BOLD ).append( "Test" ).create();
String json = ComponentSerializer.toString( component );
BaseComponent[] parsed = ComponentSerializer.parse( json );
assertNull( parsed[0].getColorRaw(), "Format should not be preserved as color" );
}
@Test
public void testComponentParting()
{