Update Alchemy for 1.9 Configuration style has changed, but theoretically old version should still work I think.

This commit is contained in:
t00thpick1
2016-03-01 17:05:58 -05:00
parent f77ae6ee15
commit f52d9feef8
4 changed files with 85 additions and 27 deletions

View File

@ -28,7 +28,7 @@ public class PotionConfig extends ConfigLoader {
private List<ItemStack> concoctionsIngredientsTierSeven = new ArrayList<ItemStack>();
private List<ItemStack> concoctionsIngredientsTierEight = new ArrayList<ItemStack>();
private Map<Short, AlchemyPotion> potionMap = new HashMap<Short, AlchemyPotion>();
private Map<String, AlchemyPotion> potionMap = new HashMap<String, AlchemyPotion>();
private PotionConfig() {
super("potions.yml");
@ -90,11 +90,11 @@ public class PotionConfig extends ConfigLoader {
int pass = 0;
int fail = 0;
for (String dataValue : potionSection.getKeys(false)) {
AlchemyPotion potion = loadPotion(potionSection.getConfigurationSection(dataValue));
for (String potionName : potionSection.getKeys(false)) {
AlchemyPotion potion = loadPotion(potionSection.getConfigurationSection(potionName));
if (potion != null) {
potionMap.put(potion.getDataValue(), potion);
potionMap.put(potionName, potion);
pass++;
}
else {
@ -115,12 +115,20 @@ public class PotionConfig extends ConfigLoader {
*/
private AlchemyPotion loadPotion(ConfigurationSection potion_section) {
try {
short dataValue = Short.parseShort(potion_section.getName());
String name = potion_section.getString("Name");
if (name != null) {
name = ChatColor.translateAlternateColorCodes('&', name);
}
short dataValue = Short.parseShort(potion_section.getString("Data"));
Material material = Material.POTION;
String mat = potion_section.getString("Material", null);
if (mat != null) {
material = Material.valueOf(mat);
}
List<String> lore = new ArrayList<String>();
if (potion_section.contains("Lore")) {
@ -147,12 +155,12 @@ public class PotionConfig extends ConfigLoader {
}
}
Map<ItemStack, Short> children = new HashMap<ItemStack, Short>();
Map<ItemStack, String> children = new HashMap<ItemStack, String>();
if (potion_section.contains("Children")) {
for (String child : potion_section.getConfigurationSection("Children").getKeys(false)) {
ItemStack ingredient = loadIngredient(child);
if (ingredient != null) {
children.put(ingredient, Short.parseShort(potion_section.getConfigurationSection("Children").getString(child)));
children.put(ingredient, potion_section.getConfigurationSection("Children").getString(child));
}
else {
mcMMO.p.getLogger().warning("Failed to parse child for potion " + name + ": " + child);
@ -160,7 +168,7 @@ public class PotionConfig extends ConfigLoader {
}
}
return new AlchemyPotion(dataValue, name, lore, effects, children);
return new AlchemyPotion(material, dataValue, name, lore, effects, children);
}
catch (Exception e) {
mcMMO.p.getLogger().warning("Failed to load Alchemy potion: " + potion_section.getName());
@ -220,7 +228,16 @@ public class PotionConfig extends ConfigLoader {
return potionMap.containsKey(item.getDurability());
}
public AlchemyPotion getPotion(short durability) {
return potionMap.get(durability);
public AlchemyPotion getPotion(String name) {
return potionMap.get(name);
}
public AlchemyPotion getPotion(ItemStack item) {
for (AlchemyPotion potion : potionMap.values()) {
if (potion.isSimilar(item)) {
return potion;
}
}
return null;
}
}