new config pt 9

This commit is contained in:
nossr50
2019-02-16 16:09:48 -08:00
parent 2de87f7189
commit 9731b9cffb
164 changed files with 3195 additions and 2597 deletions

View File

@@ -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;
}
}

View File

@@ -1,166 +0,0 @@
package com.gmail.nossr50.config.skills.repair;
import com.gmail.nossr50.config.ConfigLoader;
import com.gmail.nossr50.datatypes.skills.ItemType;
import com.gmail.nossr50.datatypes.skills.MaterialType;
import com.gmail.nossr50.skills.repair.repairables.Repairable;
import com.gmail.nossr50.skills.repair.repairables.RepairableFactory;
import com.gmail.nossr50.util.ItemUtils;
import com.gmail.nossr50.util.skills.SkillUtils;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
public class RepairConfig extends ConfigLoader {
private List<Repairable> repairables;
public RepairConfig(String fileName) {
super(fileName);
loadKeys();
}
@Override
protected void loadKeys() {
repairables = new ArrayList<Repairable>();
ConfigurationSection section = config.getConfigurationSection("Repairables");
Set<String> keys = section.getKeys(false);
for (String key : keys) {
if (config.contains("Repairables." + key + ".ItemId")) {
backup();
return;
}
// Validate all the things!
List<String> reason = new ArrayList<String>();
// Item Material
Material itemMaterial = Material.matchMaterial(key);
if (itemMaterial == null) {
reason.add("Invalid material: " + key);
}
// Repair Material Type
MaterialType repairMaterialType = MaterialType.OTHER;
String repairMaterialTypeString = config.getString("Repairables." + key + ".MaterialType", "OTHER");
if (!config.contains("Repairables." + key + ".MaterialType") && itemMaterial != null) {
ItemStack repairItem = new ItemStack(itemMaterial);
if (ItemUtils.isWoodTool(repairItem)) {
repairMaterialType = MaterialType.WOOD;
}
else if (ItemUtils.isStoneTool(repairItem)) {
repairMaterialType = MaterialType.STONE;
}
else if (ItemUtils.isStringTool(repairItem)) {
repairMaterialType = MaterialType.STRING;
}
else if (ItemUtils.isLeatherArmor(repairItem)) {
repairMaterialType = MaterialType.LEATHER;
}
else if (ItemUtils.isIronArmor(repairItem) || ItemUtils.isIronTool(repairItem)) {
repairMaterialType = MaterialType.IRON;
}
else if (ItemUtils.isGoldArmor(repairItem) || ItemUtils.isGoldTool(repairItem)) {
repairMaterialType = MaterialType.GOLD;
}
else if (ItemUtils.isDiamondArmor(repairItem) || ItemUtils.isDiamondTool(repairItem)) {
repairMaterialType = MaterialType.DIAMOND;
}
}
else {
try {
repairMaterialType = MaterialType.valueOf(repairMaterialTypeString);
}
catch (IllegalArgumentException ex) {
reason.add(key + " has an invalid MaterialType of " + repairMaterialTypeString);
}
}
// Repair Material
String repairMaterialName = config.getString("Repairables." + key + ".RepairMaterial");
Material repairMaterial = (repairMaterialName == null ? repairMaterialType.getDefaultMaterial() : Material.matchMaterial(repairMaterialName));
if (repairMaterial == null) {
reason.add(key + " has an invalid repair material: " + repairMaterialName);
}
// Maximum Durability
short maximumDurability = (itemMaterial != null ? itemMaterial.getMaxDurability() : (short) config.getInt("Repairables." + key + ".MaximumDurability"));
if (maximumDurability <= 0) {
maximumDurability = (short) config.getInt("Repairables." + key + ".MaximumDurability");
}
if (maximumDurability <= 0) {
reason.add("Maximum durability of " + key + " must be greater than 0!");
}
// Item Type
ItemType repairItemType = ItemType.OTHER;
String repairItemTypeString = config.getString("Repairables." + key + ".ItemType", "OTHER");
if (!config.contains("Repairables." + key + ".ItemType") && itemMaterial != null) {
ItemStack repairItem = new ItemStack(itemMaterial);
if (ItemUtils.isMinecraftTool(repairItem)) {
repairItemType = ItemType.TOOL;
}
else if (ItemUtils.isArmor(repairItem)) {
repairItemType = ItemType.ARMOR;
}
}
else {
try {
repairItemType = ItemType.valueOf(repairItemTypeString);
}
catch (IllegalArgumentException ex) {
reason.add(key + " has an invalid ItemType of " + repairItemTypeString);
}
}
byte repairMetadata = (byte) config.getInt("Repairables." + key + ".RepairMaterialMetadata", -1);
int minimumLevel = config.getInt("Repairables." + key + ".MinimumLevel");
double xpMultiplier = config.getDouble("Repairables." + key + ".XpMultiplier", 1);
if (minimumLevel < 0) {
reason.add(key + " has an invalid MinimumLevel of " + minimumLevel);
}
// Minimum Quantity
int minimumQuantity = (itemMaterial != null ? SkillUtils.getRepairAndSalvageQuantities(new ItemStack(itemMaterial), repairMaterial, repairMetadata) : config.getInt("Repairables." + key + ".MinimumQuantity", 2));
if (minimumQuantity <= 0 && itemMaterial != null) {
minimumQuantity = config.getInt("Repairables." + key + ".MinimumQuantity", 2);
}
if (minimumQuantity <= 0) {
reason.add("Minimum quantity of " + key + " must be greater than 0!");
}
if (noErrorsInRepairable(reason)) {
Repairable repairable = RepairableFactory.getRepairable(itemMaterial, repairMaterial, repairMetadata, minimumLevel, minimumQuantity, maximumDurability, repairItemType, repairMaterialType, xpMultiplier);
repairables.add(repairable);
}
}
}
protected List<Repairable> getLoadedRepairables() {
return repairables == null ? new ArrayList<Repairable>() : repairables;
}
private boolean noErrorsInRepairable(List<String> issues) {
for (String issue : issues) {
plugin.getLogger().warning(issue);
}
return issues.isEmpty();
}
}

