001    package org.bukkit.potion;
002    
003    public enum PotionType {
004        WATER(0, null, 0),
005        REGEN(1, PotionEffectType.REGENERATION, 2),
006        SPEED(2, PotionEffectType.SPEED, 2),
007        FIRE_RESISTANCE(3, PotionEffectType.FIRE_RESISTANCE, 1),
008        POISON(4, PotionEffectType.POISON, 2),
009        INSTANT_HEAL(5, PotionEffectType.HEAL, 2),
010        NIGHT_VISION(6, PotionEffectType.NIGHT_VISION, 1),
011        WEAKNESS(8, PotionEffectType.WEAKNESS, 1),
012        STRENGTH(9, PotionEffectType.INCREASE_DAMAGE, 2),
013        SLOWNESS(10, PotionEffectType.SLOW, 1),
014        INSTANT_DAMAGE(12, PotionEffectType.HARM, 2),
015        WATER_BREATHING(13, PotionEffectType.WATER_BREATHING, 1),
016        INVISIBILITY(14, PotionEffectType.INVISIBILITY, 1),
017        ;
018    
019        private final int damageValue, maxLevel;
020        private final PotionEffectType effect;
021    
022        PotionType(int damageValue, PotionEffectType effect, int maxLevel) {
023            this.damageValue = damageValue;
024            this.effect = effect;
025            this.maxLevel = maxLevel;
026        }
027    
028        public PotionEffectType getEffectType() {
029            return effect;
030        }
031    
032        /**
033         *
034         * @deprecated Magic value
035         */
036        @Deprecated
037        public int getDamageValue() {
038            return damageValue;
039        }
040    
041        public int getMaxLevel() {
042            return maxLevel;
043        }
044    
045        public boolean isInstant() {
046            return effect == null ? true : effect.isInstant();
047        }
048    
049        /**
050         *
051         * @deprecated Magic value
052         */
053        @Deprecated
054        public static PotionType getByDamageValue(int damage) {
055            for (PotionType type : PotionType.values()) {
056                if (type.damageValue == damage)
057                    return type;
058            }
059            return null;
060        }
061    
062        public static PotionType getByEffect(PotionEffectType effectType) {
063            if (effectType == null)
064                return WATER;
065            for (PotionType type : PotionType.values()) {
066                if (effectType.equals(type.effect))
067                    return type;
068            }
069            return null;
070        }
071    }