Skip to content

K | Utility: ManaUtils

Sartaj Singh edited this page May 29, 2025 · 6 revisions

Utility: ManaUtils

ManaUtils provides a full system for player mana, including spending, setting, checking, and displaying mana values.


1. initialize(Plugin plugin)

What it does:
Sets up the mana system. Must be called once in your plugin's onEnable().

Example:

ManaUtils.initialize(this);

2. useMana(Player player, int amount): boolean

What it does:
Attempts to spend the specified amount of mana. Returns false if not enough mana.

Example:

if (!ManaUtils.useMana(player, 10)) {
    player.sendMessage("Not enough mana!");
    return;
}

3. setMana(Player player, int amount)

What it does:
Sets the player's current mana to the given amount.

Example:

ManaUtils.setMana(player, 100);

4. getMana(Player player): int

What it does:
Returns the player's current mana.

Example:

int mana = ManaUtils.getMana(player);

5. addMana(Player player, int amount)

What it does:
Adds the given amount to the player's mana.

Example:

ManaUtils.addMana(player, 5);

6. getMaxMana(Player player): int

What it does:
Returns the player's maximum mana.

Example:

int maxMana = ManaUtils.getMaxMana(player);

7. showManaBar(Player player)

What it does:
Displays or updates a mana bar for the player.

Example:

ManaUtils.showManaBar(player);

Usage Patterns

  • Always call initialize at startup.
  • Use useMana in abilities to consume mana.
  • Use showManaBar after changing mana for instant feedback.
  • Adjust getMaxMana if you want dynamic maximums (e.g., leveling).

Clone this wiki locally