Step 1 of rewriting Alchemy - Removing all the old code

This commit is contained in:
nossr50
2019-05-12 00:53:15 -07:00
parent ddb92af400
commit 1c6b0363ce
26 changed files with 1856 additions and 1897 deletions

View File

@ -1,17 +1,5 @@
package com.gmail.nossr50.skills.alchemy;
import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.datatypes.skills.SubSkillType;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.runnables.skills.AlchemyBrewTask;
import com.gmail.nossr50.util.skills.RankUtils;
import org.bukkit.Location;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public final class Alchemy {
/*public enum Tier {
EIGHT(8),
@ -47,30 +35,30 @@ public final class Alchemy {
}
}*/
public static final int INGREDIENT_SLOT = 3;
public static int catalysisUnlockLevel = RankUtils.getUnlockLevel(SubSkillType.ALCHEMY_CATALYSIS);
public static int catalysisMaxBonusLevel = AdvancedConfig.getInstance().getCatalysisMaxBonusLevel();
public static double catalysisMinSpeed = AdvancedConfig.getInstance().getCatalysisMinSpeed();
public static double catalysisMaxSpeed = AdvancedConfig.getInstance().getCatalysisMaxSpeed();
public static Map<Location, AlchemyBrewTask> brewingStandMap = new HashMap<>();
private Alchemy() {
}
/**
* Finish all active brews. Used upon Disable to prevent vanilla potions from being brewed upon next Enable.
*/
public static void finishAllBrews() {
mcMMO.p.debug("Completing " + brewingStandMap.size() + " unfinished Alchemy brews.");
List<AlchemyBrewTask> toFinish = new ArrayList<>();
toFinish.addAll(brewingStandMap.values());
for (AlchemyBrewTask alchemyBrewTask : toFinish) {
alchemyBrewTask.finishImmediately();
}
}
// public static final int INGREDIENT_SLOT = 3;
//
// public static int catalysisUnlockLevel = RankUtils.getUnlockLevel(SubSkillType.ALCHEMY_CATALYSIS);
// public static int catalysisMaxBonusLevel = AdvancedConfig.getInstance().getCatalysisMaxBonusLevel();
// public static double catalysisMinSpeed = AdvancedConfig.getInstance().getCatalysisMinSpeed();
// public static double catalysisMaxSpeed = AdvancedConfig.getInstance().getCatalysisMaxSpeed();
//
// public static Map<Location, AlchemyBrewTask> brewingStandMap = new HashMap<>();
//
// private Alchemy() {
// }
//
// /**
// * Finish all active brews. Used upon Disable to prevent vanilla potions from being brewed upon next Enable.
// */
// public static void finishAllBrews() {
// mcMMO.p.debug("Completing " + brewingStandMap.size() + " unfinished Alchemy brews.");
//
// List<AlchemyBrewTask> toFinish = new ArrayList<>();
//
// toFinish.addAll(brewingStandMap.values());
//
// for (AlchemyBrewTask alchemyBrewTask : toFinish) {
// alchemyBrewTask.finishImmediately();
// }
// }
}

View File

@ -1,19 +1,8 @@
package com.gmail.nossr50.skills.alchemy;
import com.gmail.nossr50.config.skills.alchemy.PotionManager;
import com.gmail.nossr50.datatypes.experience.XPGainReason;
import com.gmail.nossr50.datatypes.experience.XPGainSource;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.datatypes.skills.SubSkillType;
import com.gmail.nossr50.datatypes.skills.alchemy.PotionStage;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.skills.SkillManager;
import com.gmail.nossr50.util.StringUtils;
import com.gmail.nossr50.util.skills.RankUtils;
import org.bukkit.inventory.ItemStack;
import java.util.List;
public class AlchemyManager extends SkillManager {
@ -21,39 +10,40 @@ public class AlchemyManager extends SkillManager {
super(mcMMOPlayer, PrimarySkillType.ALCHEMY);
}
public int getTier() {
return RankUtils.getRank(getPlayer(), SubSkillType.ALCHEMY_CONCOCTIONS);
}
public List<ItemStack> getIngredients() {
return PotionManager.getInstance().getIngredients(getTier());
}
public String getIngredientList() {
StringBuilder list = new StringBuilder();
for (ItemStack ingredient : getIngredients()) {
String string = StringUtils.getPrettyItemString(ingredient.getType());
list.append(", ").append(string);
}
return list.substring(2);
}
public double calculateBrewSpeed(boolean isLucky) {
int skillLevel = getSkillLevel();
if (skillLevel < Alchemy.catalysisUnlockLevel) {
return Alchemy.catalysisMinSpeed;
}
double LUCKY_MODIFIER = 4.0 / 3.0;
return Math.min(Alchemy.catalysisMaxSpeed, Alchemy.catalysisMinSpeed + (Alchemy.catalysisMaxSpeed - Alchemy.catalysisMinSpeed) * (skillLevel - Alchemy.catalysisUnlockLevel) / (Alchemy.catalysisMaxBonusLevel - Alchemy.catalysisUnlockLevel)) * (isLucky ? LUCKY_MODIFIER : 1.0);
}
public void handlePotionBrewSuccesses(PotionStage potionStage, int amount) {
//TODO: This code disturbs me
applyXpGain((float) (mcMMO.getConfigManager().getConfigExperience().getExperienceAlchemy().getPotionXPByStage(potionStage.toNumerical()) * amount), XPGainReason.PVE, XPGainSource.PASSIVE);
}
//
// public int getTier() {
// return RankUtils.getRank(getPlayer(), SubSkillType.ALCHEMY_CONCOCTIONS);
// }
//
// public List<ItemStack> getIngredients() {
// return PotionManager.getInstance().getIngredients(getTier());
// }
//
// public String getIngredientList() {
// StringBuilder list = new StringBuilder();
//
// for (ItemStack ingredient : getIngredients()) {
// String string = StringUtils.getPrettyItemString(ingredient.getType());
//
// list.append(", ").append(string);
// }
//
// return list.substring(2);
// }
//
// public double calculateBrewSpeed(boolean isLucky) {
// int skillLevel = getSkillLevel();
//
// if (skillLevel < Alchemy.catalysisUnlockLevel) {
// return Alchemy.catalysisMinSpeed;
// }
//
// double LUCKY_MODIFIER = 4.0 / 3.0;
// return Math.min(Alchemy.catalysisMaxSpeed, Alchemy.catalysisMinSpeed + (Alchemy.catalysisMaxSpeed - Alchemy.catalysisMinSpeed) * (skillLevel - Alchemy.catalysisUnlockLevel) / (Alchemy.catalysisMaxBonusLevel - Alchemy.catalysisUnlockLevel)) * (isLucky ? LUCKY_MODIFIER : 1.0);
// }
//
// public void handlePotionBrewSuccesses(PotionStage potionStage, int amount) {
// //TODO: This code disturbs me
// applyXpGain((float) (mcMMO.getConfigManager().getConfigExperience().getExperienceAlchemy().getPotionXPByStage(potionStage.toNumerical()) * amount), XPGainReason.PVE, XPGainSource.PASSIVE);
// }
}

