Custom armor can now be repaired.

This commit is contained in:
GJ
2012-05-15 16:12:59 -04:00
parent e84a9643f8
commit bc642deebd
13 changed files with 460 additions and 95 deletions

View File

@ -57,6 +57,7 @@ public class Config extends ConfigLoader {
/* SMP Mods */
public boolean getToolModsEnabled() { return config.getBoolean("Mods.Tool_Mods_Enabled", false); }
public boolean getArmorModsEnabled() { return config.getBoolean("Mods.Tool_Mods_Enabled", false); }
public boolean getBlockModsEnabled() { return config.getBoolean("Mods.Block_Mods_Enabled", false); }
/* Commands */

View File

@ -0,0 +1,96 @@
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;
import com.gmail.nossr50.datatypes.mods.CustomItem;
public class LoadCustomArmor extends ModConfigLoader{
private static LoadCustomArmor instance;
public static LoadCustomArmor getInstance() {
if (instance == null) {
instance = new LoadCustomArmor(mcMMO.p);
}
return instance;
}
public List<Integer> customBootIDs = new ArrayList<Integer>();
public List<Integer> customChestplateIDs = new ArrayList<Integer>();
public List<Integer> customHelmetIDs = new ArrayList<Integer>();
public List<Integer> customLeggingIDs = new ArrayList<Integer>();
public LoadCustomArmor(mcMMO plugin) {
super(plugin, "armor.yml");
config = plugin.getArmorConfig();
}
@Override
public void load() {
if (!configFile.exists()) {
dataFolder.mkdir();
plugin.saveArmorConfig();
}
addDefaults();
loadKeys();
}
@Override
protected void loadKeys() {
plugin.getLogger().info("Loading mcMMO armor.yml File...");
loadArmor("Boots", customBootIDs);
loadArmor("Chestplates", customChestplateIDs);
loadArmor("Helmets", customHelmetIDs);
loadArmor("Leggings", customLeggingIDs);
}
private void loadArmor(String armorType, List<Integer> idList) {
ConfigurationSection armorSection = config.getConfigurationSection(armorType);
Set<String> armorConfigSet = armorSection.getKeys(false);
Iterator<String> iterator = armorConfigSet.iterator();
while (iterator.hasNext()) {
String armorName = iterator.next();
int id = config.getInt(armorType + "." + armorName + ".ID", 0);
boolean repairable = config.getBoolean(armorType + "." + armorName + ".Repairable");
int repairID = config.getInt(armorType + "." + armorName + ".Repair_Material_ID", 0);
byte repairData = (byte) config.getInt(armorType + "." + armorName + ".Repair_Material_Data_Value", 0);
int repairQuantity = config.getInt(armorType + "." + armorName + ".Repair_Material_Quantity", 0);
short durability = (short) config.getInt(armorType + "." + armorName + ".Durability", 0);
if (id == 0) {
plugin.getLogger().warning("Missing ID. This item will be skipped.");
continue;
}
if (repairable && (repairID == 0 || repairQuantity == 0 || durability == 0)) {
plugin.getLogger().warning("Incomplete repair information. This item will be unrepairable.");
repairable = false;
}
CustomItem armor;
if (repairable) {
ItemStack repairMaterial = new ItemStack(repairID, 1, (short) 0, repairData);
armor = new CustomItem(durability, repairMaterial, repairQuantity, repairable, id);
}
else {
armor = new CustomItem(durability, null, 0, repairable, id);
}
idList.add(id);
customIDs.add(id);
customItems.add(armor);
}
}
}

View File

@ -1,6 +1,5 @@
package com.gmail.nossr50.config.mods;
import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@ -10,10 +9,9 @@ import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.ConfigLoader;
import com.gmail.nossr50.datatypes.mods.CustomTool;
public class LoadCustomTools extends ConfigLoader {
public class LoadCustomTools extends ModConfigLoader {
private static LoadCustomTools instance;
public static LoadCustomTools getInstance() {
@ -24,24 +22,15 @@ public class LoadCustomTools extends ConfigLoader {
return instance;
}
public List<CustomTool> customAxes = new ArrayList<CustomTool>();
public List<CustomTool> customBows = new ArrayList<CustomTool>();
public List<CustomTool> customHoes = new ArrayList<CustomTool>();
public List<CustomTool> customPickaxes = new ArrayList<CustomTool>();
public List<CustomTool> customShovels = new ArrayList<CustomTool>();
public List<CustomTool> customSwords = new ArrayList<CustomTool>();
public List<CustomTool> customTools = new ArrayList<CustomTool>();
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>();
public List<Integer> customIDs = new ArrayList<Integer>();
private LoadCustomTools(mcMMO plugin) {
super(plugin, "ModConfigs" + File.separator + "tools.yml");
super(plugin, "tools.yml");
config = plugin.getToolsConfig();
}
@ -60,15 +49,15 @@ public class LoadCustomTools extends ConfigLoader {
protected void loadKeys() {
plugin.getLogger().info("Loading mcMMO tools.yml File...");
loadTool("Axes", customAxes, customAxeIDs);
loadTool("Bows", customBows, customBowIDs);
loadTool("Hoes", customHoes, customHoeIDs);
loadTool("Pickaxes", customPickaxes, customPickaxeIDs);
loadTool("Shovels", customShovels, customShovelIDs);
loadTool("Swords", customSwords, customSwordIDs);
loadTool("Axes", customAxeIDs);
loadTool("Bows", customBowIDs);
loadTool("Hoes", customHoeIDs);
loadTool("Pickaxes", customPickaxeIDs);
loadTool("Shovels", customShovelIDs);
loadTool("Swords", customSwordIDs);
}
private void loadTool(String toolType, List<CustomTool> toolList, List<Integer> idList) {
private void loadTool(String toolType, List<Integer> idList) {
ConfigurationSection toolSection = config.getConfigurationSection(toolType);
Set<String> toolConfigSet = toolSection.getKeys(false);
Iterator<String> iterator = toolConfigSet.iterator();
@ -76,7 +65,7 @@ public class LoadCustomTools extends ConfigLoader {
while (iterator.hasNext()) {
String toolName = iterator.next();
int id = config.getInt(toolType + "." + toolName + ".ID");
int id = config.getInt(toolType + "." + toolName + ".ID", 0);
double multiplier = config.getDouble(toolType + "." + toolName + ".XP_Modifier", 1.0);
boolean abilityEnabled = config.getBoolean(toolType + "." + toolName + ".Ability_Enabled", true);
boolean repairable = config.getBoolean(toolType + "." + toolName + ".Repairable");
@ -90,7 +79,7 @@ public class LoadCustomTools extends ConfigLoader {
continue;
}
if (repairable && (repairID == 0 || repairQuantity == 0 || durability == 0 )) {
if (repairable && (repairID == 0 || repairQuantity == 0 || durability == 0)) {
plugin.getLogger().warning("Incomplete repair information. This item will be unrepairable.");
repairable = false;
}
@ -105,10 +94,9 @@ public class LoadCustomTools extends ConfigLoader {
tool = new CustomTool(durability, null, 0, repairable, abilityEnabled, multiplier, id);
}
toolList.add(tool);
idList.add(id);
customIDs.add(id);
customTools.add(tool);
customItems.add(tool);
}
}
}

View File

@ -0,0 +1,18 @@
package com.gmail.nossr50.config.mods;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.ConfigLoader;
import com.gmail.nossr50.datatypes.mods.CustomItem;
public abstract class ModConfigLoader extends ConfigLoader{
public List<Integer> customIDs = new ArrayList<Integer>();
public List<CustomItem> customItems = new ArrayList<CustomItem>();
public ModConfigLoader(mcMMO plugin, String fileName) {
super(plugin, "ModConfigs" + File.separator + fileName);
}
}