fix: Fix hex colors not displaying in tablist, scoreboard and items
- Use LegacyComponentSerializer for proper color parsing - Fixed TablistManager to deserialize colors - Fixed ScoreboardManager to deserialize colors - Fixed ItemBuilder to use Adventure API for item names/lore - All hex colors (&#RRGGBB) now work correctly in 1.21.1
This commit is contained in:
parent
0a5acdecb0
commit
b922f588d0
3 changed files with 14 additions and 9 deletions
|
|
@ -4,6 +4,7 @@ import com.loki.lohub.LoHub;
|
||||||
import com.loki.lohub.common.ConfigHelper;
|
import com.loki.lohub.common.ConfigHelper;
|
||||||
import com.loki.lohub.common.TextFormatter;
|
import com.loki.lohub.common.TextFormatter;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.scoreboard.DisplaySlot;
|
import org.bukkit.scoreboard.DisplaySlot;
|
||||||
|
|
@ -20,6 +21,7 @@ public class ScoreboardManager {
|
||||||
|
|
||||||
private static final String CONFIG_PATH = "scoreboard";
|
private static final String CONFIG_PATH = "scoreboard";
|
||||||
private static final String OBJECTIVE_NAME = "lohub";
|
private static final String OBJECTIVE_NAME = "lohub";
|
||||||
|
private static final LegacyComponentSerializer SERIALIZER = LegacyComponentSerializer.legacySection();
|
||||||
|
|
||||||
private final LoHub plugin;
|
private final LoHub plugin;
|
||||||
private final Map<UUID, Scoreboard> scoreboards = new HashMap<>();
|
private final Map<UUID, Scoreboard> scoreboards = new HashMap<>();
|
||||||
|
|
@ -79,7 +81,7 @@ public class ScoreboardManager {
|
||||||
|
|
||||||
private void updateTitle(Player player, Objective objective) {
|
private void updateTitle(Player player, Objective objective) {
|
||||||
String title = plugin.getConfig().getString(CONFIG_PATH + ".title", "");
|
String title = plugin.getConfig().getString(CONFIG_PATH + ".title", "");
|
||||||
objective.displayName(Component.text(TextFormatter.format(title, player)));
|
objective.displayName(SERIALIZER.deserialize(TextFormatter.format(title, player)));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateLines(Player player, Scoreboard scoreboard, Objective objective) {
|
private void updateLines(Player player, Scoreboard scoreboard, Objective objective) {
|
||||||
|
|
@ -91,7 +93,7 @@ public class ScoreboardManager {
|
||||||
String teamName = "line_" + score;
|
String teamName = "line_" + score;
|
||||||
|
|
||||||
Team team = getOrCreateTeam(scoreboard, teamName);
|
Team team = getOrCreateTeam(scoreboard, teamName);
|
||||||
team.prefix(Component.text(formatted));
|
team.prefix(SERIALIZER.deserialize(formatted));
|
||||||
objective.getScore(teamName).setScore(score);
|
objective.getScore(teamName).setScore(score);
|
||||||
score--;
|
score--;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ package com.loki.lohub.managers;
|
||||||
import com.loki.lohub.LoHub;
|
import com.loki.lohub.LoHub;
|
||||||
import com.loki.lohub.common.ConfigHelper;
|
import com.loki.lohub.common.ConfigHelper;
|
||||||
import com.loki.lohub.common.TextFormatter;
|
import com.loki.lohub.common.TextFormatter;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
|
@ -12,6 +12,7 @@ import java.util.List;
|
||||||
public class TablistManager {
|
public class TablistManager {
|
||||||
|
|
||||||
private static final String CONFIG_PATH = "tablist";
|
private static final String CONFIG_PATH = "tablist";
|
||||||
|
private static final LegacyComponentSerializer SERIALIZER = LegacyComponentSerializer.legacySection();
|
||||||
|
|
||||||
private final LoHub plugin;
|
private final LoHub plugin;
|
||||||
private int taskId = -1;
|
private int taskId = -1;
|
||||||
|
|
@ -51,8 +52,8 @@ public class TablistManager {
|
||||||
String footer = formatLines(CONFIG_PATH + ".footer", player);
|
String footer = formatLines(CONFIG_PATH + ".footer", player);
|
||||||
|
|
||||||
player.sendPlayerListHeaderAndFooter(
|
player.sendPlayerListHeaderAndFooter(
|
||||||
Component.text(header),
|
SERIALIZER.deserialize(header),
|
||||||
Component.text(footer)
|
SERIALIZER.deserialize(footer)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -89,7 +89,8 @@ public class ItemBuilder {
|
||||||
public ItemBuilder name(String name) {
|
public ItemBuilder name(String name) {
|
||||||
ItemMeta meta = itemStack.getItemMeta();
|
ItemMeta meta = itemStack.getItemMeta();
|
||||||
if (meta != null) {
|
if (meta != null) {
|
||||||
meta.setDisplayName(TextUtil.colorize(name));
|
meta.displayName(net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection()
|
||||||
|
.deserialize(TextUtil.colorize(name)));
|
||||||
itemStack.setItemMeta(meta);
|
itemStack.setItemMeta(meta);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
|
|
@ -98,10 +99,11 @@ public class ItemBuilder {
|
||||||
public ItemBuilder lore(List<String> lore) {
|
public ItemBuilder lore(List<String> lore) {
|
||||||
ItemMeta meta = itemStack.getItemMeta();
|
ItemMeta meta = itemStack.getItemMeta();
|
||||||
if (meta != null) {
|
if (meta != null) {
|
||||||
List<String> coloredLore = lore.stream()
|
List<net.kyori.adventure.text.Component> coloredLore = lore.stream()
|
||||||
.map(TextUtil::colorize)
|
.map(line -> net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection()
|
||||||
|
.deserialize(TextUtil.colorize(line)))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
meta.setLore(coloredLore);
|
meta.lore(coloredLore);
|
||||||
itemStack.setItemMeta(meta);
|
itemStack.setItemMeta(meta);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue