Skip to content

I | Utility: CustomItemUtils

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

I | Utility: CustomItemUtils

CustomItemUtils helps you identify and work with your special items by material and display name.


1. isCustomItem(ItemStack stack, Material material, String displayName): boolean

What it does:
Checks if the ItemStack is both the correct material and has the specified display name.

Example:

if (CustomItemUtils.isCustomItem(item, Material.BLAZE_ROD, "§dMagic Wand")) {
    // This is the Magic Wand
}

2. getCustomItem(Player player, Material material, String displayName): ItemStack

What it does:
Searches a player's inventory for a custom item matching the material/display name.

Example:

ItemStack wand = CustomItemUtils.getCustomItem(player, Material.BLAZE_ROD, "§dMagic Wand");
if (wand != null) {
    // Player has the custom wand
}

Usage Patterns

  • Always use isCustomItem() before running custom behavior for your items.
  • Use getCustomItem() for inventory checks, e.g., quest logic.

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