Last active
September 23, 2022 19:59
-
-
Save TehBrian/8c7df397c37081e8ceb6d279275a4aba to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/* Prefer using adventure or something, but if you need something tiny.. */ | |
public static final Pattern HEX_PATTERN = Pattern.compile("&(#[A-Fa-f0-9]{6})"); | |
public static String color(String string) { | |
return string == null ? null : replaceHex(ChatColor.translateAlternateColorCodes('&', string)); | |
} | |
public static String replaceHex(String str) { | |
Matcher matcher = HEX_PATTERN.matcher(str); | |
while (matcher.find()) { | |
str = str.replace(matcher.group(0), ChatColor.of(matcher.group(1)).toString()); | |
} | |
return str; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment