Skip to content

Commit

Permalink
#3610, 3611: inverted isEmpty method on ComponentStyle
Browse files Browse the repository at this point in the history
  • Loading branch information
diogotcorreia authored Feb 2, 2024
1 parent 02c5c1e commit c3f228f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
10 changes: 5 additions & 5 deletions chat/src/main/java/net/md_5/bungee/api/chat/ComponentStyle.java
Original file line number Diff line number Diff line change
Expand Up @@ -186,15 +186,15 @@ public Boolean isObfuscatedRaw()
}

/**
* 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()
{
return color != null || font != null || bold != null
|| italic != null || underlined != null
|| strikethrough != null || obfuscated != null;
return color == null && font == null && bold == null
&& italic == null && underlined == null
&& strikethrough == null && obfuscated == null;
}

@Override
Expand Down
22 changes: 22 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 @@ -825,6 +825,28 @@ public void testLegacyResetInBuilderBuild()
);
}

@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.
* Make sure it works in combination with ComponentBuilder.
Expand Down

0 comments on commit c3f228f

Please sign in to comment.