View File

@@ -1,42 +0,0 @@
package com.gmail.nossr50.config.skills.repair;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.skills.repair.repairables.Repairable;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
public class RepairConfigManager {
private final List<Repairable> repairables = new ArrayList<Repairable>();
public RepairConfigManager(mcMMO plugin) {
Pattern pattern = Pattern.compile("repair\\.(?:.+)\\.yml");
File dataFolder = plugin.getDataFolder();
File vanilla = new File(dataFolder, "repair.vanilla.yml");
if (!vanilla.exists()) {
plugin.saveResource("repair.vanilla.yml", false);
}
for (String fileName : dataFolder.list()) {
if (!pattern.matcher(fileName).matches()) {
continue;
}
File file = new File(dataFolder, fileName);
if (file.isDirectory()) {
continue;
}
RepairConfig rConfig = new RepairConfig(fileName);
repairables.addAll(rConfig.getLoadedRepairables());
}
}
public List<Repairable> getLoadedRepairables() {
return repairables;
}
}

View File

@@ -1,164 +0,0 @@
package com.gmail.nossr50.config.skills.salvage;
import com.gmail.nossr50.config.ConfigLoader;
import com.gmail.nossr50.datatypes.skills.ItemType;
import com.gmail.nossr50.datatypes.skills.MaterialType;
import com.gmail.nossr50.skills.salvage.salvageables.Salvageable;
import com.gmail.nossr50.skills.salvage.salvageables.SalvageableFactory;
import com.gmail.nossr50.util.ItemUtils;
import com.gmail.nossr50.util.skills.SkillUtils;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
public class SalvageConfig extends ConfigLoader {
private List<Salvageable> salvageables;
public SalvageConfig(String fileName) {
super(fileName);
loadKeys();
}
@Override
protected void loadKeys() {
salvageables = new ArrayList<Salvageable>();
ConfigurationSection section = config.getConfigurationSection("Salvageables");
Set<String> keys = section.getKeys(false);
for (String key : keys) {
// Validate all the things!
List<String> reason = new ArrayList<String>();
// Item Material
Material itemMaterial = Material.matchMaterial(key);
if (itemMaterial == null) {
reason.add("Invalid material: " + key);
}
// Salvage Material Type
MaterialType salvageMaterialType = MaterialType.OTHER;
String salvageMaterialTypeString = config.getString("Salvageables." + key + ".MaterialType", "OTHER");
if (!config.contains("Salvageables." + key + ".MaterialType") && itemMaterial != null) {
ItemStack salvageItem = new ItemStack(itemMaterial);
if (ItemUtils.isWoodTool(salvageItem)) {
salvageMaterialType = MaterialType.WOOD;
}
else if (ItemUtils.isStoneTool(salvageItem)) {
salvageMaterialType = MaterialType.STONE;
}
else if (ItemUtils.isStringTool(salvageItem)) {
salvageMaterialType = MaterialType.STRING;
}
else if (ItemUtils.isLeatherArmor(salvageItem)) {
salvageMaterialType = MaterialType.LEATHER;
}
else if (ItemUtils.isIronArmor(salvageItem) || ItemUtils.isIronTool(salvageItem)) {
salvageMaterialType = MaterialType.IRON;
}
else if (ItemUtils.isGoldArmor(salvageItem) || ItemUtils.isGoldTool(salvageItem)) {
salvageMaterialType = MaterialType.GOLD;
}
else if (ItemUtils.isDiamondArmor(salvageItem) || ItemUtils.isDiamondTool(salvageItem)) {
salvageMaterialType = MaterialType.DIAMOND;
}
}
else {
try {
salvageMaterialType = MaterialType.valueOf(salvageMaterialTypeString.replace(" ", "_").toUpperCase());
}
catch (IllegalArgumentException ex) {
reason.add(key + " has an invalid MaterialType of " + salvageMaterialTypeString);
}
}
// Salvage Material
String salvageMaterialName = config.getString("Salvageables." + key + ".SalvageMaterial");
Material salvageMaterial = (salvageMaterialName == null ? salvageMaterialType.getDefaultMaterial() : Material.matchMaterial(salvageMaterialName));
if (salvageMaterial == null) {
reason.add(key + " has an invalid salvage material: " + salvageMaterialName);
}
// Maximum Durability
short maximumDurability = (itemMaterial != null ? itemMaterial.getMaxDurability() : (short) config.getInt("Salvageables." + key + ".MaximumDurability"));
// Item Type
ItemType salvageItemType = ItemType.OTHER;
String salvageItemTypeString = config.getString("Salvageables." + key + ".ItemType", "OTHER");
if (!config.contains("Salvageables." + key + ".ItemType") && itemMaterial != null) {
ItemStack salvageItem = new ItemStack(itemMaterial);
if (ItemUtils.isMinecraftTool(salvageItem)) {
salvageItemType = ItemType.TOOL;
}
else if (ItemUtils.isArmor(salvageItem)) {
salvageItemType = ItemType.ARMOR;
}
}
else {
try {
salvageItemType = ItemType.valueOf(salvageItemTypeString.replace(" ", "_").toUpperCase());
}
catch (IllegalArgumentException ex) {
reason.add(key + " has an invalid ItemType of " + salvageItemTypeString);
}
}
byte salvageMetadata = (byte) config.getInt("Salvageables." + key + ".SalvageMaterialMetadata", -1);
int minimumLevel = config.getInt("Salvageables." + key + ".MinimumLevel");
double xpMultiplier = config.getDouble("Salvageables." + key + ".XpMultiplier", 1);
if (minimumLevel < 0) {
reason.add(key + " has an invalid MinimumLevel of " + minimumLevel);
}
// Maximum Quantity
int maximumQuantity = (itemMaterial != null ? SkillUtils.getRepairAndSalvageQuantities(new ItemStack(itemMaterial), salvageMaterial, salvageMetadata) : config.getInt("Salvageables." + key + ".MaximumQuantity", 2));
if (maximumQuantity <= 0 && itemMaterial != null) {
maximumQuantity = config.getInt("Salvageables." + key + ".MaximumQuantity", 1);
}
int configMaximumQuantity = config.getInt("Salvageables." + key + ".MaximumQuantity", -1);
if (configMaximumQuantity > 0) {
maximumQuantity = configMaximumQuantity;
}
if (maximumQuantity <= 0) {
reason.add("Maximum quantity of " + key + " must be greater than 0!");
}
if (noErrorsInSalvageable(reason)) {
Salvageable salvageable = SalvageableFactory.getSalvageable(itemMaterial, salvageMaterial, salvageMetadata, minimumLevel, maximumQuantity, maximumDurability, salvageItemType, salvageMaterialType, xpMultiplier);
salvageables.add(salvageable);
}
}
}
protected List<Salvageable> getLoadedSalvageables() {
return salvageables == null ? new ArrayList<Salvageable>() : salvageables;
}
private boolean noErrorsInSalvageable(List<String> issues) {
if (!issues.isEmpty()) {
plugin.getLogger().warning("Errors have been found in: " + fileName);
plugin.getLogger().warning("The following issues were found:");
}
for (String issue : issues) {
plugin.getLogger().warning(issue);
}
return issues.isEmpty();
}
}

View File

@@ -1,42 +0,0 @@
package com.gmail.nossr50.config.skills.salvage;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.skills.salvage.salvageables.Salvageable;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
public class SalvageConfigManager {
private final List<Salvageable> salvageables = new ArrayList<Salvageable>();
public SalvageConfigManager(mcMMO plugin) {
Pattern pattern = Pattern.compile("salvage\\.(?:.+)\\.yml");
File dataFolder = plugin.getDataFolder();
File vanilla = new File(dataFolder, "salvage.vanilla.yml");
if (!vanilla.exists()) {
plugin.saveResource("salvage.vanilla.yml", false);
}
for (String fileName : dataFolder.list()) {
if (!pattern.matcher(fileName).matches()) {
continue;
}
File file = new File(dataFolder, fileName);
if (file.isDirectory()) {
continue;
}
SalvageConfig salvageConfig = new SalvageConfig(fileName);
salvageables.addAll(salvageConfig.getLoadedSalvageables());
}
}
public List<Salvageable> getLoadedSalvageables() {
return salvageables;
}
}