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

import java.util.List;

import org.bukkit.potion.Potion;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionType;

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.getData().getType() == PotionType.WATER;
    }

    public static PotionStage getPotionStage(AlchemyPotion alchemyPotion) {
        Potion potion = alchemyPotion.toPotion(1);
        List<PotionEffect> effects = alchemyPotion.getEffects();

        int stage = 1;

        // Check if potion isn't awkward or mundane
        // Check for custom effects added by mcMMO
        if (potion.getType() != null || !effects.isEmpty()) {
            stage++;
        }

        // Check if potion has a glowstone dust amplifier
        // Else check if the potion has a custom effect with an amplifier added by mcMMO 
        if (potion.getLevel() > 1) {
            stage++;
        }else if(!effects.isEmpty()){
            for (PotionEffect effect : effects){
                if(effect.getAmplifier() > 0){
                    stage++;
                    break;
                }
            }
        }

        // 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);
    }
}

@@ -88,29 +88,94 @@
 .bukkit.
-potion.Potion
+Material;%0Aimport org.bukkit.potion.Potion;%0Aimport org.bukkit.potion.PotionData
 ;%0Aimport
@@ -1311,23 +1311,25 @@
   Potion
- potion
+Data data
  = alche
@@ -1341,18 +1341,16 @@
 ion.
-toPotion(1
+getData(
 );%0A 
@@ -1469,83 +1469,23 @@
 ion 
-isn't awkward or mundane%0A        // Check for custom effects added by mcMMO
+has base effect
 %0A   
@@ -1489,30 +1489,28 @@
         if (
-potion
+data
 .getType() !
@@ -1511,38 +1511,32 @@
 pe()
- != null %7C%7C !effects.isEmpty()
+.getEffectType() != null
 ) %7B%0A
@@ -1731,29 +1731,25 @@
 if (
-potion.getLevel() %3E 1
+data.isUpgraded()
 ) %7B%0A
@@ -1782,12 +1782,16 @@
    %7D
-else
+%0A       
  if(
@@ -2079,17 +2079,14 @@
 if (
-potion.ha
+data.i
 sExt
@@ -2094,16 +2094,8 @@
 nded
-Duration
 ()) 
@@ -2197,25 +2197,121 @@
 if (
-potion.isSplash()
+alchemyPotion.getMaterial() == Material.SPLASH_POTION %7C%7C alchemyPotion.getMaterial() == Material.LINGERING_POTION
 ) %7B%0A

Properly calculate potionstage