Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: inverted isEmpty method on ComponentStyle #3611

Merged
merged 3 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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