> For the complete documentation index, see [llms.txt](https://docs.mantic.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.mantic.dev/manticswords/developer-api.md).

# Developer API

This page documents the ManticSwords developer API.

`ManticSwordsAPI` is the static entry point for integrations. The plugin also exposes `SwordUseEvent` and the `EconomyProvider` interface.

## Add the API to your build

The API is published to our Maven repository, so there is nothing to install locally.

```xml
<repositories>
  <repository>
    <id>mantic</id>
    <url>https://repo.mantic.dev/public</url>
  </repository>
</repositories>

<dependency>
  <groupId>me.fullpage</groupId>
  <artifactId>manticswords-api</artifactId>
  <version>2.0</version>
  <scope>provided</scope>
</dependency>
```

Gradle:

```kotlin
repositories {
    maven("https://repo.mantic.dev/public") {
        content { includeGroup("me.fullpage") }
    }
}

dependencies {
    compileOnly("me.fullpage:manticswords-api:2.0")
}
```

The JAR keeps class and member signatures while replacing method bodies with empty stubs. It is for compilation only; never put it on the server or bundle it in another plugin. Published versions are browsable at <https://repo.mantic.dev/\\_browse/public>.

Declare ManticSwords as a server dependency in your plugin's `plugin.yml`:

```yaml
depend: [ManticSwords]
```

## Common calls

```java
import me.fullpage.manticsword.api.ManticSwordsAPI;
import me.fullpage.manticsword.data.Enchants;
import me.fullpage.manticsword.enchants.Enchant;
import me.fullpage.manticsword.wrappers.MPlayer;
import me.fullpage.manticsword.wrappers.MobSword;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;

public final class SwordsIntegration {
    public void commonCalls(Player player) {
        MPlayer data = ManticSwordsAPI.getPlayer(player); // also accepts OfflinePlayer, UUID, UUID string, or online name
        if (data != null) {
            double crystals = data.getAccurateCrystals();
            data.addCrystals(25.0);
        }

        MobSword heldSword = ManticSwordsAPI.getSword(player);
        Enchant enchant = Enchants.get().getEnchant("crystal_finder");
        if (heldSword.isValid() && enchant != null) {
            int level = heldSword.getLevel(enchant);
        }

        MobSword newSword = ManticSwordsAPI.getSword("default", player);
        if (newSword != null && newSword.isValid()) {
            ItemStack swordItem = newSword.getItemStack();
            // Add swordItem to an inventory or use it in your integration.
        }
    }
}
```

`getPlayer` resolves UUIDs, UUID strings, `Player`/`OfflinePlayer` objects, and online player names; it returns `null` when it cannot resolve the input. `getSword("default", player)` returns `null` if that sword type is not configured. The item-based helpers return a wrapper even when the item is not a ManticSwords sword; check `isValid()` before calling sword-specific methods. `getSwordSettings()` returns a read-only list.

`getPlayers()` returns tracked records as a read-only collection. `getSwordSetting(type)` looks up one configured sword. `getFirstJoinSword(player)` returns an optional item, and `isLucky` and `parsePlaceholderApi` expose the matching plugin helpers.

## Currency, selling, and events

`MPlayer` provides crystal methods such as `getAccurateCrystals`, `addCrystals`, `takeCrystals`, and `hasEnoughCrystals`. Prefer `getAccurateCrystals()` when fractional balances matter; `getCrystals()` is deprecated and returns a whole-number balance. `getCrystalCurrencyProvider()` can return `null` when `economy-provider` is `ManticSwords`, which uses ManticSwords' own saved balances. `getMoneyCurrencyProvider()` returns the configured money provider. `ManticSwordsAPI.giveMoney` pays through it; `getSellPrice` exposes the plugin's configured sell price.

Listen for `SwordUseEvent` to inspect or modify loot, crystals, XP, and money when a sword is used. Register listeners with Bukkit's `PluginManager`.

Implement `EconomyProvider` and register it with `ManticSwordsAPI.registerEconomyProvider` to provide the plugin's optional external economy integration. The registered provider is separate from the configured crystal and money providers.

## Additional helpers and events

`ManticSwordsAPI` also provides enchant lookup (`getEnchant`, `getEnchants`), activity lookup and counters (`getKilled`, `getTotalKilled`, `addKilled`), and direct crystal operations (`getCrystals`, `setCrystals`, `addCrystals`, `takeCrystals`, `hasEnoughCrystals`, `payCrystals`). Balance operations honor the active provider. Amounts must be finite and non-negative; activity additions also require a non-negative count.

Money helpers include `getMoney`, `giveMoney`, `takeMoney`, `setMoney` and `hasEnoughMoney`. `getPlayer` accepts players, offline players, UUIDs, names and plugin player wrappers; before player data is loaded it returns `null`, and `getPlayers` and `getEnchants` return empty collections.

Events are in `me.fullpage.manticsword.api.events`:

* `SwordPreUseEvent` — cancellable before any tool processing. Its `Stage` distinguishes `ATTACK` (before damage is applied) from `REWARDS` (before mob-kill reward processing).
* `SwordUseEvent` — the existing reward event, now cancellable before loot, currency, XP and the tracked activity are applied. Enchant commands and effects have already run by that point, so use the pre-use event to prevent those.
* `EnchantUpgradeEvent` — cancellable before charging for an upgrade; its cost can be changed to a finite, non-negative value.
* `PreDisenchantEvent` — cancellable; exposes the removed level's base cost and refund percentage range.
* `DisenchantEvent` — cancellable before the level is removed and the refund paid; exposes the actual refund. Cancelling leaves the item and balance unchanged.
* `CrystalsGiveFromMobEvent` — carries crystal rewards from mob kills. It extends the older `CrystalsGiveFromHarvestEvent`, which is deprecated but still delivered to existing listeners.

Cancelling `SwordPreUseEvent` at the `REWARDS` stage prevents Mantic rewards but does not undo a mob death. Listener changes to disenchant levels stay below the old level and above the configured base level; refunds stay finite and non-negative.

Enchant configuration uses YAML, matching the existing YAML drop configuration. Static APIs and the enchant `reload`, `register` and `save` entry points remain available. Legacy configuration migration keeps a verified backup in `old-files/`; saved player data keeps its existing format.
