mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-25 14:46:46 +01:00
Converting salvage config to the new system
This commit is contained in:
parent
c14b949b0a
commit
4bfa790be9
@ -33,9 +33,9 @@ public class RepairConfig extends ConfigCollection {
|
|||||||
public static final String MINIMUM_LEVEL = "MinimumLevel";
|
public static final String MINIMUM_LEVEL = "MinimumLevel";
|
||||||
public static final String MINIMUM_QUANTITY = "MinimumQuantity";
|
public static final String MINIMUM_QUANTITY = "MinimumQuantity";
|
||||||
|
|
||||||
public RepairConfig(String fileName) {
|
public RepairConfig(String fileName, boolean merge) {
|
||||||
//super(McmmoCore.getDataFolderPath().getAbsoluteFile(), fileName, false);
|
//super(McmmoCore.getDataFolderPath().getAbsoluteFile(), fileName, false);
|
||||||
super(mcMMO.p.getDataFolder().getAbsoluteFile(), fileName, false);
|
super(mcMMO.p.getDataFolder().getAbsoluteFile(), fileName, merge);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -108,10 +108,10 @@ public class RepairConfig extends ConfigCollection {
|
|||||||
else {
|
else {
|
||||||
//If a material cannot be matched, try matching the material to its repair material type string from the config
|
//If a material cannot be matched, try matching the material to its repair material type string from the config
|
||||||
try {
|
try {
|
||||||
repairMaterialType = MaterialType.valueOf(repairMaterialTypeString);
|
repairMaterialType = MaterialType.valueOf(repairMaterialTypeString.toUpperCase());
|
||||||
}
|
}
|
||||||
catch (IllegalArgumentException ex) {
|
catch (IllegalArgumentException ex) {
|
||||||
errorMessages.add(key + " has an invalid " + MATERIAL_TYPE + " of " + repairMaterialTypeString);
|
errorMessages.add("Repair Config: " + key + " has an invalid " + MATERIAL_TYPE + " of " + repairMaterialTypeString);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -234,16 +234,4 @@ public class RepairConfig extends ConfigCollection {
|
|||||||
private String getRepairMaterialStringName(String key) {
|
private String getRepairMaterialStringName(String key) {
|
||||||
return getStringValue(REPAIRABLES, key, REPAIR_MATERIAL);
|
return getStringValue(REPAIRABLES, key, REPAIR_MATERIAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if there are any errors for this repairable and if there are reports them to console
|
|
||||||
* @param issues errors related to loading a repairable
|
|
||||||
* @return returns true if there are no errors for this repairable
|
|
||||||
*/
|
|
||||||
private boolean noErrorsInRepairable(List<String> issues) {
|
|
||||||
|
|
||||||
|
|
||||||
return issues.isEmpty();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import com.gmail.nossr50.skills.salvage.salvageables.SalvageableFactory;
|
|||||||
import com.gmail.nossr50.util.ItemUtils;
|
import com.gmail.nossr50.util.ItemUtils;
|
||||||
import com.gmail.nossr50.util.skills.SkillUtils;
|
import com.gmail.nossr50.util.skills.SkillUtils;
|
||||||
import ninja.leaping.configurate.commented.CommentedConfigurationNode;
|
import ninja.leaping.configurate.commented.CommentedConfigurationNode;
|
||||||
|
import ninja.leaping.configurate.objectmapping.ObjectMappingException;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
@ -19,9 +20,19 @@ import java.util.Set;
|
|||||||
|
|
||||||
public class SalvageConfig extends ConfigCollection {
|
public class SalvageConfig extends ConfigCollection {
|
||||||
|
|
||||||
public SalvageConfig(String fileName) {
|
public static final String SALVAGEABLES = "Salvageables";
|
||||||
|
public static final String MATERIAL_TYPE = "MaterialType";
|
||||||
|
public static final String SALVAGE_MATERIAL = "SalvageMaterial";
|
||||||
|
public static final String MAXIMUM_DURABILITY = "MaximumDurability";
|
||||||
|
public static final String ITEM_TYPE = "ItemType";
|
||||||
|
public static final String METADATA = "Metadata";
|
||||||
|
public static final String MINIMUM_LEVEL = "MinimumLevel";
|
||||||
|
public static final String XP_MULTIPLIER = "XpMultiplier";
|
||||||
|
public static final String MAXIMUM_QUANTITY = "MaximumQuantity";
|
||||||
|
|
||||||
|
public SalvageConfig(String fileName, boolean merge) {
|
||||||
//super(McmmoCore.getDataFolderPath().getAbsoluteFile(), fileName, false);
|
//super(McmmoCore.getDataFolderPath().getAbsoluteFile(), fileName, false);
|
||||||
super(mcMMO.p.getDataFolder().getAbsoluteFile(), fileName, false);
|
super(mcMMO.p.getDataFolder().getAbsoluteFile(), fileName, merge);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -36,25 +47,34 @@ public class SalvageConfig extends ConfigCollection {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void register() {
|
public void register() {
|
||||||
CommentedConfigurationNode section = getUserRootNode().getNode("Salvageables");
|
|
||||||
Set<String> keys = section.getKeys(false);
|
try {
|
||||||
|
//Grab the "keys" under the Repairables node
|
||||||
|
ArrayList<String> keys = new ArrayList<>(getStringValueList(SALVAGEABLES));
|
||||||
|
|
||||||
for (String key : keys) {
|
for (String key : keys) {
|
||||||
// Validate all the things!
|
// Validate all the things!
|
||||||
List<String> reason = new ArrayList<String>();
|
List<String> errorMessages = new ArrayList<String>();
|
||||||
|
|
||||||
// ItemStack Material
|
// ItemStack Material
|
||||||
Material itemMaterial = Material.matchMaterial(key);
|
Material itemMaterial = Material.matchMaterial(key);
|
||||||
|
|
||||||
if (itemMaterial == null) {
|
if (itemMaterial == null) {
|
||||||
reason.add("Invalid material: " + key);
|
errorMessages.add("Salvage Config: Invalid material - " + key);
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Salvage Material Type
|
// Salvage Material Type
|
||||||
MaterialType salvageMaterialType = MaterialType.OTHER;
|
MaterialType salvageMaterialType = MaterialType.OTHER;
|
||||||
String salvageMaterialTypeString = getStringValue("Salvageables." + key + ".MaterialType", "OTHER");
|
|
||||||
|
|
||||||
if (!config.contains("Salvageables." + key + ".MaterialType") && itemMaterial != null) {
|
String salvageMaterialTypeString;
|
||||||
|
|
||||||
|
if(hasNode(SALVAGEABLES, key, MATERIAL_TYPE))
|
||||||
|
salvageMaterialTypeString = getStringValue(SALVAGEABLES, key, MATERIAL_TYPE);
|
||||||
|
else
|
||||||
|
salvageMaterialTypeString = "OTHER";
|
||||||
|
|
||||||
|
if (!hasNode(SALVAGEABLES, key, MATERIAL_TYPE)) {
|
||||||
ItemStack salvageItem = new ItemStack(itemMaterial);
|
ItemStack salvageItem = new ItemStack(itemMaterial);
|
||||||
|
|
||||||
if (ItemUtils.isWoodTool(salvageItem)) {
|
if (ItemUtils.isWoodTool(salvageItem)) {
|
||||||
@ -76,26 +96,33 @@ public class SalvageConfig extends ConfigCollection {
|
|||||||
try {
|
try {
|
||||||
salvageMaterialType = MaterialType.valueOf(salvageMaterialTypeString.replace(" ", "_").toUpperCase());
|
salvageMaterialType = MaterialType.valueOf(salvageMaterialTypeString.replace(" ", "_").toUpperCase());
|
||||||
} catch (IllegalArgumentException ex) {
|
} catch (IllegalArgumentException ex) {
|
||||||
reason.add(key + " has an invalid MaterialType of " + salvageMaterialTypeString);
|
errorMessages.add("Salvage Config: " + key + " has an invalid MaterialType of " + salvageMaterialTypeString);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Salvage Material
|
// Salvage Material
|
||||||
String salvageMaterialName = getStringValue("Salvageables." + key + ".SalvageMaterial");
|
String salvageMaterialName = getStringValue(SALVAGEABLES, key, SALVAGE_MATERIAL);
|
||||||
Material salvageMaterial = (salvageMaterialName == null ? salvageMaterialType.getDefaultMaterial() : Material.matchMaterial(salvageMaterialName));
|
Material salvageMaterial = (salvageMaterialName == null ? salvageMaterialType.getDefaultMaterial() : Material.matchMaterial(salvageMaterialName));
|
||||||
|
|
||||||
if (salvageMaterial == null) {
|
if (salvageMaterial == null) {
|
||||||
reason.add(key + " has an invalid salvage material: " + salvageMaterialName);
|
errorMessages.add(key + " has an invalid salvage material: " + salvageMaterialName);
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Maximum Durability
|
// Maximum Durability
|
||||||
short maximumDurability = (itemMaterial != null ? itemMaterial.getMaxDurability() : (short) getIntValue("Salvageables." + key + ".MaximumDurability"));
|
short maximumDurability = itemMaterial.getMaxDurability();
|
||||||
|
|
||||||
// ItemStack Type
|
// ItemStack Type
|
||||||
ItemType salvageItemType = ItemType.OTHER;
|
ItemType salvageItemType = ItemType.OTHER;
|
||||||
String salvageItemTypeString = getStringValue("Salvageables." + key + ".ItemType", "OTHER");
|
|
||||||
|
|
||||||
if (!config.contains("Salvageables." + key + ".ItemType") && itemMaterial != null) {
|
String salvageItemTypeString;
|
||||||
|
|
||||||
|
if(hasNode(SALVAGEABLES, key, ITEM_TYPE))
|
||||||
|
salvageItemTypeString = getStringValue(SALVAGEABLES, key, ITEM_TYPE);
|
||||||
|
else
|
||||||
|
salvageItemTypeString = "OTHER";
|
||||||
|
|
||||||
|
if (!hasNode(SALVAGEABLES, key, ITEM_TYPE)) {
|
||||||
ItemStack salvageItem = new ItemStack(itemMaterial);
|
ItemStack salvageItem = new ItemStack(itemMaterial);
|
||||||
|
|
||||||
if (ItemUtils.isMinecraftTool(salvageItem)) {
|
if (ItemUtils.isMinecraftTool(salvageItem)) {
|
||||||
@ -107,52 +134,52 @@ public class SalvageConfig extends ConfigCollection {
|
|||||||
try {
|
try {
|
||||||
salvageItemType = ItemType.valueOf(salvageItemTypeString.replace(" ", "_").toUpperCase());
|
salvageItemType = ItemType.valueOf(salvageItemTypeString.replace(" ", "_").toUpperCase());
|
||||||
} catch (IllegalArgumentException ex) {
|
} catch (IllegalArgumentException ex) {
|
||||||
reason.add(key + " has an invalid ItemType of " + salvageItemTypeString);
|
errorMessages.add("Salvage Config: " + key + " has an invalid " + ITEM_TYPE + " of " + salvageItemTypeString);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
byte salvageMetadata = (byte) getIntValue("Salvageables." + key + ".SalvageMaterialMetadata", -1);
|
byte salvageMetadata = -1;
|
||||||
int minimumLevel = getIntValue("Salvageables." + key + ".MinimumLevel");
|
|
||||||
double xpMultiplier = getDoubleValue("Salvageables." + key + ".XpMultiplier", 1);
|
|
||||||
|
|
||||||
if (minimumLevel < 0) {
|
if(hasNode(SALVAGEABLES, key, SALVAGE_MATERIAL, METADATA))
|
||||||
reason.add(key + " has an invalid MinimumLevel of " + minimumLevel);
|
salvageMetadata = (byte) getIntValue(SALVAGEABLES, key, SALVAGE_MATERIAL, METADATA);
|
||||||
}
|
|
||||||
|
int minimumLevel = getIntValue(SALVAGEABLES, key, MINIMUM_LEVEL);
|
||||||
|
double xpMultiplier = 1;
|
||||||
|
|
||||||
|
if(hasNode(SALVAGEABLES, key, XP_MULTIPLIER))
|
||||||
|
xpMultiplier = getDoubleValue(SALVAGEABLES, key, XP_MULTIPLIER);
|
||||||
|
|
||||||
// Maximum Quantity
|
// Maximum Quantity
|
||||||
int maximumQuantity = (itemMaterial != null ? SkillUtils.getRepairAndSalvageQuantities(new ItemStack(itemMaterial), salvageMaterial, salvageMetadata) : getIntValue("Salvageables." + key + ".MaximumQuantity", 2));
|
int maximumQuantity = SkillUtils.getRepairAndSalvageQuantities(new ItemStack(itemMaterial), salvageMaterial, salvageMetadata);
|
||||||
|
|
||||||
if (maximumQuantity <= 0 && itemMaterial != null) {
|
if(hasNode(SALVAGEABLES, key, MAXIMUM_QUANTITY))
|
||||||
maximumQuantity = getIntValue("Salvageables." + key + ".MaximumQuantity", 1);
|
maximumQuantity = getIntValue(SALVAGEABLES, key, MAXIMUM_QUANTITY);
|
||||||
}
|
|
||||||
|
|
||||||
int configMaximumQuantity = getIntValue("Salvageables." + key + ".MaximumQuantity", -1);
|
|
||||||
|
|
||||||
if (configMaximumQuantity > 0) {
|
/*
|
||||||
maximumQuantity = configMaximumQuantity;
|
* VALIDATE
|
||||||
}
|
*/
|
||||||
|
|
||||||
if (maximumQuantity <= 0) {
|
if(minimumLevel < 0)
|
||||||
reason.add("Maximum quantity of " + key + " must be greater than 0!");
|
minimumLevel = 0;
|
||||||
}
|
|
||||||
|
if(maximumQuantity < 0)
|
||||||
|
maximumQuantity = 1;
|
||||||
|
|
||||||
|
if(xpMultiplier < 0)
|
||||||
|
xpMultiplier = 0;
|
||||||
|
|
||||||
if (noErrorsInSalvageable(reason)) {
|
|
||||||
Salvageable salvageable = SalvageableFactory.getSalvageable(itemMaterial, salvageMaterial, salvageMetadata, minimumLevel, maximumQuantity, maximumDurability, salvageItemType, salvageMaterialType, xpMultiplier);
|
Salvageable salvageable = SalvageableFactory.getSalvageable(itemMaterial, salvageMaterial, salvageMetadata, minimumLevel, maximumQuantity, maximumDurability, salvageItemType, salvageMaterialType, xpMultiplier);
|
||||||
genericCollection.add(salvageable);
|
genericCollection.add(salvageable);
|
||||||
}
|
|
||||||
|
for (String issue : errorMessages) {
|
||||||
|
mcMMO.p.getLogger().warning(issue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean noErrorsInSalvageable(List<String> issues) {
|
} catch (ObjectMappingException e) {
|
||||||
if (!issues.isEmpty()) {
|
e.printStackTrace();
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user