Fix prefix showing colors when disabled + add customizable TextDisplay format with placeholders
This commit is contained in:
parent
8712a98a87
commit
4494c457a4
4 changed files with 48 additions and 49 deletions
|
|
@ -87,6 +87,7 @@ public class GradientConfig {
|
||||||
public double getTextDisplayHeight() { return config.getDouble("display.text-display-height", 2.8); }
|
public double getTextDisplayHeight() { return config.getDouble("display.text-display-height", 2.8); }
|
||||||
public float getTextDisplayScale() { return (float) config.getDouble("display.text-display-scale", 0.8); }
|
public float getTextDisplayScale() { return (float) config.getDouble("display.text-display-scale", 0.8); }
|
||||||
public boolean isTextDisplaySeeThrough() { return config.getBoolean("display.text-display-see-through", false); }
|
public boolean isTextDisplaySeeThrough() { return config.getBoolean("display.text-display-see-through", false); }
|
||||||
|
public String getTextDisplayFormat() { return config.getString("display.text-display-format", "{prefix}{player}"); }
|
||||||
|
|
||||||
// Метод для временного изменения настройки TextDisplay
|
// Метод для временного изменения настройки TextDisplay
|
||||||
public void setUseTextDisplay(boolean useTextDisplay) {
|
public void setUseTextDisplay(boolean useTextDisplay) {
|
||||||
|
|
|
||||||
|
|
@ -129,9 +129,13 @@ public final class DisplayNameUtil {
|
||||||
GradientConfig cfg = module.getConfig();
|
GradientConfig cfg = module.getConfig();
|
||||||
String prefix = cfg.getPrefixFormat().replace("{prefix}", data.getPrefix()).stripTrailing();
|
String prefix = cfg.getPrefixFormat().replace("{prefix}", data.getPrefix()).stripTrailing();
|
||||||
|
|
||||||
return (data.hasColors() && data.isColorEnabled() && cfg.isGradientOnPrefix())
|
// Применяем градиент только если цвета включены И есть цвета
|
||||||
? GradientUtil.applyGradient(prefix, data.getColors(), cfg.isUseLegacyRgbFormat())
|
if (data.hasColors() && data.isColorEnabled() && cfg.isGradientOnPrefix()) {
|
||||||
: prefix;
|
return GradientUtil.applyGradient(prefix, data.getColors(), cfg.isUseLegacyRgbFormat());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Возвращаем префикс без цветов
|
||||||
|
return prefix;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -111,59 +111,59 @@ public class TextDisplayManager {
|
||||||
* Получает текст для отображения над игроком
|
* Получает текст для отображения над игроком
|
||||||
*/
|
*/
|
||||||
private String getDisplayText(Player player, GradientPlayerData data) {
|
private String getDisplayText(Player player, GradientPlayerData data) {
|
||||||
String prefix = null;
|
String format = module.getConfig().getTextDisplayFormat();
|
||||||
|
|
||||||
|
// Получаем компоненты
|
||||||
|
String prefix = getPlayerPrefix(player, data);
|
||||||
|
String playerName = getPlayerName(player, data);
|
||||||
|
|
||||||
|
// Заменяем плейсхолдеры
|
||||||
|
String result = format
|
||||||
|
.replace("{prefix}", prefix != null ? prefix : "")
|
||||||
|
.replace("{player}", playerName)
|
||||||
|
.replace("{name}", playerName); // Альтернативный плейсхолдер
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Получает префикс игрока
|
||||||
|
*/
|
||||||
|
private String getPlayerPrefix(Player player, GradientPlayerData data) {
|
||||||
String prefixFormat = module.getConfig().getPrefixFormat();
|
String prefixFormat = module.getConfig().getPrefixFormat();
|
||||||
|
|
||||||
// Определяем префикс: сначала кастомный, потом LuckPerms
|
// Определяем префикс: сначала кастомный, потом LuckPerms
|
||||||
if (data.isPrefixEnabled() && data.hasPrefix()) {
|
if (data.isPrefixEnabled() && data.hasPrefix()) {
|
||||||
prefix = data.getPrefix();
|
String prefix = prefixFormat.replace("{prefix}", data.getPrefix());
|
||||||
|
// Применяем градиент только если цвета включены
|
||||||
|
if (data.isColorEnabled() && data.hasColors() && module.getConfig().isGradientOnPrefix()) {
|
||||||
|
return GradientUtil.applyGradient(prefix, data.getColors(), false); // MiniMessage формат
|
||||||
|
}
|
||||||
|
return prefix;
|
||||||
} else if (module.getLuckPermsHook().isEnabled()) {
|
} else if (module.getLuckPermsHook().isEnabled()) {
|
||||||
String lpPrefix = module.getLuckPermsHook().getActivePrefix(player);
|
String lpPrefix = module.getLuckPermsHook().getActivePrefix(player);
|
||||||
if (lpPrefix != null && !lpPrefix.isEmpty()) {
|
if (lpPrefix != null && !lpPrefix.isEmpty()) {
|
||||||
// Для LuckPerms префикса используем специальную логику
|
// Для LuckPerms префикса применяем градиент только если включено
|
||||||
return buildWithLuckPermsPrefix(
|
if (data.isColorEnabled() && data.hasColors() && module.getConfig().isGradientOnLuckPermsPrefix()) {
|
||||||
lpPrefix,
|
String cleanPrefix = stripColors(lpPrefix);
|
||||||
player.getName(),
|
return GradientUtil.applyGradient(cleanPrefix, data.getColors(), false);
|
||||||
data.isColorEnabled() ? data.getColors() : null,
|
}
|
||||||
module.getConfig().isUseLegacyRgbFormat(),
|
return lpPrefix;
|
||||||
module.getConfig().isContinuousGradient()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Строим display text с кастомным префиксом или без префикса
|
return "";
|
||||||
String displayText = GradientUtil.buildDisplayName(
|
|
||||||
prefix,
|
|
||||||
player.getName(),
|
|
||||||
data.isColorEnabled() ? data.getColors() : null,
|
|
||||||
module.getConfig().isGradientOnPrefix(),
|
|
||||||
module.getConfig().isContinuousGradient(),
|
|
||||||
prefixFormat,
|
|
||||||
false // Используем MiniMessage формат для TextDisplay
|
|
||||||
);
|
|
||||||
|
|
||||||
// Конвертируем &#RRGGBB в <#RRGGBB> для MiniMessage
|
|
||||||
return convertToMiniMessageFormat(displayText);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Строит текст с LuckPerms префиксом
|
* Получает имя игрока с градиентом
|
||||||
*/
|
*/
|
||||||
private String buildWithLuckPermsPrefix(String lpPrefix, String nick,
|
private String getPlayerName(Player player, GradientPlayerData data) {
|
||||||
java.util.List<String> colors,
|
// Применяем градиент только если цвета включены
|
||||||
boolean useLegacyFormat,
|
if (data.isColorEnabled() && data.hasColors()) {
|
||||||
boolean continuousGradient) {
|
return GradientUtil.applyGradient(player.getName(), data.getColors(), false); // MiniMessage формат
|
||||||
if (colors == null || colors.isEmpty()) {
|
|
||||||
return lpPrefix + nick;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (continuousGradient) {
|
|
||||||
String cleanPrefix = stripColors(lpPrefix);
|
|
||||||
String fullText = cleanPrefix + nick;
|
|
||||||
return GradientUtil.applyGradient(fullText, colors, false); // Всегда MiniMessage формат для TextDisplay
|
|
||||||
} else {
|
|
||||||
return lpPrefix + GradientUtil.applyGradient(nick, colors, false); // Всегда MiniMessage формат для TextDisplay
|
|
||||||
}
|
}
|
||||||
|
return player.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -174,14 +174,6 @@ public class TextDisplayManager {
|
||||||
return text.replaceAll("(?i)(§x(§[0-9a-f]){6}|§[0-9a-fk-or]|&[0-9a-fk-or]|&#[0-9a-f]{6}|<[^>]+>)", "");
|
return text.replaceAll("(?i)(§x(§[0-9a-f]){6}|§[0-9a-fk-or]|&[0-9a-fk-or]|&#[0-9a-f]{6}|<[^>]+>)", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Возвращает текст как есть, так как градиенты уже в MiniMessage формате
|
|
||||||
*/
|
|
||||||
private String convertToMiniMessageFormat(String text) {
|
|
||||||
if (text == null) return "";
|
|
||||||
return text;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Удаляет TextDisplay игрока
|
* Удаляет TextDisplay игрока
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -57,6 +57,8 @@ display:
|
||||||
text-display-scale: 0.8
|
text-display-scale: 0.8
|
||||||
# Видно ли TextDisplay через стены
|
# Видно ли TextDisplay через стены
|
||||||
text-display-see-through: false
|
text-display-see-through: false
|
||||||
|
# Формат TextDisplay (поддерживает плейсхолдеры)
|
||||||
|
text-display-format: "{prefix}{player}"
|
||||||
|
|
||||||
# Тип хранилища: YAML или SQLITE
|
# Тип хранилища: YAML или SQLITE
|
||||||
storage-type: YAML
|
storage-type: YAML
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue