2013-03-01 00:52:01 -05:00
|
|
|
package com.gmail.nossr50.config.mods;
|
|
|
|
|
2019-02-16 16:09:48 -08:00
|
|
|
import com.gmail.nossr50.config.Config;
|
2014-05-18 17:06:50 +02:00
|
|
|
import com.gmail.nossr50.datatypes.mods.CustomTool;
|
2013-12-14 14:27:50 +01:00
|
|
|
import com.gmail.nossr50.datatypes.skills.ItemType;
|
|
|
|
import com.gmail.nossr50.datatypes.skills.MaterialType;
|
2019-02-16 16:09:48 -08:00
|
|
|
import com.gmail.nossr50.mcMMO;
|
2013-10-07 10:23:04 -04:00
|
|
|
import com.gmail.nossr50.skills.repair.repairables.Repairable;
|
|
|
|
import com.gmail.nossr50.skills.repair.repairables.RepairableFactory;
|
2013-03-06 12:31:48 -05:00
|
|
|
import com.gmail.nossr50.util.skills.SkillUtils;
|
2019-01-14 22:11:58 -08:00
|
|
|
import org.bukkit.Material;
|
|
|
|
import org.bukkit.configuration.ConfigurationSection;
|
|
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Set;
|
2013-03-01 00:52:01 -05:00
|
|
|
|
2019-02-16 16:09:48 -08:00
|
|
|
public class CustomToolConfig extends Config {
|
|
|
|
public List<Material> customAxes = new ArrayList<Material>();
|
|
|
|
public List<Material> customBows = new ArrayList<Material>();
|
|
|
|
public List<Material> customHoes = new ArrayList<Material>();
|
2014-02-03 14:48:43 -05:00
|
|
|
public List<Material> customPickaxes = new ArrayList<Material>();
|
2019-02-16 16:09:48 -08:00
|
|
|
public List<Material> customShovels = new ArrayList<Material>();
|
|
|
|
public List<Material> customSwords = new ArrayList<Material>();
|
2014-02-03 14:48:43 -05:00
|
|
|
public HashMap<Material, CustomTool> customToolMap = new HashMap<Material, CustomTool>();
|
|
|
|
public List<Repairable> repairables = new ArrayList<Repairable>();
|
2019-02-16 16:09:48 -08:00
|
|
|
private boolean needsUpdate = false;
|
2013-03-01 00:52:01 -05:00
|
|
|
|
2014-02-03 14:48:43 -05:00
|
|
|
protected CustomToolConfig(String fileName) {
|
2019-02-16 16:09:48 -08:00
|
|
|
//super(McmmoCore.getDataFolderPath().getPath() + "mods", fileName, false);
|
|
|
|
super(mcMMO.p.getDataFolder().getPath() + "mods", fileName, false);
|
2013-03-01 00:52:01 -05:00
|
|
|
loadKeys();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void loadKeys() {
|
2013-10-18 10:01:59 -04:00
|
|
|
loadTool("Axes", customAxes);
|
|
|
|
loadTool("Bows", customBows);
|
|
|
|
loadTool("Hoes", customHoes);
|
|
|
|
loadTool("Pickaxes", customPickaxes);
|
|
|
|
loadTool("Shovels", customShovels);
|
|
|
|
loadTool("Swords", customSwords);
|
2013-10-08 13:10:09 -04:00
|
|
|
|
|
|
|
if (needsUpdate) {
|
|
|
|
needsUpdate = false;
|
|
|
|
backup();
|
|
|
|
}
|
2013-03-01 00:52:01 -05:00
|
|
|
}
|
|
|
|
|
2013-09-22 11:31:54 -04:00
|
|
|
private void loadTool(String toolType, List<Material> materialList) {
|
2013-10-18 10:01:59 -04:00
|
|
|
if (needsUpdate) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-03-01 00:52:01 -05:00
|
|
|
ConfigurationSection toolSection = config.getConfigurationSection(toolType);
|
|
|
|
|
|
|
|
if (toolSection == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Set<String> toolConfigSet = toolSection.getKeys(false);
|
|
|
|
|
|
|
|
for (String toolName : toolConfigSet) {
|
2013-10-08 13:10:09 -04:00
|
|
|
if (config.contains(toolType + "." + toolName + "." + ".ID")) {
|
|
|
|
needsUpdate = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-09-22 11:31:54 -04:00
|
|
|
Material toolMaterial = Material.matchMaterial(toolName);
|
2013-03-01 00:52:01 -05:00
|
|
|
|
2013-09-22 11:31:54 -04:00
|
|
|
if (toolMaterial == null) {
|
2013-09-25 10:42:19 -04:00
|
|
|
plugin.getLogger().warning("Invalid material name. This item will be skipped. - " + toolName);
|
2013-03-01 00:52:01 -05:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-02-16 16:09:48 -08:00
|
|
|
boolean repairable = getBooleanValue(toolType + "." + toolName + ".Repairable");
|
|
|
|
Material repairMaterial = Material.matchMaterial(getStringValue(toolType + "." + toolName + ".Repair_Material", ""));
|
2013-09-22 11:31:54 -04:00
|
|
|
|
2014-07-31 00:46:41 +02:00
|
|
|
if (repairable && (repairMaterial == null)) {
|
2013-09-25 10:42:19 -04:00
|
|
|
plugin.getLogger().warning("Incomplete repair information. This item will be unrepairable. - " + toolName);
|
2013-03-01 00:52:01 -05:00
|
|
|
repairable = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (repairable) {
|
2019-02-16 16:09:48 -08:00
|
|
|
byte repairData = (byte) getIntValue(toolType + "." + toolName + ".Repair_Material_Data_Value", -1);
|
2013-03-06 12:31:48 -05:00
|
|
|
int repairQuantity = SkillUtils.getRepairAndSalvageQuantities(new ItemStack(toolMaterial), repairMaterial, repairData);
|
2013-09-22 11:31:54 -04:00
|
|
|
|
|
|
|
if (repairQuantity == 0) {
|
2019-02-16 16:09:48 -08:00
|
|
|
repairQuantity = getIntValue(toolType + "." + toolName + ".Repair_Material_Quantity", 2);
|
2013-09-22 11:31:54 -04:00
|
|
|
}
|
|
|
|
|
2019-02-16 16:09:48 -08:00
|
|
|
String repairItemName = getStringValue(toolType + "." + toolName + ".Repair_Material_Pretty_Name");
|
|
|
|
int repairMinimumLevel = getIntValue(toolType + "." + toolName + ".Repair_MinimumLevel", 0);
|
|
|
|
double repairXpMultiplier = getDoubleValue(toolType + "." + toolName + ".Repair_XpMultiplier", 1);
|
2014-06-15 17:28:54 +02:00
|
|
|
|
2013-09-22 11:31:54 -04:00
|
|
|
short durability = toolMaterial.getMaxDurability();
|
|
|
|
|
|
|
|
if (durability == 0) {
|
2019-02-16 16:09:48 -08:00
|
|
|
durability = (short) getIntValue(toolType + "." + toolName + ".Durability", 60);
|
2013-09-22 11:31:54 -04:00
|
|
|
}
|
|
|
|
|
2014-06-15 17:31:50 +02:00
|
|
|
repairables.add(RepairableFactory.getRepairable(toolMaterial, repairMaterial, repairData, repairItemName, repairMinimumLevel, repairQuantity, durability, ItemType.TOOL, MaterialType.OTHER, repairXpMultiplier));
|
2013-03-01 00:52:01 -05:00
|
|
|
}
|
|
|
|
|
2019-02-16 16:09:48 -08:00
|
|
|
double multiplier = getDoubleValue(toolType + "." + toolName + ".XP_Modifier", 1.0);
|
|
|
|
boolean abilityEnabled = getBooleanValue(toolType + "." + toolName + ".Ability_Enabled", true);
|
|
|
|
int tier = getIntValue(toolType + "." + toolName + ".Tier", 1);
|
2013-09-22 11:31:54 -04:00
|
|
|
|
|
|
|
CustomTool tool = new CustomTool(tier, abilityEnabled, multiplier);
|
2013-03-01 00:52:01 -05:00
|
|
|
|
2013-09-22 11:31:54 -04:00
|
|
|
materialList.add(toolMaterial);
|
|
|
|
customToolMap.put(toolMaterial, tool);
|
2013-03-01 00:52:01 -05:00
|
|
|
}
|
|
|
|
}
|
2013-09-25 10:42:19 -04:00
|
|
|
}
|