2121import org .bukkit .ChatColor ;
2222import org .bukkit .Material ;
2323
24+ import java .util .regex .Matcher ;
2425import java .util .regex .Pattern ;
2526
2627public class ConfigTools {
2728
2829 private final ToolStats toolStats ;
29- private final Pattern COLOR_CODES = Pattern .compile ("(?i)&[0-9A-FK-ORX]" );
30+ private final Pattern COLOR_CODES = Pattern .compile ("&([0-9a-fk-or])" );
31+ private final Pattern HEX_PATTERN = Pattern .compile ("&#([A-Fa-f0-9]{6})" );
3032
3133 public ConfigTools (ToolStats toolStats ) {
3234 this .toolStats = toolStats ;
@@ -110,7 +112,7 @@ public boolean checkConfig(Material material, String configName) {
110112 * Gets the lore message from the config.
111113 *
112114 * @param configName The config name, "messages." is already in front.
113- * @param raw If you want the raw message with the formatting codes and placeholders.
115+ * @param raw If you want the raw message. False if you want no placeholders.
114116 * @return The lore message.
115117 */
116118 public String getLoreFromConfig (String configName , boolean raw ) {
@@ -119,13 +121,26 @@ public String getLoreFromConfig(String configName, boolean raw) {
119121 return null ;
120122 }
121123 if (raw ) {
122- return ChatColor .translateAlternateColorCodes ('&' , lore );
124+ Matcher hexMatcher = HEX_PATTERN .matcher (lore );
125+ while (hexMatcher .find ()) {
126+ String hexCode = hexMatcher .group (1 );
127+ lore = lore .replaceAll (hexMatcher .group (), net .md_5 .bungee .api .ChatColor .of ("#" + hexCode ).toString ());
128+ }
129+
130+ Matcher colorMatcher = COLOR_CODES .matcher (lore );
131+ while (colorMatcher .find ()) {
132+ String colorCode = colorMatcher .group (1 );
133+ lore = lore .replaceAll ("&" + colorCode , ChatColor .getByChar (colorCode ).toString ());
134+ }
135+
136+ return ChatColor .translateAlternateColorCodes ('§' , lore );
123137 } else {
124138 // remove all color codes
125139 // this is used to compare the current lore on the item
126140 // Example: [§7Arrows shot: §8] is on the lore
127141 // this will return [Arrows shot: ] so we can match it
128142 lore = COLOR_CODES .matcher (lore ).replaceAll ("" );
143+ lore = HEX_PATTERN .matcher (lore ).replaceAll ("" );
129144 if (lore .contains ("{player}" )) {
130145 lore = lore .replace ("{player}" , "" );
131146 }
0 commit comments