Solved Getting potion from brew event

Discussion in 'Spigot Plugin Development' started by ThatBenderGuy, Jun 28, 2018.

  1. I am trying to get the type of potion the player has brewed and I don't know how to go about it. (I am using BlockLockerAPI to get the owner of the brew stand)

    Code (Java):
        public void brewEvent(BrewEvent e) {
            Player p = Bukkit.getPlayer(BlockLockerAPI.getOwner(e.getBlock()).get().getUniqueId());
            if(p != null) {
                // I already know that contents 0-2 are the potions in the bottom of the brew stand
                ItemStack potion1 = e.getContents().getItem(0);
                ItemStack potion2 = e.getContents().getItem(1);
                ItemStack potion3 = e.getContents().getItem(2);
    How would I go about getting the potion's type from here?
    Would it be through ItemStack#getItemMeta? If so how would I get the potion effect through its meta?
  2. This should work.
    Code (Java):

    ItemStack stack = //... your stack
    Collection<PotionEffect> fx = Potion.fromItemStack(stack).getEffects();
  3. The entirety of the Potion class is deprecated, is it okay to use it still?
  4. You can try the PotionMeta.
    Code (Java):

    PotionMeta meta = (PotionMeta) itemstack.getItemMeta();
    • Agree Agree x 1
  5. Thanks! That works.