rectangle-terminalLevelling API

Overview

The Leveling API provides a clean interface for external plugins to interact with PhantomDungeons infinitely configurable leveling system. Manage player levels, check progression status, and trigger level-up rewards without worrying about database operations.


Getting Started

Follow these steps to integrate with the leveling system.

1

Get the Instance

In your plugin's onEnable, grab the API instance.

import me.fergs.phantomdungeons.modules.level.api.LevelingAPI;

// Get the singleton instance
LevelingAPI levelingAPI = LevelingAPI.get();
circle-exclamation
2

Cache for Performance

Store it in your main plugin class.

public class MyPlugin extends JavaPlugin {
    private LevelingAPI levelingAPI;
    
    @Override
    public void onEnable() {
        try {
            this.levelingAPI = LevelingAPI.get();
        } catch (IllegalStateException e) {
            getLogger().warning("PhantomDungeons not loaded!");
        }
    }
}
3

Safe Null Checks

Always check availability before using.

if (levelingAPI == null) {
    getLogger().warning("Leveling API not available!");
    return;
}

Core Operations

Checking Levels

Reading levels is synchronous and instant (cached in memory).

// Get player's level in a progression
int swordLevel = levelingAPI.getLevel(player, "sword-level");
player.sendMessage("§7Sword Level: §a" + swordLevel);

// Check if at max level
if (levelingAPI.isMaxLevel(player, "sword-level")) {
    player.sendMessage("§6Max level reached!");
}

// Check if can level up further
if (levelingAPI.canLevelUp(player, "sword-level")) {
    player.sendMessage("§aYou can level up!");
}

Adding & Removing Levels

Use async operations to modify levels.

Progression Metadata

Query progression information.


Advanced Features

Progress Bars

Generate nice progress bar strings.

Reset Levels

Reset player progression (useful for prestige systems).

Get All Levels

Retrieve all progression levels for a player.

Level Requirements

Get cost for next level.


Events API

Listen for level-up events in your plugin.


FAQ

chevron-rightCan I have unlimited progressions?hashtag

Yes! Add as many .yml files in the levels/ folder as you want.

chevron-rightDoes it work offline?hashtag

Yes! Use UUID instead of Player for offline players.

chevron-rightAre level changes async?hashtag

Yes. All modifications return CompletableFuture.

chevron-rightCan progressions have no level cap?hashtag

Yes. Set max-level: 0 in the config for unlimited levels.

chevron-rightWhat happens on server restart?hashtag

Levels are persisted in the database and restored on startup in memory cache.

chevron-rightCan I check if progression exists?hashtag

Yes. Use progressionExists(progressionId) first.


Last updated