diff options
author | bowser0000 <bowser0000@gmail.com> | 2021-07-30 17:49:30 -0400 |
---|---|---|
committer | bowser0000 <bowser0000@gmail.com> | 2021-07-30 17:49:30 -0400 |
commit | 342c6c8c6096db1e3e0e2ea4363ba34764f1121b (patch) | |
tree | d658ff0b36726fc8e8617a6ebe4ce9fac958e357 /src/main | |
parent | d534e7e9da3c3d20825cda831f2814249e212d5a (diff) | |
download | SkyblockMod-342c6c8c6096db1e3e0e2ea4363ba34764f1121b.tar.gz SkyblockMod-342c6c8c6096db1e3e0e2ea4363ba34764f1121b.tar.bz2 SkyblockMod-342c6c8c6096db1e3e0e2ea4363ba34764f1121b.zip |
Add rainbow colour names
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/me/Danker/features/ColouredNames.java | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/main/java/me/Danker/features/ColouredNames.java b/src/main/java/me/Danker/features/ColouredNames.java index 2156f3a..cba327a 100644 --- a/src/main/java/me/Danker/features/ColouredNames.java +++ b/src/main/java/me/Danker/features/ColouredNames.java @@ -22,6 +22,7 @@ import java.util.regex.Pattern; public class ColouredNames { public static List<String> users = new ArrayList<>(); + public static final EnumChatFormatting[] RAINBOW_COLOURS = new EnumChatFormatting[]{EnumChatFormatting.RED, EnumChatFormatting.GOLD, EnumChatFormatting.YELLOW, EnumChatFormatting.GREEN, EnumChatFormatting.AQUA, EnumChatFormatting.BLUE, EnumChatFormatting.DARK_PURPLE}; @SubscribeEvent public void onChat(ClientChatReceivedEvent event) { @@ -76,8 +77,23 @@ public class ColouredNames { Matcher prevColourMat = Pattern.compile("(?:.*(?:(?<colour>\\u00a7[0-9a-fbr])" + name + ")\\b.*)").matcher(text); if (prevColourMat.matches()) { + if (colour.equals("§z")) { + StringBuilder rainbowName = new StringBuilder(); + for (int i = 0; i < name.length(); i++) { + rainbowName.append(RAINBOW_COLOURS[i % 7]).append(name.charAt(i)); + } + return text.replaceAll(namePattern, rainbowName + prevColourMat.group("colour")); + } return text.replaceAll(namePattern, colour + name + prevColourMat.group("colour")); } + + if (colour.equals("§z")) { + StringBuilder rainbowName = new StringBuilder(); + for (int i = 0; i < name.length(); i++) { + rainbowName.append(RAINBOW_COLOURS[i % 7]).append(name.charAt(i)); + } + return text.replaceAll(namePattern, rainbowName.toString() + EnumChatFormatting.WHITE); + } return text.replaceAll(namePattern, colour + name + EnumChatFormatting.WHITE); } |