1818package lol .hyper .toolstats .tools .config ;
1919
2020import lol .hyper .toolstats .ToolStats ;
21- import lol .hyper .toolstats .tools .ItemLore ;
2221import org .bukkit .ChatColor ;
2322import org .bukkit .Material ;
2423
2524import java .util .regex .Matcher ;
25+ import java .util .regex .Pattern ;
2626
2727public class ConfigTools {
2828
2929 private final ToolStats toolStats ;
30+ public static final Pattern COLOR_CODES = Pattern .compile ("[&§]([0-9a-fk-or])" );
31+ public static final Pattern CONFIG_HEX_PATTERN = Pattern .compile ("[&§]#([A-Fa-f0-9]{6})" );
32+ public static final Pattern MINECRAFT_HEX_PATTERN = Pattern .compile ("§x(?:§[a-fA-F0-9]){6}|§[a-fA-F0-9]" );
3033
3134 public ConfigTools (ToolStats toolStats ) {
3235 this .toolStats = toolStats ;
@@ -123,13 +126,13 @@ public String formatLore(String configName, String placeHolder, Object value) {
123126 // set the placeholder to the value
124127 lore = lore .replace (placeHolder , String .valueOf (value ));
125128
126- Matcher hexMatcher = ItemLore . HEX_PATTERN .matcher (lore );
129+ Matcher hexMatcher = CONFIG_HEX_PATTERN .matcher (lore );
127130 while (hexMatcher .find ()) {
128131 String hexCode = hexMatcher .group (1 );
129132 lore = lore .replaceAll (hexMatcher .group (), net .md_5 .bungee .api .ChatColor .of ("#" + hexCode ).toString ());
130133 }
131134
132- Matcher colorMatcher = ItemLore . COLOR_CODES .matcher (lore );
135+ Matcher colorMatcher = COLOR_CODES .matcher (lore );
133136 while (colorMatcher .find ()) {
134137 String colorCode = colorMatcher .group (1 );
135138 lore = lore .replaceAll ("&" + colorCode , ChatColor .getByChar (colorCode ).toString ());
@@ -145,8 +148,9 @@ public String formatLore(String configName, String placeHolder, Object value) {
145148 * @return The message without color codes.
146149 */
147150 public String removeColor (String message ) {
148- message = ItemLore .COLOR_CODES .matcher (message ).replaceAll ("" );
149- message = ItemLore .HEX_PATTERN .matcher (message ).replaceAll ("" );
151+ message = MINECRAFT_HEX_PATTERN .matcher (message ).replaceAll ("" );
152+ message = COLOR_CODES .matcher (message ).replaceAll ("" );
153+ message = CONFIG_HEX_PATTERN .matcher (message ).replaceAll ("" );
150154 return message ;
151155 }
152156}
0 commit comments