diff --git a/src/me/rockyhawk/commandpanels/classresources/placeholders/Placeholders.java b/src/me/rockyhawk/commandpanels/classresources/placeholders/Placeholders.java index 4da5498..fa13061 100644 --- a/src/me/rockyhawk/commandpanels/classresources/placeholders/Placeholders.java +++ b/src/me/rockyhawk/commandpanels/classresources/placeholders/Placeholders.java @@ -11,6 +11,8 @@ import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.Damageable; +import org.bukkit.inventory.meta.PotionMeta; +import org.bukkit.potion.PotionEffect; import java.io.IOException; import java.net.InetSocketAddress; @@ -155,6 +157,30 @@ public class Placeholders { } } + // Placeholder to check if an item has POTION data %cp-potion-slot% + if (identifier.startsWith("potion-")) { + try { + String slot_key = identifier.replace("potion-", ""); + int slotIndex = (int) Double.parseDouble(slot_key); + + // Get the item in the specified slot + ItemStack item = p.getOpenInventory().getTopInventory().getItem(slotIndex); + + // Check if the item is not null and has potion meta + if (item != null && item.hasItemMeta() && item.getItemMeta() instanceof PotionMeta) { + PotionMeta potionMeta = (PotionMeta) item.getItemMeta(); + + //Returns the value like this :: Example SLOWNESS:true:false + return potionMeta.getBasePotionData().getType() + ":" + potionMeta.getBasePotionData().isExtended() + ":" + potionMeta.getBasePotionData().isUpgraded(); + } else { + return "empty"; // Item is either null or doesn't have potion meta + } + } catch (Exception ex) { + plugin.debug(ex, p); + return ""; // Handle exceptions as needed + } + } + //DO placeholders for detection of other items in a panel //get material value from slot in current open inventory (panel) if(identifier.startsWith("material-")) {