package com.gmail.nossr50.datatypes.skills.alchemy;

import org.bukkit.potion.Potion;

public enum PotionStage {
    FIVE(5),
    FOUR(4),
    THREE(3),
    TWO(2),
    ONE(1);

    int numerical;

    private PotionStage(int numerical) {
        this.numerical = numerical;
    }

    public int toNumerical() {
        return numerical;
    }

    private static PotionStage getPotionStageNumerical(int numerical) {
        for (PotionStage potionStage : values()) {
            if (numerical >= potionStage.toNumerical()) {
                return potionStage;
            }
        }

        return ONE;
    }

    public static PotionStage getPotionStage(AlchemyPotion input, AlchemyPotion output) {
        PotionStage potionStage = getPotionStage(output);
        if (!isWaterBottle(input) && getPotionStage(input) == potionStage) {
            potionStage = PotionStage.FIVE;
        }

        return potionStage;
    }

    private static boolean isWaterBottle(AlchemyPotion input) {
        return input.getDataValue() == 0;
    }

    public static PotionStage getPotionStage(AlchemyPotion alchemyPotion) {
        Potion potion = alchemyPotion.toPotion(1);

        int stage = 1;

        // Check if potion isn't awkward or mundane
        if (potion.getType() != null) {
            stage++;
        }

        // Check if potion has a glowstone dust amplifier
        if (potion.getLevel() > 1) {
            stage++;
        }

        // Check if potion has a redstone dust amplifier
        if (potion.hasExtendedDuration()) {
            stage++;
        }

        // Check if potion has a gunpowder amplifier
        if (potion.isSplash()) {
            stage++;
        }

        return PotionStage.getPotionStageNumerical(stage);
    }
}

@@ -57,32 +57,95 @@
 ort 
-org.bukkit.potion.Potion
+java.util.List;%0A%0Aimport org.bukkit.potion.Potion;%0Aimport org.bukkit.potion.PotionEffect
 ;%0A%0Ap
@@ -1221,24 +1221,89 @@
 toPotion(1);
+%0A        List%3CPotionEffect%3E effects = alchemyPotion.getEffects();
 %0A%0A        in
@@ -1368,16 +1368,67 @@
 mundane%0A
+        // Check for custom effects added by mcMMO%0A
         
@@ -1455,16 +1455,38 @@
  != null
+ %7C%7C !effects.isEmpty()
 ) %7B%0A    
@@ -1583,57 +1583,369 @@
     
-if (potion.getLevel() %3E 1) %7B%0A            stage++;
+// Else check if the potion has a custom effect with an amplifier added by mcMMO %0A        if (potion.getLevel() %3E 1) %7B%0A            stage++;%0A        %7Delse if(!effects.isEmpty())%7B%0A            for (PotionEffect effect : effects)%7B%0A                if(effect.getAmplifier() %3E 0)%7B%0A                    stage++;%0A                    break;%0A                %7D%0A            %7D
 %0A   

Fix for custom potions being missed in potion stage calculation. #2386