-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: make LegacyAdventureUtil supports hex color format (ex: &#ffffff)
- Loading branch information
Showing
2 changed files
with
90 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...ms/bukkit-platform/src/test/java/io/fairyproject/bukkit/util/LegacyAdventureUtilTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package io.fairyproject.bukkit.util; | ||
|
||
import net.kyori.adventure.text.Component; | ||
import net.kyori.adventure.text.format.NamedTextColor; | ||
import net.kyori.adventure.text.format.TextColor; | ||
import net.kyori.adventure.text.minimessage.MiniMessage; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class LegacyAdventureUtilTest { | ||
|
||
@Test | ||
public void shouldParseLegacyChatColor() { | ||
assertEquals( | ||
LegacyAdventureUtil.deserialize("&6Hello"), | ||
Component.text("Hello").color(NamedTextColor.GOLD) | ||
); | ||
} | ||
|
||
@Test | ||
public void shouldParseHexColor() { | ||
assertEquals( | ||
LegacyAdventureUtil.deserialize("&#ff0000Hello"), | ||
Component.text("Hello").color(TextColor.color(255, 0, 0)) | ||
); | ||
} | ||
|
||
@Test | ||
public void complexTestcases() { | ||
assertEquals( | ||
LegacyAdventureUtil.deserialize("&7[&r&#b92b27&lW&#aa235a&lO	a1b8d&lRb13c0&lK&7]"), | ||
MiniMessage.miniMessage().deserialize("<gray>[<reset><#b92b27><bold>W<#aa235a><bold>O<#9a1b8d><bold>R<#8b13c0><bold>K<gray>]") | ||
); | ||
} | ||
} | ||
|