Skip to content

J | Utility: EffectUtils

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

I | Utility: EffectUtils

EffectUtils lets you add or manage potion effects as long as a player is holding a specific item.


1. addEffectWhileHolding(Player player, Material itemMaterial, PotionEffectType effect, int duration, int amplifier)

What it does:
Applies a potion effect as long as the player is holding the specified item. Effect is refreshed automatically.

Example:

EffectUtils.addEffectWhileHolding(player, Material.BLAZE_ROD, PotionEffectType.FIRE_RESISTANCE, 200, 1);

Player will have Fire Resistance II as long as they hold the blaze rod.


2. removeEffectTask(Player player)

What it does:
Removes any "while holding" effect from this player.

Example:

EffectUtils.removeEffectTask(player);

3. hasEffectTask(Player player): boolean

What it does:
Returns true if a "while holding" effect task is currently active for the player.

Example:

if (EffectUtils.hasEffectTask(player)) {
    // Player has a persistent effect task running
}

Usage Patterns

  • Grant passive buffs to players holding legendary items.
  • Always remove effect tasks on logout, death, or item loss to avoid memory leaks.

Clone this wiki locally