panggilsajanabil.
📎 1 file 3,536 chars
📄
pasted-code-1782316401291.txt
txt 225 lines
▶
PLUGIN CONCEPT

This plugin creates a Rank Collection and Rank Switching System powered by LuckPerms.

The plugin is designed for servers where players may obtain ranks from:

* Store purchases
* Admin rewards
* Leaderboard rewards
* Events
* Special achievements

The plugin must maintain a collection of all ranks owned by a player.

A player may own multiple ranks but only one rank can be active at a time.

Example:

Owned Ranks:

APEX
SULTAN
TOPVOTER
PREDATOR

Current Active Rank:

APEX

Displayed In Chat:

[APEX] Nabil

When the player opens:

/titles

A INVENTORY GUI shows all owned ranks.

The player can click another owned rank.

Example:

Player clicks:

SULTAN

The plugin switches the active rank.

Displayed In Chat:

[SULTAN] Nabil

The previous rank must NOT be deleted.

The previous rank remains stored inside the player's rank collection.

Players may switch back at any time.

The plugin must function as a rank wardrobe system.

LEADERBOARD REWARDS

Leaderboard rewards are real LuckPerms groups.

Example:

Top Money -> SULTAN
Top Votes -> TOPVOTER
Top Kills -> PREDATOR

When a player becomes #1:

The reward rank is added to the player's owned rank collection.

If the player loses #1:

The reward rank is automatically removed from the collection unless configured otherwise.

The plugin must update the player's available ranks automatically.

RANK COLLECTION SYSTEM

The plugin stores:

Owned Ranks
Current Active Rank
Rank Source
Date Obtained

Example:

APEX -> STORE
SULTAN -> MONEY_LEADERBOARD
TOPVOTER -> VOTE_LEADERBOARD
IMMORTAL -> ADMIN

TITLES COMMAND

Command:

/titles

This command opens the rank selection INVENTORY GUI.

The command name remains /titles for user experience even though the plugin manages ranks rather than cosmetic titles.

RANK SWITCHING

When switching ranks:

The plugin must use the LuckPerms API.

Example:

Current:

APEX

Selected:

SULTAN

The plugin changes the player's active LuckPerms group to SULTAN.

The previous rank APEX remains stored in the player's collection.

Players can switch back at any time.

The plugin must never permanently delete owned ranks during switching.

LUCKPERMS INTEGRATION

Use LuckPerms API directly.

Never execute console commands.

Never use:

/lp user  parent set

through console execution.

Use proper LuckPerms API methods.

The plugin must:

* Detect rank changes made by administrators.
* Detect ranks granted through the store.
* Detect ranks granted through console.
* Automatically synchronize owned ranks.

Example:

Administrator executes:

/lp user Nabil parent set IMMORTAL

The plugin automatically updates:

Owned Ranks:

APEX
IMMORTAL
SULTAN

Current Active Rank:

IMMORTAL

RANK PROTECTION

Configurable protected ranks.

Example:

protected-ranks:

* owner
* admin
* developer

Protected ranks cannot be switched through the INVENTORY GUI.

RANK INVENTORY GUI

Command:

/titles

INVENTORY GUI displays:

Current Active Rank

Owned Ranks

Rank Source

Date Obtained

Rank Weight

Clicking an owned rank:

* Switches active rank.
* Updates LuckPerms.
* Saves to database.
* Refreshes placeholders.

PLACEHOLDERS

%leaderrank_current_rank%
%leaderrank_owned_ranks%
%leaderrank_rank_count%
%leaderrank_rank_source%
%leaderrank_active_rank%

Examples:

APEX

APEX,SULTAN,TOPVOTER

4
Kodari AI
KodariJun 24 at 3:59 pm 33
LeaderRank

InventoryHandler, InventoryButton, InventoryGUI, GUIManager, GUIListener5. GUI implementation:TitlesGUI6. Listeners:LuckPermsListener, PlayerListener7. Commands:T, PlayerData2. Database layer:DatabaseManager(SQLite) 3. Core logic:RankManager(LP API, cache, sync) 4. Inventory framework:

A rank wardrobe and collection system powered by LuckPerms. Players accumulate ranks from store purchases, admin grants, leaderboard rewards, and events — all stored in a persistent SQLite database. A /titles GUI lets players switch their active rank at any time without losing others. Detects external LP changes automatically. Includes PlaceholderAPI support, protected rank configuration, and a full admin command suite.