View File

@ -1,251 +0,0 @@
package com.gmail.nossr50.skills.alchemy;
import com.gmail.nossr50.config.skills.alchemy.PotionManager;
import com.gmail.nossr50.datatypes.skills.SubSkillType;
import com.gmail.nossr50.datatypes.skills.alchemy.AlchemyPotion;
import com.gmail.nossr50.datatypes.skills.alchemy.PotionStage;
import com.gmail.nossr50.events.fake.FakeBrewEvent;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.runnables.player.PlayerUpdateInventoryTask;
import com.gmail.nossr50.runnables.skills.AlchemyBrewCheckTask;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.player.UserManager;
import org.bukkit.Material;
import org.bukkit.block.BlockState;
import org.bukkit.block.BrewingStand;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.BrewerInventory;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryView;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.List;
public final class AlchemyPotionBrewer {
public static boolean isValidBrew(Player player, ItemStack[] contents) {
if (!isValidIngredient(player, contents[Alchemy.INGREDIENT_SLOT])) {
return false;
}
for (int i = 0; i < 3; i++) {
if (contents[i] == null || contents[i].getType() != Material.POTION && contents[i].getType() != Material.SPLASH_POTION && contents[i].getType() != Material.LINGERING_POTION) {
continue;
}
if (getChildPotion(PotionManager.getInstance().getPotion(contents[i]), contents[Alchemy.INGREDIENT_SLOT]) != null) {
return true;
}
}
return false;
}
private static AlchemyPotion getChildPotion(AlchemyPotion potion, ItemStack ingredient) {
if (potion != null) {
return potion.getChild(ingredient);
}
return null;
}
public static boolean isEmpty(ItemStack item) {
return item == null || item.getType() == Material.AIR || item.getAmount() == 0;
}
private static void removeIngredient(BrewerInventory inventory, Player player) {
ItemStack ingredient = inventory.getIngredient() == null ? null : inventory.getIngredient().clone();
if (isEmpty(ingredient) || !isValidIngredient(player, ingredient)) {
} else if (ingredient.getAmount() <= 1) {
inventory.setIngredient(null);
} else {
ingredient.setAmount(ingredient.getAmount() - 1);
inventory.setIngredient(ingredient);
}
}
private static boolean hasIngredient(BrewerInventory inventory, Player player) {
ItemStack ingredient = inventory.getIngredient() == null ? null : inventory.getIngredient().clone();
return !isEmpty(ingredient) && isValidIngredient(player, ingredient);
}
public static boolean isValidIngredient(Player player, ItemStack item) {
if (isEmpty(item)) {
return false;
}
for (ItemStack ingredient : getValidIngredients(player)) {
if (item.isSimilar(ingredient)) {
return true;
}
}
return false;
}
private static List<ItemStack> getValidIngredients(Player player) {
if (player == null || UserManager.getPlayer(player) == null) {
return PotionManager.getInstance().getIngredients(1);
}
return PotionManager.getInstance().getIngredients(!Permissions.isSubSkillEnabled(player, SubSkillType.ALCHEMY_CONCOCTIONS) ? 1 : UserManager.getPlayer(player).getAlchemyManager().getTier());
}
public static void finishBrewing(BlockState brewingStand, Player player, boolean forced) {
if (!(brewingStand instanceof BrewingStand)) {
return;
}
BrewerInventory inventory = ((BrewingStand) brewingStand).getInventory();
ItemStack ingredient = inventory.getIngredient() == null ? null : inventory.getIngredient().clone();
if (!hasIngredient(inventory, player)) {
return;
}
List<AlchemyPotion> inputList = new ArrayList<>();
for (int i = 0; i < 3; i++) {
ItemStack item = inventory.getItem(i);
if (isEmpty(item) || item.getType() == Material.GLASS_BOTTLE || !PotionManager.getInstance().isValidPotion(item)) {
continue;
}
AlchemyPotion input = PotionManager.getInstance().getPotion(item);
AlchemyPotion output = input.getChild(ingredient);
inputList.add(input);
if (output != null) {
inventory.setItem(i, output.toItemStack(item.getAmount()).clone());
}
}
FakeBrewEvent event = new FakeBrewEvent(brewingStand.getBlock(), inventory, ((BrewingStand) brewingStand).getFuelLevel());
mcMMO.p.getServer().getPluginManager().callEvent(event);
if (event.isCancelled() || inputList.isEmpty()) {
return;
}
removeIngredient(inventory, player);
for (AlchemyPotion input : inputList) {
AlchemyPotion output = input.getChild(ingredient);
if (output != null && player != null) {
PotionStage potionStage = PotionStage.getPotionStage(input, output);
//TODO: hmm
if (UserManager.hasPlayerDataKey(player)) {
UserManager.getPlayer(player).getAlchemyManager().handlePotionBrewSuccesses(potionStage, 1);
}
}
}
if (!forced) {
scheduleUpdate(inventory);
}
}
public static boolean transferItems(InventoryView view, int fromSlot, ClickType click) {
boolean success = false;
if (click.isLeftClick()) {
success = transferItems(view, fromSlot);
} else if (click.isRightClick()) {
success = transferOneItem(view, fromSlot);
}
return success;
}
private static boolean transferOneItem(InventoryView view, int fromSlot) {
ItemStack from = view.getItem(fromSlot).clone();
ItemStack to = view.getItem(Alchemy.INGREDIENT_SLOT).clone();
if (isEmpty(from)) {
return false;
}
boolean emptyTo = isEmpty(to);
int fromAmount = from.getAmount();
if (!emptyTo && fromAmount >= from.getType().getMaxStackSize()) {
return false;
} else if (emptyTo || from.isSimilar(to)) {
if (emptyTo) {
to = from.clone();
to.setAmount(1);
} else {
to.setAmount(to.getAmount() + 1);
}
from.setAmount(fromAmount - 1);
view.setItem(Alchemy.INGREDIENT_SLOT, to);
view.setItem(fromSlot, from);
return true;
}
return false;
}
/**
* Transfer items between two ItemStacks, returning the leftover status
*/
private static boolean transferItems(InventoryView view, int fromSlot) {
ItemStack from = view.getItem(fromSlot).clone();
ItemStack to = view.getItem(Alchemy.INGREDIENT_SLOT).clone();
if (isEmpty(from)) {
return false;
} else if (isEmpty(to)) {
view.setItem(Alchemy.INGREDIENT_SLOT, from);
view.setItem(fromSlot, null);
return true;
} else if (from.isSimilar(to)) {
int fromAmount = from.getAmount();
int toAmount = to.getAmount();
int maxSize = to.getType().getMaxStackSize();
if (fromAmount + toAmount > maxSize) {
int left = fromAmount + toAmount - maxSize;
to.setAmount(maxSize);
view.setItem(Alchemy.INGREDIENT_SLOT, to);
from.setAmount(left);
view.setItem(fromSlot, from);
return true;
}
to.setAmount(fromAmount + toAmount);
view.setItem(fromSlot, null);
view.setItem(Alchemy.INGREDIENT_SLOT, to);
return true;
}
return false;
}
public static void scheduleCheck(Player player, BrewingStand brewingStand) {
new AlchemyBrewCheckTask(player, brewingStand).runTask(mcMMO.p);
}
public static void scheduleUpdate(Inventory inventory) {
for (HumanEntity humanEntity : inventory.getViewers()) {
if (humanEntity instanceof Player) {
new PlayerUpdateInventoryTask((Player) humanEntity).runTask(mcMMO.p);
}
}
}
}

