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.
importme.fergs.phantomdungeons.modules.sword.api.SwordAPI;// Get the singleton instanceSwordAPIswordAPI=SwordAPI.get();
Add depend: [PhantomDungeons] to your plugin.yml to ensure proper load order.
Step 2: Cache for Performance
Store it in your main plugin class.
publicclassMyPluginextendsJavaPlugin{privateSwordAPI swordAPI;@OverridepublicvoidonEnable(){try{this.swordAPI=SwordAPI.get();}catch(IllegalStateExceptione){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.
Each sword has a unique UUID that maintains its identity even if dropped, stored, or traded.
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.
Always check if the returned sword is null - this indicates the upgrade failed (e.g., insufficient funds).
Enchantment Integration
Checking for Enchants
Query enchantment data from swords.
Managing Enchants
Add, update, or remove enchantments.
Frequently Asked Questions
Can I create custom sword progression orders?
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.
Are swords persistent across server restarts?
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.
Can players have multiple dungeon swords?
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.
What happens if sword configurations change?
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.