mcMMO/src/main/java/com/gmail/nossr50/datatypes/skills/alchemy/PotionStage.java

87 lines
2.3 KiB
Java
Raw Normal View History

package com.gmail.nossr50.datatypes.skills.alchemy;
2016-03-12 04:07:27 +01:00
import org.bukkit.Material;
import org.bukkit.potion.PotionData;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionType;
import java.util.List;
public enum PotionStage {
FIVE(5),
FOUR(4),
THREE(3),
TWO(2),
ONE(1);
int numerical;
2020-07-13 20:39:03 +02:00
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);
2014-06-09 22:55:03 +02:00
if (!isWaterBottle(input) && getPotionStage(input) == potionStage) {
potionStage = PotionStage.FIVE;
}
return potionStage;
}
2014-06-09 22:55:03 +02:00
private static boolean isWaterBottle(AlchemyPotion input) {
return input.getData().getType() == PotionType.WATER;
2014-06-09 22:55:03 +02:00
}
public static PotionStage getPotionStage(AlchemyPotion alchemyPotion) {
2016-03-12 04:07:27 +01:00
PotionData data = alchemyPotion.getData();
List<PotionEffect> effects = alchemyPotion.getEffects();
int stage = 1;
2016-03-16 06:39:23 +01:00
// Check if potion has an effect of any sort
if (data.getType().getEffectType() != 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
2016-03-12 04:07:27 +01:00
if (data.isUpgraded()) {
stage++;
2016-03-16 06:39:23 +01:00
} else if(!effects.isEmpty()) {
for (PotionEffect effect : effects){
if(effect.getAmplifier() > 0){
stage++;
break;
}
}
}
// Check if potion has a redstone dust amplifier
2016-03-12 04:07:27 +01:00
if (data.isExtended()) {
stage++;
}
// Check if potion has a gunpowder amplifier
2016-03-12 04:07:27 +01:00
if (alchemyPotion.getMaterial() == Material.SPLASH_POTION || alchemyPotion.getMaterial() == Material.LINGERING_POTION) {
stage++;
}
return PotionStage.getPotionStageNumerical(stage);
}
}