Youssef Waleed

Write a custom Paper Minecraft plugin in Java for Paper version 26.2. I use Vault for economy.

Requirements:

  1. Header: "Welcome to CHIPSMP" (CHIPSMP must be yellow)
  2. Footer: Show live online player count.
  3. Player format in Tab: [Username] [$Balance] -> Example: chipsoii [$58m]

The plugin must fetch the player's Vault balance and accurately shorten it to clean values like 1k, 58m, 100b, 10t. Provide the complete Java source code and plugin.yml file.

Kodari AI
KodariOct 31 at 5:55 pm 1
TabBalanceFormatter
A Paper plugin that customizes the player tab list for CHIPSMP. Displays a yellow header "Welcome to CHIPSMP", a live online player count footer, and formats each player's name with their Vault balance shortened to clean values like 1k, 58m, 100b, 10t. Uses Vault economy integration and a tab list updater task.
  1. Add a Vault-backed tab-list plugin that refreshes names and online count live.

  2. Add plugin metadata declaring Vault as a required dependency.

Added ChipSMPTablist.java and plugin.yml. The tab list shows the yellow CHIPSMP header, online count, and Vault balances shortened to k/m/b/t; it refreshes every second. Vault is declared as a required plugin dependency.

Youssef Waleed

make it show ur nametags using the plugin nametag++

Kodari AI
KodariOct 31 at 6:42 pm 1
  • Check the current tab-list implementation and plugin metadata.

  • Look up Nametag++’s documented integration, then update the plugin to show the formatted name above players’ heads.

Added overhead nametags in the [Username] [$Balance] format, refreshed with the balance once per second. They’re implemented with Bukkit scoreboard teams; I couldn’t verify a Nametag++ API, so this doesn’t call Nametag++ directly, and Nametag++ may override the tags.

Kodari can make mistakes. Review important code before using.
Files
src
Code
2 129
src/main/java/com/chipsmp/tablist/ChipSMPTablist.java
package com.chipsmp.tablist;

import net.milkbowl.vault.economy.Economy;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.scoreboard.Scoreboard;
import org.bukkit.scoreboard.Team;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

public final class ChipSMPTablist extends JavaPlugin implements Listener {
    private static final String HEADER = ChatColor.WHITE + "Welcome to " + ChatColor.YELLOW + "CHIPSMP";
    private Economy economy;
    private final Map<UUID, Team> nametagTeams = new HashMap<>();

    @Override
    public void onEnable() {
        RegisteredServiceProvider<Economy> registration = getServer()
                .getServicesManager()
                .getRegistration(Economy.class);

        if (registration == null) {
            getLogger().severe("No Vault economy provider was found. Disabling plugin.");
            getServer().getPluginManager().disablePlugin(this);
            return;
        }

        economy = registration.getProvider();
        getServer().getPluginManager().registerEvents(this, this);
        getServer().getScheduler().runTaskTimer(this, this::refreshTabLists, 0L, 20L);
    }

    @EventHandler
    public void onPlayerJoin(PlayerJoinEvent event) {
        refreshTabLists();
    }

    @EventHandler
    public void onPlayerQuit(PlayerQuitEvent event) {
        removeNametag(event.getPlayer());
        getServer().getScheduler().runTask(this, this::refreshTabLists);
    }

    @Override
    public void onDisable() {
        for (Team team : nametagTeams.values()) {
            team.unregister();
        }
        nametagTeams.clear();
    }

    private void refreshTabLists() {
        String footer = ChatColor.GRAY + "Online: " + ChatColor.YELLOW + Bukkit.getOnlinePlayers().size();

        for (Player player : Bukkit.getOnlinePlayers()) {
            player.setPlayerListHeaderFooter(HEADER, footer);
            player.setPlayerListName(
                    ChatColor.GRAY + "[" + ChatColor.WHITE + player.getName() + ChatColor.GRAY + "] "
                            + ChatColor.GREEN + "[$" + formatBalance(economy.getBalance(player)) + "]"
            );
            updateNametag(player);
        }
    }

    private void updateNametag(Player player) {
        Scoreboard scoreboard = Bukkit.getScoreboardManager().getMainScoreboard();
        String teamName = "chipsmp_" + player.getUniqueId().toString().replace("-", "").substring(0, 8);
        Team team = scoreboard.getTeam(teamName);
        if (team == null) {
            team = scoreboard.registerNewTeam(teamName);
        }

        team.setPrefix(ChatColor.GRAY + "[");
        team.setSuffix(ChatColor.GRAY + "] " + ChatColor.GREEN + "[$" + formatBalance(economy.getBalance(player)) + "]");
        team.addEntry(player.getName());
        nametagTeams.put(player.getUniqueId(), team);
    }

    private void removeNametag(Player player) {
        Team team = nametagTeams.remove(player.getUniqueId());
        if (team != null) {
            team.unregister();
        }
    }

    private String formatBalance(double balance) {
        if (!Double.isFinite(balance)) {
            return "0";
        }

        BigDecimal value = BigDecimal.valueOf(balance);
        boolean negative = value.signum() < 0;
        value = value.abs();

        String[] suffixes = {"", "k", "m", "b", "t"};
        BigDecimal thousand = BigDecimal.valueOf(1_000);
        int suffixIndex = 0;

        while (value.compareTo(thousand) >= 0 && suffixIndex < suffixes.length - 1) {
            value = value.divide(thousand);
            suffixIndex++;
        }

        value = value.setScale(2, RoundingMode.HALF_UP).stripTrailingZeros();
        if (value.compareTo(thousand) >= 0 && suffixIndex < suffixes.length - 1) {
            value = value.divide(thousand).setScale(2, RoundingMode.HALF_UP).stripTrailingZeros();
            suffixIndex++;
        }

        return (negative ? "-" : "") + value.toPlainString() + suffixes[suffixIndex];
    }
}