Skip to content

Commit

Permalink
regex optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
AoElite committed Oct 22, 2024
1 parent 09e6cec commit bfd3433
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/main/java/ac/grim/grimac/utils/anticheat/MessageUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@ public String format(String string) {
}

public String formatWithNoColor(String string) {
return string.replace("%prefix%", GrimAPI.INSTANCE.getConfigManager().getConfig().getStringElse("prefix", "&bGrim &8»"));
return string.replace("%prefix%", GrimAPI.INSTANCE.getConfigManager().getPrefix());
}

private static final Pattern HEX_PATTERN = Pattern.compile("#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{8})");

private String translateHexCodes(String message) {
final String hexPattern = "#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{8})";
Matcher matcher = Pattern.compile(hexPattern).matcher(message);
StringBuffer sb = new StringBuffer(message.length());
Matcher matcher = HEX_PATTERN.matcher(message);
StringBuilder sb = new StringBuilder(message.length());
while (matcher.find()) {
String hex = matcher.group(1);
ChatColor color = ChatColor.of("#" + hex);
Expand All @@ -44,4 +45,5 @@ private String translateHexCodes(String message) {
matcher.appendTail(sb);
return sb.toString();
}

}

0 comments on commit bfd3433

Please sign in to comment.