mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-07-03 06:04:44 +02:00
new config pt 9
This commit is contained in:
@ -1,9 +1,8 @@
|
||||
package com.gmail.nossr50.config.skills.alchemy;
|
||||
|
||||
import com.gmail.nossr50.config.ConfigLoader;
|
||||
import com.gmail.nossr50.config.ConfigCollections;
|
||||
import com.gmail.nossr50.datatypes.skills.alchemy.AlchemyPotion;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
@ -15,7 +14,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class PotionConfig extends ConfigLoader {
|
||||
public class PotionConfig extends ConfigCollections {
|
||||
private static PotionConfig instance;
|
||||
|
||||
private List<ItemStack> concoctionsIngredientsTierOne = new ArrayList<ItemStack>();
|
||||
@ -30,7 +29,7 @@ public class PotionConfig extends ConfigLoader {
|
||||
private Map<String, AlchemyPotion> potionMap = new HashMap<String, AlchemyPotion>();
|
||||
|
||||
private PotionConfig() {
|
||||
super("potions.yml");
|
||||
super(McmmoCore.getDataFolderPath().getAbsoluteFile(),"potions.yml");
|
||||
loadKeys();
|
||||
}
|
||||
|
||||
@ -95,8 +94,7 @@ public class PotionConfig extends ConfigLoader {
|
||||
if (potion != null) {
|
||||
potionMap.put(potionName, potion);
|
||||
pass++;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
fail++;
|
||||
}
|
||||
}
|
||||
@ -109,18 +107,17 @@ public class PotionConfig extends ConfigLoader {
|
||||
* Returns null if input cannot be parsed.
|
||||
*
|
||||
* @param potion_section ConfigurationSection to be parsed.
|
||||
*
|
||||
* @return Parsed AlchemyPotion.
|
||||
*/
|
||||
private AlchemyPotion loadPotion(ConfigurationSection potion_section) {
|
||||
try {
|
||||
|
||||
|
||||
|
||||
String name = potion_section.getString("Name");
|
||||
if (name != null) {
|
||||
name = ChatColor.translateAlternateColorCodes('&', name);
|
||||
}
|
||||
|
||||
|
||||
PotionData data;
|
||||
if (!potion_section.contains("PotionData")) { // Backwards config compatability
|
||||
short dataValue = Short.parseShort(potion_section.getName());
|
||||
@ -130,7 +127,7 @@ public class PotionConfig extends ConfigLoader {
|
||||
ConfigurationSection potionData = potion_section.getConfigurationSection("PotionData");
|
||||
data = new PotionData(PotionType.valueOf(potionData.getString("PotionType", "WATER")), potionData.getBoolean("Extended", false), potionData.getBoolean("Upgraded", false));
|
||||
}
|
||||
|
||||
|
||||
Material material = Material.POTION;
|
||||
String mat = potion_section.getString("Material", null);
|
||||
if (mat != null) {
|
||||
@ -155,18 +152,16 @@ public class PotionConfig extends ConfigLoader {
|
||||
|
||||
if (type != null) {
|
||||
effects.add(new PotionEffect(type, duration, amplifier));
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
mcMMO.p.getLogger().warning("Failed to parse effect for potion " + name + ": " + effect);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Color color = null;
|
||||
if (potion_section.contains("Color")) {
|
||||
color = Color.fromRGB(potion_section.getInt("Color"));
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
color = this.generateColor(effects);
|
||||
}
|
||||
|
||||
@ -176,16 +171,14 @@ public class PotionConfig extends ConfigLoader {
|
||||
ItemStack ingredient = loadIngredient(child);
|
||||
if (ingredient != null) {
|
||||
children.put(ingredient, potion_section.getConfigurationSection("Children").getString(child));
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
mcMMO.p.getLogger().warning("Failed to parse child for potion " + name + ": " + child);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new AlchemyPotion(material, data, name, lore, effects, color, children);
|
||||
}
|
||||
catch (Exception e) {
|
||||
} catch (Exception e) {
|
||||
mcMMO.p.getLogger().warning("Failed to load Alchemy potion: " + potion_section.getName());
|
||||
return null;
|
||||
}
|
||||
@ -197,7 +190,6 @@ public class PotionConfig extends ConfigLoader {
|
||||
* Returns null if input cannot be parsed.
|
||||
*
|
||||
* @param ingredient String representing an ingredient.
|
||||
*
|
||||
* @return Parsed ingredient.
|
||||
*/
|
||||
private ItemStack loadIngredient(String ingredient) {
|
||||
@ -243,7 +235,7 @@ public class PotionConfig extends ConfigLoader {
|
||||
public AlchemyPotion getPotion(String name) {
|
||||
return potionMap.get(name);
|
||||
}
|
||||
|
||||
|
||||
public AlchemyPotion getPotion(ItemStack item) {
|
||||
for (AlchemyPotion potion : potionMap.values()) {
|
||||
if (potion.isSimilar(item)) {
|
||||
@ -252,7 +244,7 @@ public class PotionConfig extends ConfigLoader {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public Color generateColor(List<PotionEffect> effects) {
|
||||
if (effects != null && !effects.isEmpty()) {
|
||||
List<Color> colors = new ArrayList<Color>();
|
||||
@ -270,7 +262,7 @@ public class PotionConfig extends ConfigLoader {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public Color calculateAverageColor(List<Color> colors) {
|
||||
int red = 0;
|
||||
int green = 0;
|
||||
@ -280,8 +272,8 @@ public class PotionConfig extends ConfigLoader {
|
||||
green += color.getGreen();
|
||||
blue += color.getBlue();
|
||||
}
|
||||
Color color = Color.fromRGB(red/colors.size(), green/colors.size(), blue/colors.size());
|
||||
Color color = Color.fromRGB(red / colors.size(), green / colors.size(), blue / colors.size());
|
||||
return color;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user