Исправлен баг с отображением градиента в GUI: теперь используется MiniMessage формат для правильного отображения градиента
This commit is contained in:
parent
cb60c29e91
commit
55c965603f
2 changed files with 14 additions and 5 deletions
|
|
@ -3,6 +3,7 @@ package com.loki.lochat.gradient.gui;
|
|||
import com.loki.lochat.gradient.GradientModule;
|
||||
import com.loki.lochat.gradient.util.GradientConstants;
|
||||
import com.loki.lochat.gradient.util.GradientUtil;
|
||||
import com.loki.lochat.utils.ChatFormatter;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.format.TextDecoration;
|
||||
|
|
@ -67,7 +68,8 @@ public class GradientConfirmGUI implements InventoryHolder {
|
|||
skullMeta.setOwningPlayer(player);
|
||||
|
||||
String preview = buildPreview();
|
||||
Component previewComponent = SERIALIZER.deserialize(preview);
|
||||
// Preview уже в MiniMessage формате, просто парсим
|
||||
Component previewComponent = ChatFormatter.parse(preview);
|
||||
skullMeta.displayName(previewComponent.decoration(TextDecoration.ITALIC, false));
|
||||
|
||||
List<Component> lore = new ArrayList<>();
|
||||
|
|
@ -124,6 +126,9 @@ public class GradientConfirmGUI implements InventoryHolder {
|
|||
}
|
||||
}
|
||||
|
||||
// Для GUI всегда используем MiniMessage формат (false) для правильного отображения градиента
|
||||
boolean useLegacyForPreview = false;
|
||||
|
||||
// Если нет кастомного префикса - используем LuckPerms префикс
|
||||
if ((prefixToUse == null || prefixToUse.isEmpty()) && module.getLuckPermsHook().isEnabled()) {
|
||||
String lpPrefix = module.getLuckPermsHook().getActivePrefix(player);
|
||||
|
|
@ -134,11 +139,11 @@ public class GradientConfirmGUI implements InventoryHolder {
|
|||
// Убираем цвета из LP префикса и применяем градиент на всё
|
||||
String cleanLpPrefix = stripColors(lpPrefix);
|
||||
String fullText = cleanLpPrefix + nick;
|
||||
return GradientUtil.applyGradient(fullText, colorsToUse, module.getConfig().isUseLegacyRgbFormat());
|
||||
return GradientUtil.applyGradient(fullText, colorsToUse, useLegacyForPreview);
|
||||
} else {
|
||||
// LP префикс со своими цветами + градиентный ник
|
||||
if (colorsToUse != null && !colorsToUse.isEmpty()) {
|
||||
return lpPrefix + GradientUtil.applyGradient(nick, colorsToUse, module.getConfig().isUseLegacyRgbFormat());
|
||||
return lpPrefix + GradientUtil.applyGradient(nick, colorsToUse, useLegacyForPreview);
|
||||
}
|
||||
return lpPrefix + nick;
|
||||
}
|
||||
|
|
@ -152,7 +157,7 @@ public class GradientConfirmGUI implements InventoryHolder {
|
|||
module.getConfig().isGradientOnPrefix(),
|
||||
module.getConfig().isContinuousGradient(),
|
||||
module.getConfig().getPrefixFormat(),
|
||||
module.getConfig().isUseLegacyRgbFormat()
|
||||
useLegacyForPreview
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -40,12 +40,16 @@ public final class GradientUtil {
|
|||
result.append(colorCode).append(text).append("</color>");
|
||||
}
|
||||
} else {
|
||||
// Градиент из нескольких цветов
|
||||
Color[] colors = hexColors.stream()
|
||||
.map(GradientUtil::parseHex)
|
||||
.toArray(Color[]::new);
|
||||
|
||||
// Правильно вычисляем ratio для каждого символа
|
||||
for (int i = 0; i < length; i++) {
|
||||
Color interpolated = interpolateMultiColor(colors, (double) i / Math.max(1, length - 1));
|
||||
// Вычисляем позицию символа от 0.0 до 1.0
|
||||
double ratio = length > 1 ? (double) i / (length - 1) : 0.0;
|
||||
Color interpolated = interpolateMultiColor(colors, ratio);
|
||||
String hex = String.format("#%02x%02x%02x",
|
||||
interpolated.getRed(), interpolated.getGreen(), interpolated.getBlue());
|
||||
result.append(formatHex(hex, useLegacyFormat)).append(chars[i]);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue