Skip to content

Commit

Permalink
#371 Add hex support to messages.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
espidev committed Jul 5, 2024
1 parent 36ac55f commit 24c225a
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions src/main/java/dev/espi/protectionstones/PSL.java
Original file line number Diff line number Diff line change
Expand Up @@ -516,21 +516,14 @@ private static void messageUpgrades(PSL psl, YamlConfiguration yml) {
}
}

// match all %#123abc#% format for hex
private static final Pattern hexPatternLong = Pattern.compile("(?<!\\\\\\\\)(%#[a-fA-F0-9]{8}%)"),
hexPatternShort = Pattern.compile("(?<!\\\\\\\\)(%#[a-fA-F0-9]{6}%)");
// match all &#123abc format for hex
private static final Pattern hexPattern = Pattern.compile("(?<!\\\\\\\\)(&#[a-fA-F0-9]{6})");

private static String applyInGameColours(String msg) {

Matcher matcher = hexPatternLong.matcher(msg);
Matcher matcher = hexPattern.matcher(msg);
while (matcher.find()) {
String color = msg.substring(matcher.start() + 1, matcher.end() - 1);
msg = msg.replace(msg.substring(matcher.start(), matcher.end()), "" + net.md_5.bungee.api.ChatColor.of(color));
}

matcher = hexPatternShort.matcher(msg);
while (matcher.find()) {
String color = msg.substring(matcher.start() + 1, matcher.end() - 1);
String color = msg.substring(matcher.start() + 1, matcher.end());
msg = msg.replace(msg.substring(matcher.start(), matcher.end()), "" + net.md_5.bungee.api.ChatColor.of(color));
}

Expand Down

0 comments on commit 24c225a

Please sign in to comment.