#3610, 3611: inverted isEmpty method on ComponentStyle

This commit is contained in:
Diogo Correia 2024-02-02 01:16:46 +01:00 committed by GitHub
parent 02c5c1ee76
commit c3f228f626
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 27 additions and 5 deletions

View File

@ -186,15 +186,15 @@ public final class ComponentStyle implements Cloneable
} }
/** /**
* Returns whether this style has any formatting explicitly set. * Returns whether this style has no formatting explicitly set.
* *
* @return true if at least one value is set, false if none are set * @return true if no value is set, false if at least one is set
*/ */
public boolean isEmpty() public boolean isEmpty()
{ {
return color != null || font != null || bold != null return color == null && font == null && bold == null
|| italic != null || underlined != null && italic == null && underlined == null
|| strikethrough != null || obfuscated != null; && strikethrough == null && obfuscated == null;
} }
@Override @Override

View File

@ -825,6 +825,28 @@ public class ComponentsTest
); );
} }
@Test
public void testHasFormatting()
{
BaseComponent component = new TextComponent();
assertFalse( component.hasFormatting() );
component.setBold( true );
assertTrue( component.hasFormatting() );
}
@Test
public void testStyleIsEmpty()
{
ComponentStyle style = ComponentStyle.builder().build();
assertTrue( style.isEmpty() );
style = ComponentStyle.builder()
.bold( true )
.build();
assertFalse( style.isEmpty() );
}
/* /*
* In legacy chat, colors and reset both reset all formatting. * In legacy chat, colors and reset both reset all formatting.
* Make sure it works in combination with ComponentBuilder. * Make sure it works in combination with ComponentBuilder.