Skip to content
This repository has been archived by the owner on May 13, 2024. It is now read-only.

Commit

Permalink
[ci-skip] Make hex colors configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
ryderbelserion committed Apr 3, 2023
1 parent 429814c commit 0e1e511
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 17 deletions.
Expand Up @@ -41,6 +41,13 @@ public void onEnable() {
settingsManager.saveConfig();
}

String hexColorFormat = settingsManager.getConfig().getString("Hex_Color_Format");

if (hexColorFormat == null) {
settingsManager.getConfig().set("Hex_Color_Format", "#");
settingsManager.saveConfig();
}

String metricsValue = settingsManager.getConfig().getString("Metrics_Enabled");

if (metricsValue == null) {
Expand Down
45 changes: 28 additions & 17 deletions paper/src/main/java/me/h1dd3nxn1nja/chatmanager/Methods.java
Expand Up @@ -6,6 +6,7 @@
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import me.h1dd3nxn1nja.chatmanager.support.PluginSupport;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
Expand Down Expand Up @@ -41,33 +42,43 @@ public class Methods {
public static ArrayList<UUID> cm_socialSpy = new ArrayList<>();
public static ArrayList<UUID> cm_staffChat = new ArrayList<>();
public static ArrayList<UUID> cm_togglePM = new ArrayList<>();
public final static Pattern HEX_COLOR_PATTERN = Pattern.compile("#([A-Fa-f0-9]{6})");

private static final char COLOR_CHAR = ChatColor.COLOR_CHAR;

public static String color(String message) {
Matcher matcher = HEX_COLOR_PATTERN.matcher(message);
StringBuilder buffer = new StringBuilder();
String format = settingsManager.getConfig().getString("Hex_Color_Format");
Pattern hex = Pattern.compile(format + "([A-Fa-f0-9]{6})");
Matcher matcher = hex.matcher(message);
StringBuilder buffer = new StringBuilder(message.length() + 4 * 8);

while (matcher.find()) {
matcher.appendReplacement(buffer, ChatColor.of(matcher.group()).toString());
String group = matcher.group(1);
matcher.appendReplacement(buffer, COLOR_CHAR + "x"
+ COLOR_CHAR + group.charAt(0) + COLOR_CHAR + group.charAt(1)
+ COLOR_CHAR + group.charAt(2) + COLOR_CHAR + group.charAt(3)
+ COLOR_CHAR + group.charAt(4) + COLOR_CHAR + group.charAt(5)
);
}

return ChatColor.translateAlternateColorCodes('&', matcher.appendTail(buffer).toString());
return ChatColor.translateAlternateColorCodes('&', message);
}

public static String color(Player player, String message) {
if (plugin.getServer().getPluginManager().getPlugin("PlaceholderAPI") != null) {
Matcher matcher = HEX_COLOR_PATTERN.matcher(message);
StringBuilder buffer = new StringBuilder();

while (matcher.find()) {
matcher.appendReplacement(buffer, ChatColor.of(matcher.group()).toString());
}
public static String color(Player player, String message) {
String format = settingsManager.getConfig().getString("Hex_Color_Format");
Pattern hex = Pattern.compile(format + "([A-Fa-f0-9]{6})");
Matcher matcher = hex.matcher(message);
StringBuilder buffer = new StringBuilder(message.length() + 4 * 8);

return ChatColor.translateAlternateColorCodes('&', PlaceholderAPI.setPlaceholders(player, matcher.appendTail(buffer).toString()));
while (matcher.find()) {
String group = matcher.group(1);
matcher.appendReplacement(buffer, COLOR_CHAR + "x"
+ COLOR_CHAR + group.charAt(0) + COLOR_CHAR + group.charAt(1)
+ COLOR_CHAR + group.charAt(2) + COLOR_CHAR + group.charAt(3)
+ COLOR_CHAR + group.charAt(4) + COLOR_CHAR + group.charAt(5)
);
}

return color(message);
return PluginSupport.PLACEHOLDERAPI.isPluginEnabled() ? ChatColor.translateAlternateColorCodes('&', PlaceholderAPI.setPlaceholders(player, matcher.appendTail(buffer).toString())) : color(message);
}

public static String getPrefix() {
Expand Down
4 changes: 4 additions & 0 deletions paper/src/main/resources/config.yml
Expand Up @@ -876,6 +876,10 @@ Update_Checker: true
# If metrics is enabled or not
Metrics_Enabled: true

# The hex color format.
# Does not support <>, Only used to do &# etc. or any other identifier.
Hex_Color_Format: "#"

#=================================================================================================#
# You are done with the config!
#=================================================================================================#
Expand Down

0 comments on commit 0e1e511

Please sign in to comment.