View File

@ -1,718 +0,0 @@
package com.gmail.nossr50.skills.alchemy;
import com.gmail.nossr50.datatypes.skills.alchemy.AlchemyPotion;
import com.gmail.nossr50.mcMMO;
import com.google.common.reflect.TypeToken;
import org.bukkit.ChatColor;
import org.bukkit.Color;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionData;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.potion.PotionType;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
public class PotionGenerator {
private HashMap<String, AlchemyPotion> potionHashMap;
public PotionGenerator() {
potionHashMap = new HashMap<>();
init();
}
private void init() {
Map<WriteablePotion, Map<Ingredient, WriteablePotion>> vanillaPotions = new HashMap<>();
populateVanillaPotions(vanillaPotions);
Map<WriteablePotion, Map<Ingredient, WriteablePotion>> mcMMOPotions = new HashMap<>();
populateCustomPotions(mcMMOPotions);
List<WriteablePotion> sorted = new ArrayList<>();
sorted.addAll(vanillaPotions.keySet());
sorted.addAll(mcMMOPotions.keySet());
sorted.sort((a, b) -> {
// All normal potions first
if (a.mat == Material.POTION && b.mat != Material.POTION) {
return -1;
}
if (b.mat == Material.POTION && a.mat != Material.POTION) {
return 1;
}
// All splash potions second
if (a.mat == Material.SPLASH_POTION && b.mat != Material.SPLASH_POTION) {
return -1;
}
if (b.mat == Material.SPLASH_POTION && a.mat != Material.SPLASH_POTION) {
return 1;
}
// Vanilla Potions first
if (a.effect == null && b.effect != null) {
return -1;
}
if (b.effect == null && a.effect != null) {
return 1;
}
// Vanilla potions
if (a.effect == null && b.effect == null) {
// Order by PotionType
if (a.data.getType() != b.data.getType()) {
return Integer.compare(a.data.getType().ordinal(), b.data.getType().ordinal());
}
// Plain before extended or upgraded
if (!a.data.isExtended() && !a.data.isUpgraded() && (b.data.isExtended() || b.data.isUpgraded())) {
return -1;
}
if (!b.data.isExtended() && !b.data.isUpgraded() && (a.data.isExtended() || a.data.isUpgraded())) {
return 1;
}
// Extended before Upgraded
if (a.data.isExtended() && b.data.isUpgraded()) {
return -1;
}
if (b.data.isExtended() && a.data.isUpgraded()) {
return -1;
}
// Same potion somehow?
return 0;
}
// mcMMO Potions
else {
if ((a.baseName.contains("II") || a.baseName.contains("EXTENDED")) && !(b.baseName.contains("II") || b.baseName.contains("EXTENDED"))) {
return 1;
}
if ((b.baseName.contains("II") || b.baseName.contains("EXTENDED")) && !(a.baseName.contains("II") || a.baseName.contains("EXTENDED"))) {
return -1;
}
if (!a.baseName.contains("II") && b.baseName.contains("II")) {
return -1;
}
if (!b.baseName.contains("II") && a.baseName.contains("II")) {
return 1;
}
return a.baseName.split("_")[0].compareTo(b.baseName.split("_")[0]);
}
});
/* Hacky solution, this entire class disgusts me */
HashMap<String, AlchemyPotion> potionHashMap = new HashMap<>();
for(WriteablePotion potion : sorted)
{
AlchemyPotion alchemyPotion = convertWriteableToAlchemyPotion(potion);
potionHashMap.put(alchemyPotion.getName(), alchemyPotion);
}
// for (WriteablePotion potion : sorted) {
// System.out.println(" " + potion.name + ":");
// Map<Ingredient, WriteablePotion> children;
// if (vanillaPotions.containsKey(potion)) {
// children = vanillaPotions.get(potion);
// } else {
// System.out.println(" Name: " + prettify(potion.name));
// children = mcMMOPotions.get(potion);
// }
// System.out.println(" Material: " + potion.mat.name());
// System.out.println(" PotionData:");
// System.out.println(" PotionType: " + potion.data.getType().name());
// if (potion.data.isExtended()) {
// System.out.println(" Extended: true");
// }
// if (potion.data.isUpgraded()) {
// System.out.println(" Upgraded: true");
// }
// if (potion.effect != null) {
// System.out.println(" Effects: [\"" + getName(potion.effect.getType()) + " " + potion.effect.getAmplifier() + " " + potion.effect.getDuration() + "\"]");
// }
// if (children == null || children.isEmpty()) {
// continue;
// }
// System.out.println(" Children:");
// for (Entry<Ingredient, WriteablePotion> child : children.entrySet()) {
// System.out.println(" " + child.getKey().name + ": " + child.getValue().name);
// }
// }
}
/**
* I just want anyone who reads this to know
* This entire class is an abomination
* What you see below is a hacky solution to keep Alchemy functioning with the new config system
* Alchemy will be rewritten, until then, this disgusting class exists.
* @param writeablePotion target WriteablePotion
* @return converted WriteablePotion
*/
private AlchemyPotion convertWriteableToAlchemyPotion(WriteablePotion writeablePotion) {
try {
String name = writeablePotion.name;
if (name != null) {
name = prettify(ChatColor.translateAlternateColorCodes('&', name));
}
PotionData data = writeablePotion.data;
Material material = Material.POTION;
if(writeablePotion.mat != null)
material = writeablePotion.mat;
//Lore is unused as far as I can tell
List<String> lore = new ArrayList<>();
List<PotionEffect> effects = new ArrayList<>();
effects.add(writeablePotion.effect);
Color color = this.generateColor(effects);
return new AlchemyPotion(material, data, name, lore, effects, color, getChildren(writeablePotion));
} catch (Exception e) {
mcMMO.p.getLogger().warning("Failed to load Alchemy potion: " + potion_section.getString());
return null;
}
}
public Color generateColor(List<PotionEffect> effects) {
if (effects != null && !effects.isEmpty()) {
List<Color> colors = new ArrayList<>();
for (PotionEffect effect : effects) {
if (effect.getType().getColor() != null) {
colors.add(effect.getType().getColor());
}
}
if (!colors.isEmpty()) {
if (colors.size() > 1) {
return calculateAverageColor(colors);
}
return colors.get(0);
}
}
return null;
}
public Color calculateAverageColor(List<Color> colors) {
int red = 0;
int green = 0;
int blue = 0;
for (Color color : colors) {
red += color.getRed();
green += color.getGreen();
blue += color.getBlue();
}
Color color = Color.fromRGB(red / colors.size(), green / colors.size(), blue / colors.size());
return color;
}
private static String prettify(String name) {
String[] substrings = name.split("_");
String prettyString = "";
int size = 1;
for (String string : substrings) {
prettyString = prettyString.concat(getCapitalized(string));
if (size < substrings.length) {
prettyString = prettyString.concat(" ");
}
size++;
}
return prettyString;
}
public static String getCapitalized(String target) {
if (target.equals("II")) { // hacks
return target;
}
return target.substring(0, 1).toUpperCase() + target.substring(1).toLowerCase();
}
private static String getName(PotionEffectType type) {
switch (type.getId()) {
case 1:
return "SPEED";
case 2:
return "SLOW";
case 3:
return "FAST_DIGGING";
case 4:
return "SLOW_DIGGING";
case 5:
return "INCREASE_DAMAGE";
case 6:
return "HEAL";
case 7:
return "HARM";
case 8:
return "JUMP";
case 9:
return "CONFUSION";
case 10:
return "REGENERATION";
case 11:
return "DAMAGE_RESISTANCE";
case 12:
return "FIRE_RESISTANCE";
case 13:
return "WATER_BREATHING";
case 14:
return "INVISIBILITY";
case 15:
return "BLINDNESS";
case 16:
return "NIGHT_VISION";
case 17:
return "HUNGER";
case 18:
return "WEAKNESS";
case 19:
return "POISON";
case 20:
return "WITHER";
case 21:
return "HEALTH_BOOST";
case 22:
return "ABSORPTION";
case 23:
return "SATURATION";
case 24:
return "GLOWING";
case 25:
return "LEVITATION";
case 26:
return "LUCK";
case 27:
return "UNLUCK";
case 28:
return "SLOW_FALLING";
case 29:
return "CONDUIT_POWER";
case 30:
return "DOLPHINS_GRACE";
default:
return "UNKNOWN_EFFECT_TYPE_" + type.getId();
}
}
private void populateVanillaPotions(Map<WriteablePotion, Map<Ingredient, WriteablePotion>> vanillaPotions) {
for (PotionType type : PotionType.values()) {
for (Material material : new Material[]{Material.POTION, Material.SPLASH_POTION, Material.LINGERING_POTION}) {
WriteablePotion writeablePotion = new WriteablePotion(material, type);
getChildren(writeablePotion);
vanillaPotions.put(writeablePotion, getChildren(writeablePotion));
if (type.isExtendable()) {
writeablePotion = new WriteablePotion(material, new PotionData(type, true, false));
vanillaPotions.put(writeablePotion, getChildren(writeablePotion));
}
if (type.isUpgradeable()) {
writeablePotion = new WriteablePotion(material, new PotionData(type, false, true));
vanillaPotions.put(writeablePotion, getChildren(writeablePotion));
}
}
}
for (Entry<WriteablePotion, Map<Ingredient, WriteablePotion>> entry : vanillaPotions.entrySet()) {
if (entry.getKey().mat == Material.POTION) {
entry.getValue().put(new Ingredient(Material.GUNPOWDER), new WriteablePotion(Material.SPLASH_POTION, entry.getKey().data));
}
if (entry.getKey().mat == Material.SPLASH_POTION) {
entry.getValue().put(new Ingredient(Material.DRAGON_BREATH), new WriteablePotion(Material.LINGERING_POTION, entry.getKey().data));
}
}
//Store children
}
private HashMap<Ingredient, WriteablePotion> getChildren(WriteablePotion writeablePotion) {
HashMap<Ingredient, WriteablePotion> children = new HashMap<>();
switch (writeablePotion.data.getType()) {
case WATER:
assert (!writeablePotion.data.isExtended());
assert (!writeablePotion.data.isUpgraded());
children.put(new Ingredient(Material.NETHER_WART), new WriteablePotion(writeablePotion.mat, PotionType.AWKWARD));
children.put(new Ingredient(Material.FERMENTED_SPIDER_EYE), new WriteablePotion(writeablePotion.mat, PotionType.WEAKNESS));
children.put(new Ingredient(Material.REDSTONE), new WriteablePotion(writeablePotion.mat, PotionType.MUNDANE));
children.put(new Ingredient(Material.GLOWSTONE_DUST), new WriteablePotion(writeablePotion.mat, PotionType.THICK));
children.put(new Ingredient(Material.BLAZE_POWDER), new WriteablePotion(writeablePotion.mat, PotionType.MUNDANE));
children.put(new Ingredient(Material.SUGAR), new WriteablePotion(writeablePotion.mat, PotionType.MUNDANE));
children.put(new Ingredient(Material.RABBIT_FOOT), new WriteablePotion(writeablePotion.mat, PotionType.MUNDANE));
children.put(new Ingredient(Material.SPIDER_EYE), new WriteablePotion(writeablePotion.mat, PotionType.MUNDANE));
children.put(new Ingredient(Material.MAGMA_CREAM), new WriteablePotion(writeablePotion.mat, PotionType.MUNDANE));
children.put(new Ingredient(Material.GLISTERING_MELON_SLICE), new WriteablePotion(writeablePotion.mat, PotionType.MUNDANE));
children.put(new Ingredient(Material.GHAST_TEAR), new WriteablePotion(writeablePotion.mat, PotionType.MUNDANE));
return children;
case AWKWARD:
assert (!writeablePotion.data.isExtended());
assert (!writeablePotion.data.isUpgraded());
children.put(new Ingredient(Material.GOLDEN_CARROT), new WriteablePotion(writeablePotion.mat, PotionType.NIGHT_VISION));
children.put(new Ingredient(Material.RABBIT_FOOT), new WriteablePotion(writeablePotion.mat, PotionType.JUMP));
children.put(new Ingredient(Material.MAGMA_CREAM), new WriteablePotion(writeablePotion.mat, PotionType.FIRE_RESISTANCE));
children.put(new Ingredient(Material.SUGAR), new WriteablePotion(writeablePotion.mat, PotionType.SPEED));
children.put(new Ingredient(Material.PUFFERFISH), new WriteablePotion(writeablePotion.mat, PotionType.WATER_BREATHING));
children.put(new Ingredient(Material.GLISTERING_MELON_SLICE), new WriteablePotion(writeablePotion.mat, PotionType.INSTANT_HEAL));
children.put(new Ingredient(Material.SPIDER_EYE), new WriteablePotion(writeablePotion.mat, PotionType.POISON));
children.put(new Ingredient(Material.GHAST_TEAR), new WriteablePotion(writeablePotion.mat, PotionType.REGEN));
children.put(new Ingredient(Material.BLAZE_POWDER), new WriteablePotion(writeablePotion.mat, PotionType.STRENGTH));
children.put(new Ingredient(Material.TURTLE_HELMET), new WriteablePotion(writeablePotion.mat, PotionType.TURTLE_MASTER));
children.put(new Ingredient(Material.PHANTOM_MEMBRANE), new WriteablePotion(writeablePotion.mat, PotionType.SLOW_FALLING));
// mcMMO custom potions
double mod = 1;
if (writeablePotion.mat == Material.SPLASH_POTION) {
mod = 0.75;
}
if (writeablePotion.mat == Material.LINGERING_POTION) {
mod = 0.25;
}
children.put(new Ingredient(Material.BROWN_MUSHROOM), new WriteablePotion(writeablePotion.mat, PotionType.UNCRAFTABLE, new PotionEffect(PotionEffectType.CONFUSION, (int) (450 * mod), 0), "NAUSEA"));
children.put(new Ingredient(Material.CARROT), new WriteablePotion(writeablePotion.mat, PotionType.UNCRAFTABLE, new PotionEffect(PotionEffectType.FAST_DIGGING, (int) (3600 * mod), 0), "HASTE"));
children.put(new Ingredient(Material.SLIME_BALL), new WriteablePotion(writeablePotion.mat, PotionType.UNCRAFTABLE, new PotionEffect(PotionEffectType.SLOW_DIGGING, (int) (3600 * mod), 0), "DULLNESS"));
children.put(new Ingredient(Material.GOLDEN_APPLE), new WriteablePotion(writeablePotion.mat, PotionType.UNCRAFTABLE, new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, (int) (450 * mod), 0), "RESISTANCE"));
children.put(new Ingredient(Material.INK_SAC), new WriteablePotion(writeablePotion.mat, PotionType.UNCRAFTABLE, new PotionEffect(PotionEffectType.BLINDNESS, (int) (225 * mod), 0), "BLINDNESS"));
children.put(new Ingredient(Material.ROTTEN_FLESH), new WriteablePotion(writeablePotion.mat, PotionType.UNCRAFTABLE, new PotionEffect(PotionEffectType.HUNGER, (int) (900 * mod), 0), "HUNGER"));
children.put(new Ingredient(Material.POISONOUS_POTATO), new WriteablePotion(writeablePotion.mat, PotionType.UNCRAFTABLE, new PotionEffect(PotionEffectType.WITHER, (int) (450 * mod), 0), "DECAY"));
children.put(new Ingredient(Material.QUARTZ), new WriteablePotion(writeablePotion.mat, PotionType.UNCRAFTABLE, new PotionEffect(PotionEffectType.ABSORPTION, (int) (1800 * mod), 0), "ABSORPTION"));
children.put(new Ingredient(Material.FERN), new WriteablePotion(writeablePotion.mat, PotionType.UNCRAFTABLE, new PotionEffect(PotionEffectType.SATURATION, (int) (8 * mod), 0), "SATURATION"));
children.put(new Ingredient(Material.APPLE), new WriteablePotion(writeablePotion.mat, PotionType.UNCRAFTABLE, new PotionEffect(PotionEffectType.HEALTH_BOOST, (int) (1800 * mod), 0), "HEALTH_BOOST"));
return children;
case FIRE_RESISTANCE:
assert (!writeablePotion.data.isUpgraded());
if (writeablePotion.data.isExtended()) {
children.put(new Ingredient(Material.FERMENTED_SPIDER_EYE), new WriteablePotion(writeablePotion.mat, new PotionData(PotionType.SLOWNESS, true, false)));
} else {
children.put(new Ingredient(Material.FERMENTED_SPIDER_EYE), new WriteablePotion(writeablePotion.mat, PotionType.SLOWNESS));
children.put(new Ingredient(Material.REDSTONE), new WriteablePotion(writeablePotion.mat, new PotionData(writeablePotion.data.getType(), true, false)));
}
return children;
case INSTANT_DAMAGE:
assert (!writeablePotion.data.isExtended());
if (!writeablePotion.data.isUpgraded()) {
children.put(new Ingredient(Material.GLOWSTONE_DUST), new WriteablePotion(writeablePotion.mat, new PotionData(writeablePotion.data.getType(), false, true)));
}
return children;
case INSTANT_HEAL:
assert (!writeablePotion.data.isExtended());
if (!writeablePotion.data.isUpgraded()) {
children.put(new Ingredient(Material.FERMENTED_SPIDER_EYE), new WriteablePotion(writeablePotion.mat, PotionType.INSTANT_DAMAGE));
children.put(new Ingredient(Material.GLOWSTONE_DUST), new WriteablePotion(writeablePotion.mat, new PotionData(writeablePotion.data.getType(), false, true)));
} else {
children.put(new Ingredient(Material.FERMENTED_SPIDER_EYE), new WriteablePotion(writeablePotion.mat, new PotionData(PotionType.INSTANT_DAMAGE, false, true)));
}
return children;
case INVISIBILITY:
assert (!writeablePotion.data.isUpgraded());
if (!writeablePotion.data.isExtended()) {
children.put(new Ingredient(Material.REDSTONE), new WriteablePotion(writeablePotion.mat, new PotionData(writeablePotion.data.getType(), true, false)));
}
return children;
case JUMP:
if (!writeablePotion.data.isUpgraded() && !writeablePotion.data.isExtended()) {
children.put(new Ingredient(Material.FERMENTED_SPIDER_EYE), new WriteablePotion(writeablePotion.mat, PotionType.SLOWNESS));
children.put(new Ingredient(Material.GLOWSTONE_DUST), new WriteablePotion(writeablePotion.mat, new PotionData(writeablePotion.data.getType(), false, true)));
children.put(new Ingredient(Material.REDSTONE), new WriteablePotion(writeablePotion.mat, new PotionData(writeablePotion.data.getType(), true, false)));
}
return children;
case NIGHT_VISION:
assert (!writeablePotion.data.isUpgraded());
if (!writeablePotion.data.isExtended()) {
children.put(new Ingredient(Material.FERMENTED_SPIDER_EYE), new WriteablePotion(writeablePotion.mat, PotionType.INVISIBILITY));
children.put(new Ingredient(Material.REDSTONE), new WriteablePotion(writeablePotion.mat, new PotionData(writeablePotion.data.getType(), true, false)));
} else {
children.put(new Ingredient(Material.FERMENTED_SPIDER_EYE), new WriteablePotion(writeablePotion.mat, new PotionData(PotionType.INVISIBILITY, true, false)));
}
return children;
case POISON:
if (!writeablePotion.data.isUpgraded() && !writeablePotion.data.isExtended()) {
children.put(new Ingredient(Material.FERMENTED_SPIDER_EYE), new WriteablePotion(writeablePotion.mat, PotionType.INSTANT_DAMAGE));
children.put(new Ingredient(Material.GLOWSTONE_DUST), new WriteablePotion(writeablePotion.mat, new PotionData(writeablePotion.data.getType(), false, true)));
children.put(new Ingredient(Material.REDSTONE), new WriteablePotion(writeablePotion.mat, new PotionData(writeablePotion.data.getType(), true, false)));
} else {
children.put(new Ingredient(Material.FERMENTED_SPIDER_EYE), new WriteablePotion(writeablePotion.mat, new PotionData(PotionType.INSTANT_DAMAGE, false, true)));
}
return children;
case REGEN:
if (!writeablePotion.data.isUpgraded() && !writeablePotion.data.isExtended()) {
children.put(new Ingredient(Material.GLOWSTONE_DUST), new WriteablePotion(writeablePotion.mat, new PotionData(writeablePotion.data.getType(), false, true)));
children.put(new Ingredient(Material.REDSTONE), new WriteablePotion(writeablePotion.mat, new PotionData(writeablePotion.data.getType(), true, false)));
}
return children;
case SLOWNESS:
assert (!writeablePotion.data.isUpgraded());
if (!writeablePotion.data.isExtended()) {
children.put(new Ingredient(Material.REDSTONE), new WriteablePotion(writeablePotion.mat, new PotionData(writeablePotion.data.getType(), true, false)));
}
return children;
case SLOW_FALLING:
assert (!writeablePotion.data.isUpgraded());
if (!writeablePotion.data.isExtended()) {
children.put(new Ingredient(Material.REDSTONE), new WriteablePotion(writeablePotion.mat, new PotionData(writeablePotion.data.getType(), true, false)));
}
return children;
case SPEED:
if (!writeablePotion.data.isUpgraded() && !writeablePotion.data.isExtended()) {
children.put(new Ingredient(Material.FERMENTED_SPIDER_EYE), new WriteablePotion(writeablePotion.mat, PotionType.SLOWNESS));
children.put(new Ingredient(Material.GLOWSTONE_DUST), new WriteablePotion(writeablePotion.mat, new PotionData(writeablePotion.data.getType(), false, true)));
children.put(new Ingredient(Material.REDSTONE), new WriteablePotion(writeablePotion.mat, new PotionData(writeablePotion.data.getType(), true, false)));
} else {
children.put(new Ingredient(Material.FERMENTED_SPIDER_EYE), new WriteablePotion(writeablePotion.mat, new PotionData(PotionType.SLOWNESS, true, false)));
}
return children;
case STRENGTH:
if (!writeablePotion.data.isUpgraded() && !writeablePotion.data.isExtended()) {
children.put(new Ingredient(Material.GLOWSTONE_DUST), new WriteablePotion(writeablePotion.mat, new PotionData(writeablePotion.data.getType(), false, true)));
children.put(new Ingredient(Material.REDSTONE), new WriteablePotion(writeablePotion.mat, new PotionData(writeablePotion.data.getType(), true, false)));
}
return children;
case TURTLE_MASTER:
if (!writeablePotion.data.isUpgraded() && !writeablePotion.data.isExtended()) {
children.put(new Ingredient(Material.GLOWSTONE_DUST), new WriteablePotion(writeablePotion.mat, new PotionData(writeablePotion.data.getType(), false, true)));
children.put(new Ingredient(Material.REDSTONE), new WriteablePotion(writeablePotion.mat, new PotionData(writeablePotion.data.getType(), true, false)));
}
return children;
case WATER_BREATHING:
assert (!writeablePotion.data.isUpgraded());
if (!writeablePotion.data.isExtended()) {
children.put(new Ingredient(Material.FERMENTED_SPIDER_EYE), new WriteablePotion(writeablePotion.mat, PotionType.INSTANT_DAMAGE));
children.put(new Ingredient(Material.REDSTONE), new WriteablePotion(writeablePotion.mat, new PotionData(writeablePotion.data.getType(), true, false)));
}
return children;
case WEAKNESS:
assert (!writeablePotion.data.isUpgraded());
if (!writeablePotion.data.isExtended()) {
children.put(new Ingredient(Material.REDSTONE), new WriteablePotion(writeablePotion.mat, new PotionData(writeablePotion.data.getType(), true, false)));
}
return children;
case LUCK:
case MUNDANE:
case THICK:
case UNCRAFTABLE:
assert (!writeablePotion.data.isExtended());
assert (!writeablePotion.data.isUpgraded());
return children;
default:
return children;
}
}
private static void populateCustomPotions(Map<WriteablePotion, Map<Ingredient, WriteablePotion>> mcMMOPotions) {
for (Material material : new Material[]{Material.POTION, Material.SPLASH_POTION, Material.LINGERING_POTION}) {
WriteablePotion data;
double mod = 1;
if (material == Material.SPLASH_POTION) {
mod = 0.75;
}
if (material == Material.LINGERING_POTION) {
mod = 0.25;
}
HashMap<Ingredient, WriteablePotion> children;
data = new WriteablePotion(material, PotionType.UNCRAFTABLE, new PotionEffect(PotionEffectType.CONFUSION, (int) (450 * mod), 0), "NAUSEA");
children = new HashMap<>();
children.put(new Ingredient(Material.GLOWSTONE_DUST), new WriteablePotion(material, PotionType.UNCRAFTABLE, new PotionEffect(data.effect.getType(), data.effect.getDuration() / 2, 1), data.baseName + "_II"));
children.put(new Ingredient(Material.REDSTONE), new WriteablePotion(material, PotionType.UNCRAFTABLE, new PotionEffect(data.effect.getType(), data.effect.getDuration() * 2, 0), data.baseName + "_EXTENDED"));
for (WriteablePotion child : children.values()) {
mcMMOPotions.put(child, new HashMap<>());
}
mcMMOPotions.put(data, children);
data = new WriteablePotion(material, PotionType.UNCRAFTABLE, new PotionEffect(PotionEffectType.FAST_DIGGING, (int) (3600 * mod), 0), "HASTE");
children = new HashMap<>();
children.put(new Ingredient(Material.GLOWSTONE_DUST), new WriteablePotion(material, PotionType.UNCRAFTABLE, new PotionEffect(data.effect.getType(), data.effect.getDuration() / 2, 1), data.baseName + "_II"));
children.put(new Ingredient(Material.REDSTONE), new WriteablePotion(material, PotionType.UNCRAFTABLE, new PotionEffect(data.effect.getType(), data.effect.getDuration() * 2, 0), data.baseName + "_EXTENDED"));
for (WriteablePotion child : children.values()) {
mcMMOPotions.put(child, new HashMap<>());
}
mcMMOPotions.put(data, children);
data = new WriteablePotion(material, PotionType.UNCRAFTABLE, new PotionEffect(PotionEffectType.SLOW_DIGGING, (int) (3600 * mod), 0), "DULLNESS");
children = new HashMap<>();
children.put(new Ingredient(Material.GLOWSTONE_DUST), new WriteablePotion(material, PotionType.UNCRAFTABLE, new PotionEffect(data.effect.getType(), data.effect.getDuration() / 2, 1), data.baseName + "_II"));
children.put(new Ingredient(Material.REDSTONE), new WriteablePotion(material, PotionType.UNCRAFTABLE, new PotionEffect(data.effect.getType(), data.effect.getDuration() * 2, 0), data.baseName + "_EXTENDED"));
for (WriteablePotion child : children.values()) {
mcMMOPotions.put(child, new HashMap<>());
}
mcMMOPotions.put(data, children);
data = new WriteablePotion(material, PotionType.UNCRAFTABLE, new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, (int) (450 * mod), 0), "RESISTANCE");
children = new HashMap<>();
children.put(new Ingredient(Material.GLOWSTONE_DUST), new WriteablePotion(material, PotionType.UNCRAFTABLE, new PotionEffect(data.effect.getType(), data.effect.getDuration() / 2, 1), data.baseName + "_II"));
children.put(new Ingredient(Material.REDSTONE), new WriteablePotion(material, PotionType.UNCRAFTABLE, new PotionEffect(data.effect.getType(), data.effect.getDuration() * 2, 0), data.baseName + "_EXTENDED"));
for (WriteablePotion child : children.values()) {
mcMMOPotions.put(child, new HashMap<>());
}
mcMMOPotions.put(data, children);
data = new WriteablePotion(material, PotionType.UNCRAFTABLE, new PotionEffect(PotionEffectType.BLINDNESS, (int) (225 * mod), 0), "BLINDNESS");
children = new HashMap<>();
children.put(new Ingredient(Material.GLOWSTONE_DUST), new WriteablePotion(material, PotionType.UNCRAFTABLE, new PotionEffect(data.effect.getType(), data.effect.getDuration() / 2, 1), data.baseName + "_II"));
children.put(new Ingredient(Material.REDSTONE), new WriteablePotion(material, PotionType.UNCRAFTABLE, new PotionEffect(data.effect.getType(), data.effect.getDuration() * 2, 0), data.baseName + "_EXTENDED"));
for (WriteablePotion child : children.values()) {
mcMMOPotions.put(child, new HashMap<>());
}
mcMMOPotions.put(data, children);
data = new WriteablePotion(material, PotionType.UNCRAFTABLE, new PotionEffect(PotionEffectType.HUNGER, (int) (900 * mod), 0), "HUNGER");
children = new HashMap<>();
children.put(new Ingredient(Material.GLOWSTONE_DUST), new WriteablePotion(material, PotionType.UNCRAFTABLE, new PotionEffect(data.effect.getType(), data.effect.getDuration() / 2, 1), data.baseName + "_II"));
children.put(new Ingredient(Material.REDSTONE), new WriteablePotion(material, PotionType.UNCRAFTABLE, new PotionEffect(data.effect.getType(), data.effect.getDuration() * 2, 0), data.baseName + "_EXTENDED"));
for (WriteablePotion child : children.values()) {
mcMMOPotions.put(child, new HashMap<>());
}
mcMMOPotions.put(data, children);
data = new WriteablePotion(material, PotionType.UNCRAFTABLE, new PotionEffect(PotionEffectType.WITHER, (int) (450 * mod), 0), "DECAY");
children = new HashMap<>();
children.put(new Ingredient(Material.GLOWSTONE_DUST), new WriteablePotion(material, PotionType.UNCRAFTABLE, new PotionEffect(data.effect.getType(), data.effect.getDuration() / 2, 1), data.baseName + "_II"));
children.put(new Ingredient(Material.REDSTONE), new WriteablePotion(material, PotionType.UNCRAFTABLE, new PotionEffect(data.effect.getType(), data.effect.getDuration() * 2, 0), data.baseName + "_EXTENDED"));
for (WriteablePotion child : children.values()) {
mcMMOPotions.put(child, new HashMap<>());
}
mcMMOPotions.put(data, children);
data = new WriteablePotion(material, PotionType.UNCRAFTABLE, new PotionEffect(PotionEffectType.ABSORPTION, (int) (1800 * mod), 0), "ABSORPTION");
children = new HashMap<>();
children.put(new Ingredient(Material.GLOWSTONE_DUST), new WriteablePotion(material, PotionType.UNCRAFTABLE, new PotionEffect(data.effect.getType(), data.effect.getDuration() / 2, 1), data.baseName + "_II"));
children.put(new Ingredient(Material.REDSTONE), new WriteablePotion(material, PotionType.UNCRAFTABLE, new PotionEffect(data.effect.getType(), data.effect.getDuration() * 2, 0), data.baseName + "_EXTENDED"));
for (WriteablePotion child : children.values()) {
mcMMOPotions.put(child, new HashMap<>());
}
mcMMOPotions.put(data, children);
data = new WriteablePotion(material, PotionType.UNCRAFTABLE, new PotionEffect(PotionEffectType.SATURATION, (int) (8 * mod), 0), "SATURATION");
children = new HashMap<>();
children.put(new Ingredient(Material.GLOWSTONE_DUST), new WriteablePotion(material, PotionType.UNCRAFTABLE, new PotionEffect(data.effect.getType(), data.effect.getDuration() / 2, 1), data.baseName + "_II"));
children.put(new Ingredient(Material.REDSTONE), new WriteablePotion(material, PotionType.UNCRAFTABLE, new PotionEffect(data.effect.getType(), data.effect.getDuration() * 2, 0), data.baseName + "_EXTENDED"));
for (WriteablePotion child : children.values()) {
mcMMOPotions.put(child, new HashMap<>());
}
mcMMOPotions.put(data, children);
data = new WriteablePotion(material, PotionType.UNCRAFTABLE, new PotionEffect(PotionEffectType.HEALTH_BOOST, (int) (1800 * mod), 0), "HEALTH_BOOST");
children = new HashMap<>();
children.put(new Ingredient(Material.GLOWSTONE_DUST), new WriteablePotion(material, PotionType.UNCRAFTABLE, new PotionEffect(data.effect.getType(), data.effect.getDuration() / 2, 1), data.baseName + "_II"));
children.put(new Ingredient(Material.REDSTONE), new WriteablePotion(material, PotionType.UNCRAFTABLE, new PotionEffect(data.effect.getType(), data.effect.getDuration() * 2, 0), data.baseName + "_EXTENDED"));
for (WriteablePotion child : children.values()) {
mcMMOPotions.put(child, new HashMap<>());
}
mcMMOPotions.put(data, children);
}
// Add all material state changes
for (Entry<WriteablePotion, Map<Ingredient, WriteablePotion>> entry : mcMMOPotions.entrySet()) {
if (entry.getKey().mat == Material.POTION) {
PotionEffect effect = new PotionEffect(entry.getKey().effect.getType(), (int) (entry.getKey().effect.getDuration() * 0.75), entry.getKey().effect.getAmplifier());
entry.getValue().put(new Ingredient(Material.GUNPOWDER), new WriteablePotion(Material.SPLASH_POTION, entry.getKey().data, effect, entry.getKey().baseName));
} else if (entry.getKey().mat == Material.SPLASH_POTION) {
PotionEffect effect = new PotionEffect(entry.getKey().effect.getType(), (int) (entry.getKey().effect.getDuration() * 0.33), entry.getKey().effect.getAmplifier());
entry.getValue().put(new Ingredient(Material.DRAGON_BREATH), new WriteablePotion(Material.LINGERING_POTION, entry.getKey().data, effect, entry.getKey().baseName));
}
}
}
public static class Ingredient {
public Material mat;
public int data;
public String name;
public Ingredient(Material mat) {
this.mat = mat;
this.data = 0;
name = mat.name();
}
}
public static class WriteablePotion {
public String name;
public Material mat;
public PotionData data;
public PotionEffect effect;
public String baseName;
public WriteablePotion(PotionData data) {
this(Material.POTION, data);
}
public WriteablePotion(Material type, PotionData data) {
this(type, data, null, getMCName(data.getType()));
}
public WriteablePotion(Material mat, PotionType type, PotionEffect effect, String baseName) {
this(mat, new PotionData(type, false, false), effect, baseName);
}
public WriteablePotion(Material type, PotionData data, PotionEffect effect, String baseName) {
this.data = data;
this.effect = effect;
this.mat = type;
this.baseName = baseName;
this.name = "POTION_OF_" + baseName;
if (mat == Material.SPLASH_POTION) {
this.name = "SPLASH_" + this.name;
}
if (mat == Material.LINGERING_POTION) {
this.name = "LINGERING_" + this.name;
}
if (data.isExtended()) {
this.name += "_EXTENDED";
}
if (data.isUpgraded()) {
this.name += "_II";
}
}
public WriteablePotion(PotionType type) {
this(new PotionData(type, false, false));
}
public WriteablePotion(Material mat, PotionType type) {
this(mat, new PotionData(type, false, false));
}
private static String getMCName(PotionType type) {
switch (type) {
case INSTANT_DAMAGE:
return "HARMING";
case INSTANT_HEAL:
return "HEALING";
case JUMP:
return "LEAPING";
case REGEN:
return "REGENERATION";
case SPEED:
return "SWIFTNESS";
case UNCRAFTABLE:
return "EMPTY";
case LUCK:
case MUNDANE:
case NIGHT_VISION:
case POISON:
case INVISIBILITY:
case SLOWNESS:
case AWKWARD:
case STRENGTH:
case THICK:
case FIRE_RESISTANCE:
case WATER:
case WATER_BREATHING:
case WEAKNESS:
case TURTLE_MASTER:
case SLOW_FALLING:
return type.name();
default:
return "";
}
}
public int hashCode() {
return name.hashCode();
}
public boolean equals(Object obj) {
if (!(obj instanceof WriteablePotion)) {
return false;
}
return name.equals(((WriteablePotion) obj).name);
}
}
}