swordSword API

Overview

The Sword API provides a clean interface for external plugins to interact with PhantomDungeons dungeon sword system. Create custom swords, manage tiers, handle upgrades, and integrate with the combat system seamlessly.

Getting Started

Step 1: Get the API Instance

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

import me.fergs.phantomdungeons.modules.sword.api.SwordAPI;

// Get the singleton instance
SwordAPI swordAPI = SwordAPI.get();
circle-exclamation

Step 2: Cache for Performance

Store it in your main plugin class.

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

Step 3: Safe Null Checks

Always check availability before using.

Core Operations

Creating Swords

Generate new dungeon swords for players.

circle-check

Finding Player Swords

Locate a player's dungeon sword in their inventory.

Reading Sword Data

Extract information from sword ItemStacks.

Sword Upgrades

Validating Upgrades

Check if a sword can be upgraded before attempting.

Performing Upgrades

Upgrade swords asynchronously (handles economy deduction automatically).

triangle-exclamation

Enchantment Integration

Checking for Enchants

Query enchantment data from swords.

Managing Enchants

Add, update, or remove enchantments.

Frequently Asked Questions

chevron-rightCan I create custom sword progression orders?hashtag

Yes. Define custom swords in the swords/ directory and set the progression order in sword.yml under settings.sword-order. The order determines which sword comes next when a player maxes out their current sword.

chevron-rightAre swords persistent across server restarts?hashtag

Yes. Swords use NBT data that persists across server restarts. Each sword has a unique UUID that maintains its identity even if the player dies, drops it, or stores it in a chest.

chevron-rightCan players have multiple dungeon swords?hashtag

Players should only have one dungeon sword at a time. The findPlayerSword() method locates their active sword in inventory. If you give a player a new sword, it's recommended to remove their old one first to avoid confusion.

chevron-rightWhat happens if sword configurations change?hashtag

Use refreshSword() to update existing swords with new display data after config changes. This updates the lore, name, and visual properties without changing the tier or progression state.

ItemStack sword = swordAPI.findPlayerSword(player);ItemStack updated = swordAPI.refreshSword(player, sword);player.getInventory().setItemInMainHand(updated);

chevron-rightCan I customize the damage formula per tier?hashtag

Yes! Each tier in a sword configuration can have its own damage value. You can use linear scaling, exponential growth, or custom values per tier:

tiers: 1: damage: 10.0 2: damage: 15.0 # +5 3: damage: 25.0 # +10 (exponential)

chevron-rightHow do I integrate custom currencies?hashtag

Configure the currency field in the upgrade cost section:

upgrade-cost: currency: souls # Uses PhantomDungeons economy amount: 1000

As long as the currency is registered in the PhantomDungeons economy system (economies/ folder), it will work automatically!


sack-dollarEconomy APIchevron-rightbottle-waterBoosters APIchevron-rightcodepenEnchants APIchevron-rightrectangle-terminalLevelling APIchevron-rightswordSword APIchevron-right

Last updated