I am currently making my own plugin with paper / spigot. My goal is to make an all-in-one economy plugin that allows users to connect to various database languages and to have full customization for their economy. I am currently in the process of making scoreboards that use placeholderapi to display certain characteristics pertaining to the player. I've made a scoreboard system using a dependency called "fastboard" to help me make the scoreboards. I would like to render unicode emojis as well as hexadecimal colors on the scoreboard. My configs look something like follows:
All of the placeholders work, the issue is the hexadecimal in the title as well as the emojis "^z^t" like such. The goal is to replace keystroke emojis with the actual ones in game. I've seen TAB do exactly what my goal is though I'm not sure how.
Here is the code for my scoreboard handler. It gets instantiated in the main.
YAML:
scoreboard:
enabled: true
hidden-by-default: false
title: "<#FFFFFF>&l- Wall-Y.ca -</#FFFF00>"
lines:
- ""
- "&4&l ^z^t&r Kills: &4%statistic_player_kills%"
- "&6&l ^=^r^`&r Deaths: &6%statistic_deaths%"
- "&a&l$&r Money: &a%vault_eco_balance_formatted%"
- "&e&l ^o &r Playtime: &e%ptr_playtime_days%d %ptr_playtime_hours_trimmed%h"
- "&9&l ^=^q &r Rank: %luckperms_suffix%"
All of the placeholders work, the issue is the hexadecimal in the title as well as the emojis "^z^t" like such. The goal is to replace keystroke emojis with the actual ones in game. I've seen TAB do exactly what my goal is though I'm not sure how.
Here is the code for my scoreboard handler. It gets instantiated in the main.
Java:
package isaacwallace123.ecoverse.Utils;
import fr.mrmicky.fastboard.FastBoard;
import isaacwallace123.ecoverse.Ecoverse;
import me.clip.placeholderapi.PlaceholderAPI;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Scoreboard implements Listener {
private final Map<UUID, FastBoard> boards = new HashMap<>();
private final FileConfiguration config;
private final boolean hasPlaceholders = Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null;
public Scoreboard(Ecoverse plugin) {
Bukkit.getPluginManager().registerEvents(this, plugin);
config = plugin.getConfig();
plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, () -> {
for (FastBoard board : boards.values()) {
updateBoard(board);
}
}, 0L, 10L);
}
@EventHandler
public void onPlayerJoin(org.bukkit.event.player.PlayerJoinEvent event) {
Player player = event.getPlayer();
FastBoard board = new FastBoard(player);
String title = config.getString("scoreboard.title", "&c&lEcoverse");;
board.updateTitle(formatLine(title, player));
boards.put(player.getUniqueId(), board);
}
@EventHandler
public void onPlayerQuit(org.bukkit.event.player.PlayerQuitEvent event) {
Player player = event.getPlayer();
FastBoard board = boards.remove(player.getUniqueId());
if (board != null) {
board.delete();
}
}
private void updateBoard(FastBoard board) {
String[] lines = config.getStringList("scoreboard.lines").toArray(new String[0]);
Player player = board.getPlayer();
for (int i = 0; i < lines.length; i++) {
lines[i] = formatLine(lines[i], player);
}
board.updateLines(lines);
}
private String replaceHexColors(String text) {
Pattern hexPattern = Pattern.compile("#([A-Fa-f0-9]{6})");
Matcher matcher = hexPattern.matcher(text);
// Replace #RRGGBB with the correct Minecraft color format
while (matcher.find()) {
String hexColor = matcher.group();
String minecraftColor = "&x" + hexColor.charAt(1) + hexColor.charAt(2) + hexColor.charAt(3) + hexColor.charAt(4) + hexColor.charAt(5) + hexColor.charAt(6);
text = text.replace(hexColor, minecraftColor);
}
return text;
}
private String formatLine(String line, Player player) {
if (hasPlaceholders) {
line = PlaceholderAPI.setPlaceholders(player, line);
}
line = ChatColor.translateAlternateColorCodes('&', line);
line = replaceHexColors(line);
return line;
}
}