Plan:

  1. Data classes: OwnedRankitlesCommand, LeaderRankCommand

  2. Placeholders: LeaderRankExpansion

  3. Main plugin class + resources

Here’s a breakdown of what was built:

Architecture:

  • DatabaseManager — SQLite persistence with synchronized queries; stores owned ranks (name, source, date) and active rank per player

  • RankManager — core logic hub; manages in-memory cache, LP API calls, and distinguishes plugin-initiated LP changes from external ones via processingSwitch set

  • LuckPermsListener — hooks LP’s own event bus (not Bukkit) to catch /lp user X parent set Y and store-granted ranks automatically

  • PlayerListener — loads player data on join, syncs from LP groups if it’s their first time

Key behaviors:

  • Only the active rank exists as an LP group; all other owned ranks are DB-only → clean LP state

  • External LP changes (admin, store) auto-add to collection with source EXTERNAL and become the new active rank

  • Leaderboard ranks (configurable list) are auto-removed from collection when LP removes them; non-leaderboard ranks are never deleted from collection on LP remove

  • processingSwitch prevents our own LP mutations from re-triggering the sync logic

Placeholders: %leaderrank_current_rank%, %leaderrank_active_rank%, %leaderrank_owned_ranks%, %leaderrank_rank_count%, %leaderrank_rank_source%

Admin commands: /leaderrank add <player> <rank> [source], remove, info, reload

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
Code
19 1,252
src/main/java/com/leaderrank/LeaderRankPlugin.java
package com.leaderrank;

import com.leaderrank.commands.LeaderRankCommand;
import com.leaderrank.commands.TitlesCommand;
import com.leaderrank.inventory.gui.GUIListener;
import com.leaderrank.inventory.gui.GUIManager;
import com.leaderrank.listeners.LuckPermsListener;
import com.leaderrank.listeners.PlayerListener;
import com.leaderrank.managers.DatabaseManager;
import com.leaderrank.managers.RankManager;
import com.leaderrank.placeholders.LeaderRankExpansion;
import lombok.Getter;
import net.luckperms.api.LuckPerms;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.logging.Level;

@Getter
public class LeaderRankPlugin extends JavaPlugin {

    private LuckPerms luckPerms;
    private DatabaseManager databaseManager;
    private RankManager rankManager;
    private GUIManager guiManager;
    private LuckPermsListener luckPermsListener;

    @Override
    public void onEnable() {
        saveDefaultConfig();

        if (!setupLuckPerms()) {
            getLogger().severe("LuckPerms not found! Disabling LeaderRank.");
            getServer().getPluginManager().disablePlugin(this);
            return;
        }

        databaseManager = new DatabaseManager(this);
        databaseManager.init();

        rankManager = new RankManager(this, databaseManager, luckPerms);
        guiManager = new GUIManager();

        luckPermsListener = new LuckPermsListener(this, rankManager, luckPerms);

        getServer().getPluginManager().registerEvents(new PlayerListener(this), this);
        getServer().getPluginManager().registerEvents(new GUIListener(guiManager), this);

        getCommand("titles").setExecutor(new TitlesCommand(this));
        LeaderRankCommand adminCommand = new LeaderRankCommand(this);
        getCommand("leaderrank").setExecutor(adminCommand);
        getCommand("leaderrank").setTabCompleter(adminCommand);

        if (getServer().getPluginManager().getPlugin("PlaceholderAPI") != null) {
            new LeaderRankExpansion(this).register();
            getLogger().info("PlaceholderAPI hooked successfully.");
        }

        // Load online players (in case of reload)
        getServer().getOnlinePlayers().forEach(player ->
                getServer().getScheduler().runTaskAsynchronously(this, () ->
                        rankManager.loadPlayer(player.getUniqueId()))
        );

        getLogger().info("LeaderRank enabled successfully.");
    }

    @Override
    public void onDisable() {
        if (luckPermsListener != null) luckPermsListener.unsubscribe();
        if (databaseManager != null) databaseManager.close();
        getLogger().info("LeaderRank disabled.");
    }

    private boolean setupLuckPerms() {
        RegisteredServiceProvider<LuckPerms> provider =
                getServer().getServicesManager().getRegistration(LuckPerms.class);
        if (provider == null) return false;
        luckPerms = provider.getProvider();
        return true;
    }
}