Skip to content

J | Utility: EffectUtils

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

J | Utility: EffectUtils


Table of Contents


1. Overview

EffectUtils is a utility class in FXItems for working with potion effects (status effects) in Minecraft.
It provides a simple and consistent API for adding, removing, and checking potion effects on players or entities, especially in the context of custom item and food logic.


2. What is EffectUtils?

  • Purpose: Makes it easy to manage Bukkit potion effects in your item, food, or ability code.
  • Scope: Only deals with potion effects.
    (Does not handle particles, sounds, titles, or action bars—see other utilities for that.)
  • Usage: Designed for use in FXItemBehavior, FXFoodBehavior, and event listeners.

3. Basic Usage

Give a potion effect

EffectUtils.addPotionEffect(player, PotionEffectType.SPEED, 200, 1); // Speed II for 10 seconds (200 ticks)

Remove a potion effect

EffectUtils.removePotionEffect(player, PotionEffectType.SPEED);

Check if a player has a potion effect

if (EffectUtils.hasPotionEffect(player, PotionEffectType.REGENERATION)) {
    // Player has regeneration
}

4. API Reference

// Adds a potion effect to a player or entity
void EffectUtils.addPotionEffect(LivingEntity entity, PotionEffectType effectType, int durationTicks, int amplifier);

// Removes a specific potion effect
void EffectUtils.removePotionEffect(LivingEntity entity, PotionEffectType effectType);

// Checks if an entity has a specific potion effect
boolean EffectUtils.hasPotionEffect(LivingEntity entity, PotionEffectType effectType);
  • entity: The player or mob to affect.
  • effectType: The type of effect (e.g., PotionEffectType.SPEED).
  • durationTicks: How long the effect lasts (20 ticks = 1 second).
  • amplifier: Level (0 = I, 1 = II, etc).

5. Advanced Patterns

  • Re-applying effects:
    If you call addPotionEffect again with the same type, it will overwrite the previous effect.
  • Stacking with other effects:
    You can apply multiple different effects at once.
  • Temporary buffs:
    Use in conjunction with CooldownUtils or ManaUtils to limit ability usage.

6. Limitations & Troubleshooting

  • Does not persist over logout:
    Potion effects wear off with time or on disconnect.
  • Not for visual/audio feedback:
    Use other utility classes for particles, sounds, titles, etc.
  • Effect conflicts:
    Applying the same effect twice will overwrite, not stack.

7. See Also


Clone this wiki locally