mirror of
https://gitlab.com/phoenix-dvpmt/mmoitems.git
synced 2024-12-22 04:37:42 +01:00
<tier-color> fixed
This commit is contained in:
parent
5ed21155ea
commit
1878e7eb5c
@ -33,13 +33,13 @@ public class DisplayName extends StringStat implements GemStoneStat {
|
||||
// Bake
|
||||
String format = data.toString()
|
||||
.replace("<tier-name>", tier != null ? ColorUtils.stripColors(tier.getName()) : "")
|
||||
.replace("<tier-color>", tier != null ? ChatColor.getLastColors(tier.getName()) : "&f")
|
||||
.replace("<tier-color-cleaned>", tier != null ? ColorUtils.stripDecoration(ChatColor.getLastColors(tier.getName())) : "&f");
|
||||
.replace("<tier-color>", tier != null ? ColorUtils.getLastColors(tier.getName()) : "&f")
|
||||
.replace("<tier-color-cleaned>", tier != null ? ColorUtils.stripDecoration(ColorUtils.getLastColors(tier.getName())) : "&f");
|
||||
|
||||
if (tier != null) {
|
||||
System.out.println("Name: " + tier.getName());
|
||||
System.out.println("Format: " + format);
|
||||
System.out.println("Last Colors: " + ChatColor.getLastColors(tier.getName()) + " w: " + ColorUtils.stripDecoration(ChatColor.getLastColors(tier.getName())));
|
||||
System.out.println("Last Colors: " + ColorUtils.getLastColors(tier.getName()) + " w: " + ColorUtils.stripDecoration(ChatColor.getLastColors(tier.getName())));
|
||||
System.out.println("===================\n");
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,7 @@ package net.Indyuce.mmoitems.util;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
@ -15,12 +16,23 @@ public class ColorUtils {
|
||||
|
||||
private static final Pattern STRIP_DECORATION_PATTERN = Pattern.compile("(?i)" + '§' + "[K-O]");
|
||||
private static final Pattern COLOR_TAG_PATTERN = Pattern.compile("(?i)<.*>");
|
||||
private static final Pattern START_COLOR_TAG_PATTERN = Pattern.compile("(?i)<[^/]*>");
|
||||
private static final Pattern MINI_MSG_DECORATION_PATTERN = Pattern.compile("(?i)(<|</)(bold|italic|underlined|strikethrough|obfuscated|b|em|i|u|st|obf).*>");
|
||||
|
||||
public static @NotNull String stripDecoration(@NotNull String input) {
|
||||
return "%s%s".formatted(ChatColor.RESET, STRIP_DECORATION_PATTERN.matcher(input).replaceAll("")).replace('§', '&');
|
||||
return "%s%s".formatted(ChatColor.RESET, MINI_MSG_DECORATION_PATTERN.matcher(STRIP_DECORATION_PATTERN.matcher(input).replaceAll("")).replaceAll(""))
|
||||
.replace('§', '&');
|
||||
}
|
||||
|
||||
public static @NotNull String stripColors(@NotNull String input) {
|
||||
return ChatColor.stripColor(COLOR_TAG_PATTERN.matcher(input).replaceAll(""));
|
||||
}
|
||||
|
||||
public static @NotNull String getLastColors(@NotNull String input) {
|
||||
Matcher matcher = START_COLOR_TAG_PATTERN.matcher(input);
|
||||
String lastMatch = null;
|
||||
while (matcher.find())
|
||||
lastMatch = matcher.group();
|
||||
return lastMatch == null ? ChatColor.getLastColors(input) : lastMatch;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user