priyanshu_2010

Add a Stats System to my Zenith MC Minecraft plugin for Paper 1.21.11 / Java 21.

Command

text
/stats

Permission:

text
plugin.stats

GUI

Open one single chest GUI showing:

* 💰 Money Top 10 * ◆ Shards Top 10 * ⚔ Kills Top 10 * ☠ Deaths Top 10

Each category should show the Top 10 players, preferably with player heads.

At the bottom of the same GUI, show the player who opened /stats:

text
YOUR STATS

PlayerName

💰 Money: $125,000
◆ Shards: 8,500
⚔ Kills: 125
☠ Deaths: 42

Money Rank: #14
Shards Rank: #8
Kills Rank: #23
Deaths Rank: #31

The player's personal stats and ranks must always be shown, even if they are not in the Top 10.

Storage

* Store Shards, Kills and Deaths by UUID. * Use Vault for Money. * Stats must persist after restart/reload. * Use cached rankings for performance.

Admin

text
/statsadmin reload
/statsadmin refresh

Permission:

text
plugin.stats.admin

GUI Security

Players must not be able to take or move any GUI items through clicking, shift-click, dragging, number keys, etc.

Geyser/Floodgate

The entire /stats GUI must work for both Java and Bedrock players through GeyserMC + Floodgate using a normal chest inventory GUI.

Important

Do not put rankings on the normal Zenith MC scoreboard. Rankings should only appear in /stats.

Keep the system simple and focused only on Money, Shards, Kills, Deaths, Top 10 rankings, and the viewing player's own stats/ranks.

Kodari AI
KodariSep 24 at 12:46 pm 2
ZenithStatsGUI
A Bukkit/Paper plugin adding a /stats command with a chest GUI showing Money, Shards, Kills, and Deaths Top 10 leaderboards with player heads. Displays the viewing player's personal stats and ranks at the bottom, even if not in Top 10. Uses Vault for money, persistent UUID-based storage for shards/kills/deaths, cached rankings for performance, and a /statsadmin command for reload/refresh. Fully compatible with Geyser/Floodgate Bedrock players, with complete GUI security preventing item movement.

Plan:

  1. Create a Java 21/Paper plugin skeleton and Vault-backed money integration.

  2. Add UUID-persisted stats, cached rankings, and join/death tracking.

  3. Add the combined, click-protected /stats GUI and admin reload/refresh commands.

Created the ZenithStats plugin with /stats and /statsadmin reload|refresh.

The single chest GUI shows Top 10 lists for money, shards, kills, and deaths, plus the viewer’s own stats and ranks. Shards, kills, and deaths are stored by UUID in data.yml; money comes from Vault. Rankings are cached and refreshed periodically (configurable in config.yml) or with /statsadmin refresh. GUI clicks and drags are cancelled, and the standard chest inventory works through Geyser/Floodgate.

Kills and deaths update on player deaths. Other plugins can update shards through getStatsManager().addShards(uuid, amount) or setShards(uuid, amount). Vault and a compatible economy provider are required.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
settings.gradle
Code
10 618
src/main/java/com/zenithmc/stats/ZenithStatsPlugin.java
package com.zenithmc.stats;

import net.milkbowl.vault.economy.Economy;
import org.bukkit.Bukkit;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitTask;

public final class ZenithStatsPlugin extends JavaPlugin {
    private StatsManager statsManager;
    private BukkitTask rankingTask;

    @Override
    public void onEnable() {
        RegisteredServiceProvider<Economy> registration = getServer().getServicesManager().getRegistration(Economy.class);
        if (registration == null || registration.getProvider() == null) {
            getLogger().severe("Vault and a Vault-compatible economy provider are required.");
            Bukkit.getPluginManager().disablePlugin(this);
            return;
        }

        saveDefaultConfig();
        statsManager = new StatsManager(this, registration.getProvider());
        statsManager.refreshRankings();
        startRankingRefresh();

        getServer().getPluginManager().registerEvents(new StatsListener(statsManager), this);
        getCommand("stats").setExecutor(new StatsCommand(statsManager));
        getCommand("statsadmin").setExecutor(new StatsAdminCommand(this));
    }

    @Override
    public void onDisable() {
        if (rankingTask != null) {
            rankingTask.cancel();
        }
        if (statsManager != null) {
            statsManager.saveData();
        }
    }

    public void reloadStats() {
        reloadConfig();
        statsManager.reloadData();
        statsManager.refreshRankings();
        startRankingRefresh();
    }

    public void refreshRankings() {
        statsManager.refreshRankings();
    }

    public StatsManager getStatsManager() {
        return statsManager;
    }

    private void startRankingRefresh() {
        if (rankingTask != null) {
            rankingTask.cancel();
        }
        long seconds = Math.max(10L, getConfig().getLong("ranking-refresh-seconds", 60L));
        rankingTask = getServer().getScheduler().runTaskTimer(this, statsManager::refreshRankings,
                seconds * 20L, seconds * 20L);
    }
}