2013-03-01 00:52:01 -05:00
|
|
|
package com.gmail.nossr50.config.mods;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Set;
|
|
|
|
|
2013-09-19 11:02:47 -04:00
|
|
|
import org.bukkit.Material;
|
2013-03-01 00:52:01 -05:00
|
|
|
import org.bukkit.configuration.ConfigurationSection;
|
2013-09-22 11:31:54 -04:00
|
|
|
import org.bukkit.inventory.ItemStack;
|
2013-03-01 00:52:01 -05:00
|
|
|
|
|
|
|
import com.gmail.nossr50.config.ConfigLoader;
|
|
|
|
import com.gmail.nossr50.datatypes.mods.CustomTool;
|
2013-09-22 11:31:54 -04:00
|
|
|
import com.gmail.nossr50.skills.repair.Repair;
|
2013-10-07 10:23:04 -04:00
|
|
|
import com.gmail.nossr50.skills.repair.repairables.RepairItemType;
|
|
|
|
import com.gmail.nossr50.skills.repair.repairables.RepairMaterialType;
|
|
|
|
import com.gmail.nossr50.skills.repair.repairables.Repairable;
|
|
|
|
import com.gmail.nossr50.skills.repair.repairables.RepairableFactory;
|
2013-03-01 00:52:01 -05:00
|
|
|
|
|
|
|
public class CustomToolConfig extends ConfigLoader {
|
|
|
|
private static CustomToolConfig instance;
|
2013-10-08 13:10:09 -04:00
|
|
|
|
|
|
|
private boolean needsUpdate = false;
|
|
|
|
|
2013-03-01 00:52:01 -05:00
|
|
|
private List<Repairable> repairables;
|
2013-08-23 14:52:21 -04:00
|
|
|
|
2013-09-25 10:42:19 -04:00
|
|
|
private List<Material> customAxes = new ArrayList<Material>();
|
|
|
|
private List<Material> customBows = new ArrayList<Material>();
|
|
|
|
private List<Material> customHoes = new ArrayList<Material>();
|
|
|
|
private List<Material> customPickaxes = new ArrayList<Material>();
|
|
|
|
private List<Material> customShovels = new ArrayList<Material>();
|
|
|
|
private List<Material> customSwords = new ArrayList<Material>();
|
2013-08-23 14:52:21 -04:00
|
|
|
|
2013-09-25 10:42:19 -04:00
|
|
|
private HashMap<Material, CustomTool> customToolMap = new HashMap<Material, CustomTool>();
|
2013-03-01 00:52:01 -05:00
|
|
|
|
|
|
|
private CustomToolConfig() {
|
2013-10-07 10:32:40 -04:00
|
|
|
super("mods", "tools.yml");
|
2013-03-01 00:52:01 -05:00
|
|
|
loadKeys();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static CustomToolConfig getInstance() {
|
|
|
|
if (instance == null) {
|
|
|
|
instance = new CustomToolConfig();
|
|
|
|
}
|
|
|
|
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
public List<Repairable> getLoadedRepairables() {
|
|
|
|
if (repairables == null) {
|
|
|
|
return new ArrayList<Repairable>();
|
|
|
|
}
|
|
|
|
|
|
|
|
return repairables;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void loadKeys() {
|
|
|
|
repairables = new ArrayList<Repairable>();
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-09-22 11:31:54 -04:00
|
|
|
boolean repairable = config.getBoolean(toolType + "." + toolName + ".Repairable");
|
|
|
|
Material repairMaterial = Material.matchMaterial(config.getString(toolType + "." + toolName + ".Repair_Material", ""));
|
|
|
|
|
|
|
|
if (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) {
|
2013-09-22 11:31:54 -04:00
|
|
|
byte repairData = (byte) config.getInt(toolType + "." + toolName + ".Repair_Material_Data_Value", -1);
|
|
|
|
int repairQuantity = Repair.getRepairAndSalvageQuantities(new ItemStack(toolMaterial), repairMaterial, repairData);
|
|
|
|
|
|
|
|
if (repairQuantity == 0) {
|
|
|
|
repairQuantity = config.getInt(toolType + "." + toolName + ".Repair_Material_Data_Quantity", 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
short durability = toolMaterial.getMaxDurability();
|
|
|
|
|
|
|
|
if (durability == 0) {
|
|
|
|
durability = (short) config.getInt(toolType + "." + toolName + ".Durability", 60);
|
|
|
|
}
|
|
|
|
|
|
|
|
repairables.add(RepairableFactory.getRepairable(toolMaterial, repairMaterial, repairData, 0, repairQuantity, durability, RepairItemType.TOOL, RepairMaterialType.OTHER, 1.0));
|
2013-03-01 00:52:01 -05:00
|
|
|
}
|
|
|
|
|
2013-09-22 11:31:54 -04:00
|
|
|
double multiplier = config.getDouble(toolType + "." + toolName + ".XP_Modifier", 1.0);
|
|
|
|
boolean abilityEnabled = config.getBoolean(toolType + "." + toolName + ".Ability_Enabled", true);
|
|
|
|
int tier = config.getInt(toolType + "." + toolName + ".Tier", 1);
|
|
|
|
|
|
|
|
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-22 11:31:54 -04:00
|
|
|
|
2013-09-25 10:42:19 -04:00
|
|
|
public boolean isCustomAxe(Material material) {
|
|
|
|
return customAxes.contains(material);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isCustomBow(Material material) {
|
|
|
|
return customBows.contains(material);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isCustomHoe(Material material) {
|
|
|
|
return customHoes.contains(material);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isCustomPickaxe(Material material) {
|
|
|
|
return customPickaxes.contains(material);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isCustomShovel(Material material) {
|
|
|
|
return customShovels.contains(material);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isCustomSword(Material material) {
|
|
|
|
return customSwords.contains(material);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isCustomTool(Material material) {
|
|
|
|
return customToolMap.containsKey(material);
|
|
|
|
}
|
|
|
|
|
|
|
|
public CustomTool getCustomTool(Material material) {
|
|
|
|
return customToolMap.get(material);
|
|
|
|
}
|
|
|
|
}
|