2013-01-30 17:35:33 +01:00
|
|
|
package com.gmail.nossr50.mods.config;
|
2012-05-04 20:04:42 +02:00
|
|
|
|
|
|
|
import java.util.ArrayList;
|
2012-05-18 20:29:53 +02:00
|
|
|
import java.util.HashMap;
|
2012-05-04 20:04:42 +02:00
|
|
|
import java.util.List;
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
import org.bukkit.configuration.ConfigurationSection;
|
|
|
|
|
2012-07-03 21:57:24 +02:00
|
|
|
import com.gmail.nossr50.config.ConfigLoader;
|
2013-01-30 17:35:33 +01:00
|
|
|
import com.gmail.nossr50.mods.datatypes.CustomTool;
|
2012-05-22 13:56:48 +02:00
|
|
|
import com.gmail.nossr50.skills.repair.Repairable;
|
2012-05-22 14:21:05 +02:00
|
|
|
import com.gmail.nossr50.skills.repair.RepairableFactory;
|
2012-05-04 20:04:42 +02:00
|
|
|
|
2012-07-03 21:57:24 +02:00
|
|
|
public class CustomToolsConfig extends ConfigLoader {
|
2012-05-17 16:26:21 +02:00
|
|
|
private static CustomToolsConfig instance;
|
2012-05-22 13:56:48 +02:00
|
|
|
private List<Repairable> repairables;
|
2012-05-04 20:04:42 +02:00
|
|
|
public List<Integer> customAxeIDs = new ArrayList<Integer>();
|
|
|
|
public List<Integer> customBowIDs = new ArrayList<Integer>();
|
|
|
|
public List<Integer> customHoeIDs = new ArrayList<Integer>();
|
|
|
|
public List<Integer> customPickaxeIDs = new ArrayList<Integer>();
|
|
|
|
public List<Integer> customShovelIDs = new ArrayList<Integer>();
|
|
|
|
public List<Integer> customSwordIDs = new ArrayList<Integer>();
|
2012-05-17 06:24:33 +02:00
|
|
|
public List<Integer> customIDs = new ArrayList<Integer>();
|
2012-05-18 20:29:53 +02:00
|
|
|
public List<CustomTool> customToolList = new ArrayList<CustomTool>();
|
|
|
|
public HashMap<Integer, CustomTool> customTools = new HashMap<Integer, CustomTool>();
|
2012-05-17 06:24:33 +02:00
|
|
|
|
2012-07-03 21:57:24 +02:00
|
|
|
private CustomToolsConfig() {
|
|
|
|
super("ModConfigs", "tools.yml");
|
2012-07-03 23:29:26 +02:00
|
|
|
loadKeys();
|
2012-07-03 21:57:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static CustomToolsConfig getInstance() {
|
|
|
|
if (instance == null) {
|
|
|
|
instance = new CustomToolsConfig();
|
|
|
|
}
|
|
|
|
|
|
|
|
return instance;
|
2012-05-04 20:04:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void loadKeys() {
|
2012-05-22 13:56:48 +02:00
|
|
|
repairables = new ArrayList<Repairable>();
|
2012-05-04 20:04:42 +02:00
|
|
|
|
2012-05-15 22:12:59 +02:00
|
|
|
loadTool("Axes", customAxeIDs);
|
|
|
|
loadTool("Bows", customBowIDs);
|
|
|
|
loadTool("Hoes", customHoeIDs);
|
|
|
|
loadTool("Pickaxes", customPickaxeIDs);
|
|
|
|
loadTool("Shovels", customShovelIDs);
|
|
|
|
loadTool("Swords", customSwordIDs);
|
2012-05-04 20:04:42 +02:00
|
|
|
}
|
|
|
|
|
2012-05-15 22:12:59 +02:00
|
|
|
private void loadTool(String toolType, List<Integer> idList) {
|
2012-05-04 20:04:42 +02:00
|
|
|
ConfigurationSection toolSection = config.getConfigurationSection(toolType);
|
2012-10-31 02:12:50 +01:00
|
|
|
|
2013-01-10 05:03:17 +01:00
|
|
|
if (toolSection == null)
|
2012-10-31 02:12:50 +01:00
|
|
|
return;
|
|
|
|
|
2012-05-04 20:04:42 +02:00
|
|
|
Set<String> toolConfigSet = toolSection.getKeys(false);
|
|
|
|
|
2013-01-10 04:18:41 +01:00
|
|
|
for (String toolName : toolConfigSet) {
|
2012-05-15 22:12:59 +02:00
|
|
|
int id = config.getInt(toolType + "." + toolName + ".ID", 0);
|
2012-05-04 20:04:42 +02:00
|
|
|
double multiplier = config.getDouble(toolType + "." + toolName + ".XP_Modifier", 1.0);
|
2012-05-15 16:44:57 +02:00
|
|
|
boolean abilityEnabled = config.getBoolean(toolType + "." + toolName + ".Ability_Enabled", true);
|
2012-05-18 03:19:17 +02:00
|
|
|
int tier = config.getInt(toolType + "." + toolName + ".Tier", 1);
|
2012-05-04 20:04:42 +02:00
|
|
|
boolean repairable = config.getBoolean(toolType + "." + toolName + ".Repairable");
|
2012-05-15 16:44:57 +02:00
|
|
|
int repairID = config.getInt(toolType + "." + toolName + ".Repair_Material_ID", 0);
|
|
|
|
byte repairData = (byte) config.getInt(toolType + "." + toolName + ".Repair_Material_Data_Value", 0);
|
|
|
|
int repairQuantity = config.getInt(toolType + "." + toolName + ".Repair_Material_Quantity", 0);
|
|
|
|
short durability = (short) config.getInt(toolType + "." + toolName + ".Durability", 0);
|
2012-05-04 20:04:42 +02:00
|
|
|
|
|
|
|
if (id == 0) {
|
|
|
|
plugin.getLogger().warning("Missing ID. This item will be skipped.");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-05-15 22:12:59 +02:00
|
|
|
if (repairable && (repairID == 0 || repairQuantity == 0 || durability == 0)) {
|
2012-05-04 20:04:42 +02:00
|
|
|
plugin.getLogger().warning("Incomplete repair information. This item will be unrepairable.");
|
|
|
|
repairable = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
CustomTool tool;
|
|
|
|
|
|
|
|
if (repairable) {
|
2012-05-22 14:21:05 +02:00
|
|
|
repairables.add(RepairableFactory.getRepairable(id, repairID, repairData, repairQuantity, durability));
|
2012-05-04 20:04:42 +02:00
|
|
|
}
|
|
|
|
|
2012-05-27 20:31:37 +02:00
|
|
|
tool = new CustomTool(tier, abilityEnabled, multiplier, durability, id);
|
2012-05-22 14:37:32 +02:00
|
|
|
|
2012-05-04 20:04:42 +02:00
|
|
|
idList.add(id);
|
2012-05-15 16:44:57 +02:00
|
|
|
customIDs.add(id);
|
2012-05-18 20:29:53 +02:00
|
|
|
customToolList.add(tool);
|
|
|
|
customTools.put(id, tool);
|
2012-05-04 20:04:42 +02:00
|
|
|
}
|
|
|
|
}
|
2012-05-22 13:56:48 +02:00
|
|
|
|
|
|
|
public List<Repairable> getLoadedRepairables() {
|
2013-01-10 05:03:17 +01:00
|
|
|
if (repairables == null) return new ArrayList<Repairable>();
|
2012-05-22 13:56:48 +02:00
|
|
|
return repairables;
|
|
|
|
}
|
2012-05-04 20:04:42 +02:00
|
|
|
}
|