rockyhawk64 / CommandPanels

Command Panels main Github page. Wiki Page Below:
https://commandpanels.net/home
GNU General Public License v3.0
94 stars 25 forks source link

Potion autofill from cpg #283

Closed TinyTank800 closed 9 months ago

TinyTank800 commented 10 months ago

Terms

Is your feature request related to a problem? Please describe.

Auto full potion: when /cpg is executed

Describe the solution you'd like

To get the potion type from an ItemStack in Spigot and Paper, you can use the following code snippet in Java:

import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.potion.PotionData;
import org.bukkit.potion.PotionType;

public class PotionExample {

    public PotionType getPotionTypeFromItemStack(ItemStack itemStack) {
        if (itemStack != null && itemStack.getType() == Material.POTION) {
            if (itemStack.hasItemMeta() && itemStack.getItemMeta() instanceof PotionMeta) {
                PotionMeta potionMeta = (PotionMeta) itemStack.getItemMeta();
                PotionData potionData = potionMeta.getBasePotionData();
                return potionData.getType();
            }
        }
        return null; // Return null if the ItemStack is not a potion or doesn't have potion meta
    }

    // Example usage
    public static void main(String[] args) {
        ItemStack potionItemStack = new ItemStack(Material.POTION); // Replace this with your actual ItemStack
        PotionExample potionExample = new PotionExample();
        PotionType potionType = potionExample.getPotionTypeFromItemStack(potionItemStack);
        System.out.println("Potion Type: " + potionType);
    }
}

This code checks if the ItemStack is a potion, has item meta, and if the item meta is an instance of PotionMeta. It then retrieves the base potion data and gets the potion type from it. The getPotionTypeFromItemStack method returns the PotionType or null if the conditions are not met.

Make sure to replace potionItemStack with your actual ItemStack.

Snippet from chat gpt. Will be trying to add later but placing here to remember or if someone else on the team wants to take a stab at it.

Describe alternatives you've considered

None

Screenshots/Videos (you can drag and drop files or paste links)

No response

TinyTank800 commented 9 months ago

added in pull request https://github.com/rockyhawk64/CommandPanels/pull/286