2012-05-04 20:04:42 +02:00
|
|
|
package com.gmail.nossr50.config.mods;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
import org.bukkit.configuration.ConfigurationSection;
|
|
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
|
|
|
|
import com.gmail.nossr50.mcMMO;
|
2012-05-17 06:24:33 +02:00
|
|
|
import com.gmail.nossr50.datatypes.mods.CustomItem;
|
2012-05-04 20:04:42 +02:00
|
|
|
import com.gmail.nossr50.datatypes.mods.CustomTool;
|
|
|
|
|
2012-05-17 16:26:21 +02:00
|
|
|
public class CustomToolsConfig extends ModConfigLoader {
|
|
|
|
private static CustomToolsConfig instance;
|
2012-05-04 20:04:42 +02:00
|
|
|
|
2012-05-17 16:26:21 +02:00
|
|
|
public static CustomToolsConfig getInstance() {
|
2012-05-04 20:04:42 +02:00
|
|
|
if (instance == null) {
|
2012-05-17 16:26:21 +02:00
|
|
|
instance = new CustomToolsConfig(mcMMO.p);
|
2012-05-04 20:04:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
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>();
|
|
|
|
public List<CustomItem> customItems = new ArrayList<CustomItem>();
|
|
|
|
|
2012-05-17 16:26:21 +02:00
|
|
|
private CustomToolsConfig(mcMMO plugin) {
|
2012-05-15 22:12:59 +02:00
|
|
|
super(plugin, "tools.yml");
|
2012-05-04 20:04:42 +02:00
|
|
|
config = plugin.getToolsConfig();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-05-05 19:02:36 +02:00
|
|
|
public void load() {
|
2012-05-04 20:04:42 +02:00
|
|
|
if (!configFile.exists()) {
|
|
|
|
dataFolder.mkdir();
|
|
|
|
plugin.saveToolsConfig();
|
|
|
|
}
|
|
|
|
|
|
|
|
addDefaults();
|
|
|
|
loadKeys();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void loadKeys() {
|
|
|
|
plugin.getLogger().info("Loading mcMMO tools.yml File...");
|
|
|
|
|
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);
|
|
|
|
Set<String> toolConfigSet = toolSection.getKeys(false);
|
|
|
|
Iterator<String> iterator = toolConfigSet.iterator();
|
|
|
|
|
|
|
|
while (iterator.hasNext()) {
|
|
|
|
String toolName = iterator.next();
|
|
|
|
|
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) {
|
|
|
|
ItemStack repairMaterial = new ItemStack(repairID, 1, (short) 0, repairData);
|
2012-05-18 03:19:17 +02:00
|
|
|
tool = new CustomTool(durability, repairMaterial, repairQuantity, repairable, tier, abilityEnabled, multiplier, id);
|
2012-05-04 20:04:42 +02:00
|
|
|
}
|
|
|
|
else {
|
2012-05-18 03:19:17 +02:00
|
|
|
tool = new CustomTool(durability, null, 0, repairable, tier, abilityEnabled, multiplier, id);
|
2012-05-04 20:04:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
idList.add(id);
|
2012-05-15 16:44:57 +02:00
|
|
|
customIDs.add(id);
|
2012-05-15 22:12:59 +02:00
|
|
|
customItems.add(tool);
|
2012-05-04 20:04:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|