From bc642deebda540187815e314c8b503717b5a9c69 Mon Sep 17 00:00:00 2001 From: GJ Date: Tue, 15 May 2012 16:12:59 -0400 Subject: [PATCH] Custom armor can now be repaired. --- Changelog.txt | 1 + .../java/com/gmail/nossr50/config/Config.java | 1 + .../nossr50/config/mods/LoadCustomArmor.java | 96 +++++++++++++++++++ .../nossr50/config/mods/LoadCustomTools.java | 36 +++---- .../nossr50/config/mods/ModConfigLoader.java | 18 ++++ .../nossr50/datatypes/mods/CustomItem.java | 60 ++++++++++++ .../nossr50/datatypes/mods/CustomTool.java | 53 +--------- src/main/java/com/gmail/nossr50/mcMMO.java | 58 +++++++++++ .../com/gmail/nossr50/skills/misc/Repair.java | 59 ++++++++++-- .../com/gmail/nossr50/util/ItemChecks.java | 45 ++++++++- .../com/gmail/nossr50/util/ModChecks.java | 52 ++++++++-- src/main/resources/armor.yml | 75 +++++++++++++++ src/main/resources/config.yml | 1 + 13 files changed, 460 insertions(+), 95 deletions(-) create mode 100644 src/main/java/com/gmail/nossr50/config/mods/LoadCustomArmor.java create mode 100644 src/main/java/com/gmail/nossr50/config/mods/ModConfigLoader.java create mode 100644 src/main/java/com/gmail/nossr50/datatypes/mods/CustomItem.java create mode 100644 src/main/resources/armor.yml diff --git a/Changelog.txt b/Changelog.txt index 0270965ec..f4a2a3654 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -10,6 +10,7 @@ Key: Version 1.3.07 + Added ability to gain XP with custom tools. Enable custom tools in the config file, then enter the data in the tools.yml file. + Added ability to repair custom tools. Enable custom tools in the config file, then enter the data in the tools.yml file. + + Added ability to repair custom armor. Enable custom armor in the config file, then enter the data in the armor.yml file. + Added functionality which makes a new folder in all world files "mcmmo_data" to store player placed block information in + Added new configurable Hardcore mode functionality to mcMMO + Added new configurable Vampirism PVP stat leech for Hardcore mode diff --git a/src/main/java/com/gmail/nossr50/config/Config.java b/src/main/java/com/gmail/nossr50/config/Config.java index 6a38e689b..4e1676e66 100644 --- a/src/main/java/com/gmail/nossr50/config/Config.java +++ b/src/main/java/com/gmail/nossr50/config/Config.java @@ -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 */ diff --git a/src/main/java/com/gmail/nossr50/config/mods/LoadCustomArmor.java b/src/main/java/com/gmail/nossr50/config/mods/LoadCustomArmor.java new file mode 100644 index 000000000..a533490cc --- /dev/null +++ b/src/main/java/com/gmail/nossr50/config/mods/LoadCustomArmor.java @@ -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 customBootIDs = new ArrayList(); + public List customChestplateIDs = new ArrayList(); + public List customHelmetIDs = new ArrayList(); + public List customLeggingIDs = new ArrayList(); + + 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 idList) { + ConfigurationSection armorSection = config.getConfigurationSection(armorType); + Set armorConfigSet = armorSection.getKeys(false); + Iterator 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); + } + } +} diff --git a/src/main/java/com/gmail/nossr50/config/mods/LoadCustomTools.java b/src/main/java/com/gmail/nossr50/config/mods/LoadCustomTools.java index 05cf623ae..1fcc30665 100644 --- a/src/main/java/com/gmail/nossr50/config/mods/LoadCustomTools.java +++ b/src/main/java/com/gmail/nossr50/config/mods/LoadCustomTools.java @@ -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 customAxes = new ArrayList(); - public List customBows = new ArrayList(); - public List customHoes = new ArrayList(); - public List customPickaxes = new ArrayList(); - public List customShovels = new ArrayList(); - public List customSwords = new ArrayList(); - public List customTools = new ArrayList(); - public List customAxeIDs = new ArrayList(); public List customBowIDs = new ArrayList(); public List customHoeIDs = new ArrayList(); public List customPickaxeIDs = new ArrayList(); public List customShovelIDs = new ArrayList(); public List customSwordIDs = new ArrayList(); - public List customIDs = new ArrayList(); 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 toolList, List idList) { + private void loadTool(String toolType, List idList) { ConfigurationSection toolSection = config.getConfigurationSection(toolType); Set toolConfigSet = toolSection.getKeys(false); Iterator 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); } } } diff --git a/src/main/java/com/gmail/nossr50/config/mods/ModConfigLoader.java b/src/main/java/com/gmail/nossr50/config/mods/ModConfigLoader.java new file mode 100644 index 000000000..70224bade --- /dev/null +++ b/src/main/java/com/gmail/nossr50/config/mods/ModConfigLoader.java @@ -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 customIDs = new ArrayList(); + public List customItems = new ArrayList(); + + public ModConfigLoader(mcMMO plugin, String fileName) { + super(plugin, "ModConfigs" + File.separator + fileName); + } +} diff --git a/src/main/java/com/gmail/nossr50/datatypes/mods/CustomItem.java b/src/main/java/com/gmail/nossr50/datatypes/mods/CustomItem.java new file mode 100644 index 000000000..7e04b4f52 --- /dev/null +++ b/src/main/java/com/gmail/nossr50/datatypes/mods/CustomItem.java @@ -0,0 +1,60 @@ +package com.gmail.nossr50.datatypes.mods; + +import org.bukkit.inventory.ItemStack; + +public class CustomItem { + protected int itemID; + protected boolean repairable; + protected ItemStack repairMaterial; + protected int repairQuantity; + protected short durability; + + public CustomItem(short durability, ItemStack repairMaterial, int repairQuantity, boolean repairable, int itemID) { + this.itemID = itemID; + this.repairable = repairable; + this.repairMaterial = repairMaterial; + this.repairQuantity = repairQuantity; + this.durability = durability; + } + + public int getItemID() { + return itemID; + } + + public void setItemID(int itemID) { + this.itemID = itemID; + } + + + public boolean isRepairable() { + return repairable; + } + + public void setRepairable(boolean repairable) { + this.repairable = repairable; + } + + public ItemStack getRepairMaterial() { + return repairMaterial; + } + + public void setRepairMaterial(ItemStack repairMaterial) { + this.repairMaterial = repairMaterial; + } + + public int getRepairQuantity() { + return repairQuantity; + } + + public void setRepairQuantity(int repairQuantity) { + this.repairQuantity = repairQuantity; + } + + public short getDurability() { + return durability; + } + + public void setDurability(short durability) { + this.durability = durability; + } +} diff --git a/src/main/java/com/gmail/nossr50/datatypes/mods/CustomTool.java b/src/main/java/com/gmail/nossr50/datatypes/mods/CustomTool.java index ad33a7bcd..1ec12e981 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/mods/CustomTool.java +++ b/src/main/java/com/gmail/nossr50/datatypes/mods/CustomTool.java @@ -2,31 +2,14 @@ package com.gmail.nossr50.datatypes.mods; import org.bukkit.inventory.ItemStack; -public class CustomTool { - private int itemID; +public class CustomTool extends CustomItem { private double xpMultiplier; private boolean abilityEnabled; - private boolean repairable; - private ItemStack repairMaterial; - private int repairQuantity; - private short durability; public CustomTool(short durability, ItemStack repairMaterial, int repairQuantity, boolean repairable, boolean abilityEnabled, double xpMultiplier, int itemID) { - this.itemID = itemID; + super(durability, repairMaterial, repairQuantity, repairable, itemID); this.xpMultiplier = xpMultiplier; this.abilityEnabled = abilityEnabled; - this.repairable = repairable; - this.repairMaterial = repairMaterial; - this.repairQuantity = repairQuantity; - this.durability = durability; - } - - public int getItemID() { - return itemID; - } - - public void setItemID(int itemID) { - this.itemID = itemID; } public double getXpMultiplier() { @@ -44,36 +27,4 @@ public class CustomTool { public void setAbilityEnabled(boolean abilityEnabled) { this.abilityEnabled = abilityEnabled; } - - public boolean isRepairable() { - return repairable; - } - - public void setRepairable(boolean repairable) { - this.repairable = repairable; - } - - public ItemStack getRepairMaterial() { - return repairMaterial; - } - - public void setRepairMaterial(ItemStack repairMaterial) { - this.repairMaterial = repairMaterial; - } - - public int getRepairQuantity() { - return repairQuantity; - } - - public void setRepairQuantity(int repairQuantity) { - this.repairQuantity = repairQuantity; - } - - public short getDurability() { - return durability; - } - - public void setDurability(short durability) { - this.durability = durability; - } } diff --git a/src/main/java/com/gmail/nossr50/mcMMO.java b/src/main/java/com/gmail/nossr50/mcMMO.java index 11e522d89..c0b5cb56d 100644 --- a/src/main/java/com/gmail/nossr50/mcMMO.java +++ b/src/main/java/com/gmail/nossr50/mcMMO.java @@ -8,6 +8,7 @@ import com.gmail.nossr50.commands.party.*; import com.gmail.nossr50.commands.general.*; import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.LoadTreasures; +import com.gmail.nossr50.config.mods.LoadCustomArmor; import com.gmail.nossr50.config.mods.LoadCustomTools; import com.gmail.nossr50.runnables.*; import com.gmail.nossr50.util.Database; @@ -77,6 +78,10 @@ public class mcMMO extends JavaPlugin { LoadCustomTools.getInstance().load(); } + if (configInstance.getArmorModsEnabled()) { + LoadCustomArmor.getInstance().load(); + } + if (!configInstance.getUseMySQL()) { Users.loadUsers(); } @@ -440,4 +445,57 @@ public class mcMMO extends JavaPlugin { getLogger().severe("Could not save config to " + toolsConfigFile + ex.toString()); } } + + /* + * Boilerplate Custom Config Stuff (Armor) + */ + + private FileConfiguration armorConfig = null; + private File armorConfigFile = null; + + /** + * Reload the Armor.yml file. + */ + public void reloadArmorConfig() { + if (armorConfigFile == null) { + armorConfigFile = new File(modDirectory, "armor.yml"); + } + + armorConfig = YamlConfiguration.loadConfiguration(armorConfigFile); + InputStream defConfigStream = getResource("armor.yml"); // Look for defaults in the jar + + if (defConfigStream != null) { + YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream); + armorConfig.setDefaults(defConfig); + } + } + + /** + * Get the Armor config information. + * + * @return the configuration object for armor.yml + */ + public FileConfiguration getArmorConfig() { + if (armorConfig == null) { + reloadArmorConfig(); + } + + return armorConfig; + } + + /** + * Save the Armor config informtion. + */ + public void saveArmorConfig() { + if (armorConfig == null || armorConfigFile == null) { + return; + } + + try { + armorConfig.save(armorConfigFile); + } + catch (IOException ex) { + getLogger().severe("Could not save config to " + armorConfigFile + ex.toString()); + } + } } diff --git a/src/main/java/com/gmail/nossr50/skills/misc/Repair.java b/src/main/java/com/gmail/nossr50/skills/misc/Repair.java index ffe5b489b..a1cf54493 100644 --- a/src/main/java/com/gmail/nossr50/skills/misc/Repair.java +++ b/src/main/java/com/gmail/nossr50/skills/misc/Repair.java @@ -16,16 +16,18 @@ import org.getspout.spoutapi.player.SpoutPlayer; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.config.Config; +import com.gmail.nossr50.config.mods.LoadCustomArmor; import com.gmail.nossr50.config.mods.LoadCustomTools; import com.gmail.nossr50.spout.SpoutSounds; import com.gmail.nossr50.util.ItemChecks; import com.gmail.nossr50.util.Misc; +import com.gmail.nossr50.util.ModChecks; import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Skills; import com.gmail.nossr50.util.Users; import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.SkillType; -import com.gmail.nossr50.datatypes.mods.CustomTool; +import com.gmail.nossr50.datatypes.mods.CustomItem; import com.gmail.nossr50.events.skills.McMMOPlayerRepairCheckEvent; import com.gmail.nossr50.locale.LocaleLoader; @@ -113,10 +115,35 @@ public class Repair { else if (ItemChecks.isCustomTool(is) && permInstance.toolRepair(player)) { LoadCustomTools toolsInstance = LoadCustomTools.getInstance(); - for (CustomTool tool : toolsInstance.customTools) { + for (CustomItem tool : toolsInstance.customItems) { if (tool.getItemID() == is.getTypeId()) { - if (inventory.contains(tool.getRepairMaterial())) { - repairCustomItem(player, is, tool.getRepairMaterial()); + ItemStack repairMaterial = tool.getRepairMaterial(); + + if (inventory.contains(repairMaterial)) { + repairCustomItem(player, is, repairMaterial); + xpHandler(player, PP, is, durabilityBefore, 1, true); + } + else { + needMoreVespeneGas(is, player); + } + + break; + } + } + } + + /* + * REPAIR CUSTOM ARMOR + */ + else if (ItemChecks.isCustomArmor(is) && permInstance.armorRepair(player)) { + LoadCustomArmor armorInstance = LoadCustomArmor.getInstance(); + + for (CustomItem armor : armorInstance.customItems) { + if (armor.getItemID() == is.getTypeId()) { + ItemStack repairMaterial = armor.getRepairMaterial(); + + if (inventory.contains(repairMaterial)) { + repairCustomItem(player, is, repairMaterial); xpHandler(player, PP, is, durabilityBefore, 1, true); } else { @@ -384,11 +411,25 @@ public class Repair { int materialsRequired = 0; int repairAmount = 0; - for (CustomTool tool : LoadCustomTools.getInstance().customTools) { - if (tool.getItemID() == is.getTypeId()) { - maxDurability = tool.getDurability(); - materialsRequired = tool.getRepairQuantity(); - break; + LoadCustomTools toolInstance = LoadCustomTools.getInstance(); + LoadCustomArmor armorInstance = LoadCustomArmor.getInstance(); + + if (ModChecks.getToolFromItemStack(is) != null) { + for (CustomItem tool : toolInstance.customItems) { + if (tool.getItemID() == is.getTypeId()) { + maxDurability = tool.getDurability(); + materialsRequired = tool.getRepairQuantity(); + break; + } + } + } + else if (ModChecks.getArmorFromItemStack(is) != null) { + for (CustomItem armor : armorInstance.customItems) { + if (armor.getItemID() == is.getTypeId()) { + maxDurability = armor.getDurability(); + materialsRequired = armor.getRepairQuantity(); + break; + } } } diff --git a/src/main/java/com/gmail/nossr50/util/ItemChecks.java b/src/main/java/com/gmail/nossr50/util/ItemChecks.java index 79fb09e35..4294ca505 100644 --- a/src/main/java/com/gmail/nossr50/util/ItemChecks.java +++ b/src/main/java/com/gmail/nossr50/util/ItemChecks.java @@ -3,11 +3,13 @@ package com.gmail.nossr50.util; import org.bukkit.inventory.ItemStack; import com.gmail.nossr50.config.Config; +import com.gmail.nossr50.config.mods.LoadCustomArmor; import com.gmail.nossr50.config.mods.LoadCustomTools; public class ItemChecks { private static Config configInstance = Config.getInstance(); private static boolean customToolsEnabled = configInstance.getToolModsEnabled(); + private static boolean customArmorEnabled = configInstance.getArmorModsEnabled(); /** * Checks if the item is a sword. @@ -149,7 +151,12 @@ public class ItemChecks { return true; default: - return false; + if (customArmorEnabled && LoadCustomArmor.getInstance().customHelmetIDs.contains(is.getTypeId())) { + return true; + } + else { + return false; + } } } @@ -168,7 +175,12 @@ public class ItemChecks { return true; default: - return false; + if (customArmorEnabled && LoadCustomArmor.getInstance().customChestplateIDs.contains(is.getTypeId())) { + return true; + } + else { + return false; + } } } @@ -187,7 +199,12 @@ public class ItemChecks { return true; default: - return false; + if (customArmorEnabled && LoadCustomArmor.getInstance().customLeggingIDs.contains(is.getTypeId())) { + return true; + } + else { + return false; + } } } @@ -206,7 +223,12 @@ public class ItemChecks { return true; default: - return false; + if (customArmorEnabled && LoadCustomArmor.getInstance().customBootIDs.contains(is.getTypeId())) { + return true; + } + else { + return false; + } } } @@ -220,6 +242,21 @@ public class ItemChecks { return isLeatherArmor(is) || isGoldArmor(is) || isIronArmor(is) || isDiamondArmor(is); } + /** + * Checks to see if an item is a custom tool. + * + * @param is Item to check + * @return true if the item is a custom tool, false otherwise + */ + public static boolean isCustomArmor(ItemStack is) { + if (customArmorEnabled && LoadCustomArmor.getInstance().customIDs.contains(is.getTypeId())) { + return true; + } + else { + return false; + } + } + /** * Checks to see if an item is a leather armor piece. * diff --git a/src/main/java/com/gmail/nossr50/util/ModChecks.java b/src/main/java/com/gmail/nossr50/util/ModChecks.java index 9c059db74..471ab0d46 100644 --- a/src/main/java/com/gmail/nossr50/util/ModChecks.java +++ b/src/main/java/com/gmail/nossr50/util/ModChecks.java @@ -2,10 +2,14 @@ package com.gmail.nossr50.util; import org.bukkit.inventory.ItemStack; +import com.gmail.nossr50.config.mods.LoadCustomArmor; import com.gmail.nossr50.config.mods.LoadCustomTools; +import com.gmail.nossr50.datatypes.mods.CustomItem; import com.gmail.nossr50.datatypes.mods.CustomTool; public class ModChecks { + private static LoadCustomTools toolInstance = LoadCustomTools.getInstance(); + private static LoadCustomArmor armorInstance = LoadCustomArmor.getInstance(); /** * Check if this custom tool can use abilities. @@ -14,25 +18,59 @@ public class ModChecks { * @return true if the tool can use abilities, false otherwise */ public static boolean toolAbilityEnabled(ItemStack item) { - for (CustomTool tool : LoadCustomTools.getInstance().customTools) { - if (tool.getItemID() == item.getTypeId()) { - return tool.isAbilityEnabled(); + int id = item.getTypeId(); + + if (!toolInstance.customIDs.contains(id)) { + return false; + } + + for (CustomItem tool : toolInstance.customItems) { + if (tool.getItemID() == id) { + return ((CustomTool) tool).isAbilityEnabled(); } } return false; } + /** + * Get the custom armor associated with an item. + * + * @param item The item to check + * @return the ay if it exists, null otherwise + */ + public static CustomItem getArmorFromItemStack(ItemStack item) { + int id = item.getTypeId(); + + if (!armorInstance.customIDs.contains(id)) { + return null; + } + + for (CustomItem armor : armorInstance.customItems) { + if (armor.getItemID() == id) { + return armor; + } + } + + return null; + } + /** * Get the custom tool associated with an item. * * @param item The item to check - * @return the tool if it exists, null otherwise + * @return the armor if it exists, null otherwise */ public static CustomTool getToolFromItemStack(ItemStack item) { - for (CustomTool tool : LoadCustomTools.getInstance().customTools) { - if (tool.getItemID() == item.getTypeId()) { - return tool; + int id = item.getTypeId(); + + if (!toolInstance.customIDs.contains(id)) { + return null; + } + + for (CustomItem tool : toolInstance.customItems) { + if (tool.getItemID() == id) { + return (CustomTool) tool; } } diff --git a/src/main/resources/armor.yml b/src/main/resources/armor.yml new file mode 100644 index 000000000..535ef722b --- /dev/null +++ b/src/main/resources/armor.yml @@ -0,0 +1,75 @@ +# +# Settings for Boots +### +Boots: + Boot_1: + ID: 999 + Repairable: true + Repair_Material_ID: 99 + Repair_Material_Data_Value: 0 + Repair_Material_Quantity: 9 + Durability: 9999 + Boot_2: + ID: 999 + Repairable: true + Repair_Material_ID: 99 + Repair_Material_Data_Value: 0 + Repair_Material_Quantity: 9 + Durability: 9999 + +# +# Settings for Chestplates +### +Chestplates: + Chestplate_1: + ID: 999 + Repairable: true + Repair_Material_ID: 99 + Repair_Material_Data_Value: 0 + Repair_Material_Quantity: 9 + Durability: 9999 + Chestplate_2: + ID: 999 + Repairable: true + Repair_Material_ID: 99 + Repair_Material_Data_Value: 0 + Repair_Material_Quantity: 9 + Durability: 9999 + +# +# Settings for Helmets +### +Helmets: + Helmet_1: + ID: 999 + Repairable: true + Repair_Material_ID: 99 + Repair_Material_Data_Value: 0 + Repair_Material_Quantity: 9 + Durability: 9999 + Helmet_2: + ID: 999 + Repairable: true + Repair_Material_ID: 99 + Repair_Material_Data_Value: 0 + Repair_Material_Quantity: 9 + Durability: 9999 + +# +# Settings for Leggings +### +Leggings: + Legging_1: + ID: 999 + Repairable: true + Repair_Material_ID: 99 + Repair_Material_Data_Value: 0 + Repair_Material_Quantity: 9 + Durability: 9999 + Legging_2: + ID: 999 + Repairable: true + Repair_Material_ID: 99 + Repair_Material_Data_Value: 0 + Repair_Material_Quantity: 9 + Durability: 9999 \ No newline at end of file diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 295c5ff32..f6ad56a5f 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -45,6 +45,7 @@ Hardcore: ### Mods: Tool_Mods_Enabled: false + Armor_Mods_Enabled: false Block_Mods_Enabled: false #