Skip to content

Commit

Permalink
#3621: Warn about use of valid chat colors and add test
Browse files Browse the repository at this point in the history
  • Loading branch information
md-5 committed Mar 30, 2024
1 parent f224787 commit 6ab0f5e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,9 @@ public void setStyle(ComponentStyle style)

/**
* 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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
/**
Expand Down
11 changes: 11 additions & 0 deletions chat/src/test/java/net/md_5/bungee/api/chat/ComponentsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,17 @@ public void testComponentGettingExceptions()
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()
{
Expand Down

0 comments on commit 6ab0f5e

Please sign in to comment.