Add gradient on LuckPerms prefix option

This commit is contained in:
loki5512344 2025-12-29 15:52:01 +01:00
parent 4d21241150
commit df06da900a
3 changed files with 25 additions and 2 deletions

View file

@ -122,7 +122,7 @@ public class GradientModule {
GradientPlayerData data = dataManager.getPlayerData(player.getUniqueId());
StringBuilder result = new StringBuilder();
// Сначала LuckPerms префикс (если нет кастомного)
// LuckPerms префикс
String lpPrefix = null;
if (luckPermsHook.isEnabled()) {
lpPrefix = luckPermsHook.getActivePrefix(player);
@ -137,8 +137,14 @@ public class GradientModule {
result.append(customPrefix);
}
} else if (lpPrefix != null && !lpPrefix.isEmpty()) {
// Применяем градиент на LP префикс если включено и есть цвета
if (data.hasColors() && data.isColorEnabled() && config.isGradientOnLuckPermsPrefix()) {
String cleanPrefix = stripColors(lpPrefix);
result.append(GradientUtil.applyGradient(cleanPrefix, data.getColors(), config.isUseLegacyRgbFormat()));
} else {
result.append(lpPrefix);
}
}
// Ник с градиентом
if (data.hasColors() && data.isColorEnabled()) {
@ -150,6 +156,14 @@ public class GradientModule {
return result.toString();
}
/**
* Убирает цветовые коды из строки
*/
private String stripColors(String text) {
if (text == null) return "";
return text.replaceAll("(?i)(§x(§[0-9a-f]){6}|§[0-9a-fk-or]|&[0-9a-fk-or]|&#[0-9a-f]{6}|<[^>]+>)", "");
}
/**
* Получает только градиентный ник (без префикса)
*/
@ -185,6 +199,11 @@ public class GradientModule {
if (luckPermsHook.isEnabled()) {
String lpPrefix = luckPermsHook.getActivePrefix(player);
if (lpPrefix != null && !lpPrefix.isEmpty()) {
// Применяем градиент если включено
if (data.hasColors() && data.isColorEnabled() && config.isGradientOnLuckPermsPrefix()) {
String cleanPrefix = stripColors(lpPrefix);
return GradientUtil.applyGradient(cleanPrefix, data.getColors(), config.isUseLegacyRgbFormat());
}
return lpPrefix;
}
}

View file

@ -64,6 +64,7 @@ public class GradientConfig {
public int getMaxPrefixLength() { return config.getInt("max-prefix-length", 7); }
public String getPrefixFormat() { return config.getString("prefix-format", "[{prefix}] "); }
public boolean isGradientOnPrefix() { return config.getBoolean("gradient-on-prefix", true); }
public boolean isGradientOnLuckPermsPrefix() { return config.getBoolean("gradient-on-luckperms-prefix", true); }
public boolean isContinuousGradient() { return config.getBoolean("continuous-gradient", true); }
public boolean isUseLegacyRgbFormat() { return config.getBoolean("use-legacy-rgb-format", true); }
public String getStorageType() { return config.getString("storage-type", "YAML"); }

View file

@ -34,6 +34,9 @@ prefix-format: "[{prefix}] "
# Применять градиент на префикс
gradient-on-prefix: true
# Применять градиент на LuckPerms префикс (если нет кастомного)
gradient-on-luckperms-prefix: true
# Единый градиент на префикс + ник
continuous-gradient: true