Rework custom tool config.

** YOU WILL NEED TO UPDATE YOUR CONFIG TO THE NEW FORMAT **
This commit is contained in:
GJ 2013-09-22 11:31:54 -04:00 committed by TfT_02
parent 1b92131ce9
commit fc6c7bb1de
9 changed files with 90 additions and 109 deletions

View File

@ -8,7 +8,7 @@ Key:
- Removal - Removal
Version 1.4.07-dev Version 1.4.07-dev
+ Added Carrot on a Stick, Bucket, and Flint & Steel to repair.vanilla.yml + Added Carrot on a Stick and Flint & Steel to repair.vanilla.yml
+ Added horses to the "Shake" ability + Added horses to the "Shake" ability
+ Added ability to summon horses via "Call of the Wild" using apples + Added ability to summon horses via "Call of the Wild" using apples
+ Added XP gain to Taming for horses + Added XP gain to Taming for horses

View File

@ -10,6 +10,8 @@ import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.config.ConfigLoader; import com.gmail.nossr50.config.ConfigLoader;
import com.gmail.nossr50.skills.repair.Repair; import com.gmail.nossr50.skills.repair.Repair;
import com.gmail.nossr50.skills.repair.RepairItemType;
import com.gmail.nossr50.skills.repair.RepairMaterialType;
import com.gmail.nossr50.skills.repair.Repairable; import com.gmail.nossr50.skills.repair.Repairable;
import com.gmail.nossr50.skills.repair.RepairableFactory; import com.gmail.nossr50.skills.repair.RepairableFactory;
@ -94,7 +96,7 @@ public class CustomArmorConfig extends ConfigLoader {
durability = (short) config.getInt(armorType + "." + armorName + ".Durability", 70); durability = (short) config.getInt(armorType + "." + armorName + ".Durability", 70);
} }
repairables.add(RepairableFactory.getRepairable(armorMaterial, repairMaterial, repairData, repairQuantity, durability)); repairables.add(RepairableFactory.getRepairable(armorMaterial, repairMaterial, repairData, repairQuantity, 0, durability, RepairItemType.ARMOR, RepairMaterialType.OTHER, 1.0));
} }
materialList.add(armorMaterial); materialList.add(armorMaterial);

View File

@ -65,7 +65,7 @@ public class CustomEntityConfig extends ConfigLoader {
CustomEntity entity; CustomEntity entity;
if (id == 0) { if (id == 0) {
plugin.getLogger().warning("Missing ID. This block will be skipped."); plugin.getLogger().warning("Missing ID. This entity will be skipped.");
continue; continue;
} }

View File

@ -7,9 +7,13 @@ import java.util.Set;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.config.ConfigLoader; import com.gmail.nossr50.config.ConfigLoader;
import com.gmail.nossr50.datatypes.mods.CustomTool; import com.gmail.nossr50.datatypes.mods.CustomTool;
import com.gmail.nossr50.skills.repair.Repair;
import com.gmail.nossr50.skills.repair.RepairItemType;
import com.gmail.nossr50.skills.repair.RepairMaterialType;
import com.gmail.nossr50.skills.repair.Repairable; import com.gmail.nossr50.skills.repair.Repairable;
import com.gmail.nossr50.skills.repair.RepairableFactory; import com.gmail.nossr50.skills.repair.RepairableFactory;
@ -17,16 +21,15 @@ public class CustomToolConfig extends ConfigLoader {
private static CustomToolConfig instance; private static CustomToolConfig instance;
private List<Repairable> repairables; private List<Repairable> repairables;
public List<Integer> customAxeIDs = new ArrayList<Integer>(); public List<Material> customAxes = new ArrayList<Material>();
public List<Integer> customBowIDs = new ArrayList<Integer>(); public List<Material> customBows = new ArrayList<Material>();
public List<Integer> customHoeIDs = new ArrayList<Integer>(); public List<Material> customHoes = new ArrayList<Material>();
public List<Integer> customPickaxeIDs = new ArrayList<Integer>(); public List<Material> customPickaxes = new ArrayList<Material>();
public List<Integer> customShovelIDs = new ArrayList<Integer>(); public List<Material> customShovels = new ArrayList<Material>();
public List<Integer> customSwordIDs = new ArrayList<Integer>(); public List<Material> customSwords = new ArrayList<Material>();
public List<Integer> customIDs = new ArrayList<Integer>(); public List<Material> customTool = new ArrayList<Material>();
public List<CustomTool> customToolList = new ArrayList<CustomTool>(); public HashMap<Material, CustomTool> customToolMap = new HashMap<Material, CustomTool>();
public HashMap<Integer, CustomTool> customTools = new HashMap<Integer, CustomTool>();
private CustomToolConfig() { private CustomToolConfig() {
super("ModConfigs", "tools.yml"); super("ModConfigs", "tools.yml");
@ -53,15 +56,15 @@ public class CustomToolConfig extends ConfigLoader {
protected void loadKeys() { protected void loadKeys() {
repairables = new ArrayList<Repairable>(); repairables = new ArrayList<Repairable>();
loadTool("Axes", customAxeIDs); loadTool("Axes", customAxes);
loadTool("Bows", customBowIDs); loadTool("Bows", customBows);
loadTool("Hoes", customHoeIDs); loadTool("Hoes", customHoes);
loadTool("Pickaxes", customPickaxeIDs); loadTool("Pickaxes", customPickaxes);
loadTool("Shovels", customShovelIDs); loadTool("Shovels", customShovels);
loadTool("Swords", customSwordIDs); loadTool("Swords", customSwords);
} }
private void loadTool(String toolType, List<Integer> idList) { private void loadTool(String toolType, List<Material> materialList) {
ConfigurationSection toolSection = config.getConfigurationSection(toolType); ConfigurationSection toolSection = config.getConfigurationSection(toolType);
if (toolSection == null) { if (toolSection == null) {
@ -71,38 +74,48 @@ public class CustomToolConfig extends ConfigLoader {
Set<String> toolConfigSet = toolSection.getKeys(false); Set<String> toolConfigSet = toolSection.getKeys(false);
for (String toolName : toolConfigSet) { for (String toolName : toolConfigSet) {
int id = config.getInt(toolType + "." + toolName + ".ID", 0); Material toolMaterial = Material.matchMaterial(toolName);
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);
boolean repairable = config.getBoolean(toolType + "." + toolName + ".Repairable");
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);
if (id == 0) { if (toolMaterial == null) {
plugin.getLogger().warning("Missing ID. This item will be skipped."); plugin.getLogger().warning("Invalid material name. This item will be skipped.");
continue; continue;
} }
if (repairable && (repairID == 0 || repairQuantity == 0 || durability == 0)) { boolean repairable = config.getBoolean(toolType + "." + toolName + ".Repairable");
Material repairMaterial = Material.matchMaterial(config.getString(toolType + "." + toolName + ".Repair_Material", ""));
if (repairMaterial == null) {
plugin.getLogger().warning("Incomplete repair information. This item will be unrepairable."); plugin.getLogger().warning("Incomplete repair information. This item will be unrepairable.");
repairable = false; repairable = false;
} }
CustomTool tool;
if (repairable) { if (repairable) {
repairables.add(RepairableFactory.getRepairable(Material.getMaterial(id), Material.getMaterial(repairID), repairData, repairQuantity, durability)); 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);
} }
tool = new CustomTool(tier, abilityEnabled, multiplier, id); short durability = toolMaterial.getMaxDurability();
idList.add(id); if (durability == 0) {
customIDs.add(id); durability = (short) config.getInt(toolType + "." + toolName + ".Durability", 60);
customToolList.add(tool); }
customTools.put(id, tool);
repairables.add(RepairableFactory.getRepairable(toolMaterial, repairMaterial, repairData, 0, repairQuantity, durability, RepairItemType.TOOL, RepairMaterialType.OTHER, 1.0));
}
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);
materialList.add(toolMaterial);
customTool.add(toolMaterial);
customToolMap.put(toolMaterial, tool);
} }
} }
} }

View File

@ -1,49 +1,25 @@
package com.gmail.nossr50.datatypes.mods; package com.gmail.nossr50.datatypes.mods;
import org.bukkit.Material;
public class CustomTool { public class CustomTool {
private Material material;
private double xpMultiplier; private double xpMultiplier;
private boolean abilityEnabled; private boolean abilityEnabled;
private int tier; private int tier;
public CustomTool(int tier, boolean abilityEnabled, double xpMultiplier, int itemID) { public CustomTool(int tier, boolean abilityEnabled, double xpMultiplier) {
this.material = Material.getMaterial(itemID);
this.xpMultiplier = xpMultiplier; this.xpMultiplier = xpMultiplier;
this.abilityEnabled = abilityEnabled; this.abilityEnabled = abilityEnabled;
this.tier = tier; this.tier = tier;
} }
public Material getType() {
return material;
}
public void setType(Material material) {
this.material = material;
}
public double getXpMultiplier() { public double getXpMultiplier() {
return xpMultiplier; return xpMultiplier;
} }
public void setXpMultiplier(Double xpMultiplier) {
this.xpMultiplier = xpMultiplier;
}
public boolean isAbilityEnabled() { public boolean isAbilityEnabled() {
return abilityEnabled; return abilityEnabled;
} }
public void setAbilityEnabled(boolean abilityEnabled) {
this.abilityEnabled = abilityEnabled;
}
public int getTier() { public int getTier() {
return tier; return tier;
} }
public void setTier(int tier) {
this.tier = tier;
}
} }

View File

@ -21,7 +21,9 @@ public class ItemUtils {
* @return true if the item is a sword, false otherwise * @return true if the item is a sword, false otherwise
*/ */
public static boolean isSword(ItemStack item) { public static boolean isSword(ItemStack item) {
switch (item.getType()) { Material type = item.getType();
switch (type) {
case DIAMOND_SWORD: case DIAMOND_SWORD:
case GOLD_SWORD: case GOLD_SWORD:
case IRON_SWORD: case IRON_SWORD:
@ -30,7 +32,7 @@ public class ItemUtils {
return true; return true;
default: default:
return (Config.getInstance().getToolModsEnabled() && CustomToolConfig.getInstance().customSwordIDs.contains(item.getTypeId())); return (Config.getInstance().getToolModsEnabled() && CustomToolConfig.getInstance().customSwords.contains(type));
} }
} }
@ -41,7 +43,9 @@ public class ItemUtils {
* @return true if the item is a hoe, false otherwise * @return true if the item is a hoe, false otherwise
*/ */
public static boolean isHoe(ItemStack item) { public static boolean isHoe(ItemStack item) {
switch (item.getType()) { Material type = item.getType();
switch (type) {
case DIAMOND_HOE: case DIAMOND_HOE:
case GOLD_HOE: case GOLD_HOE:
case IRON_HOE: case IRON_HOE:
@ -50,7 +54,7 @@ public class ItemUtils {
return true; return true;
default: default:
return (Config.getInstance().getToolModsEnabled() && CustomToolConfig.getInstance().customHoeIDs.contains(item.getTypeId())); return (Config.getInstance().getToolModsEnabled() && CustomToolConfig.getInstance().customHoes.contains(type));
} }
} }
@ -61,7 +65,9 @@ public class ItemUtils {
* @return true if the item is a shovel, false otherwise * @return true if the item is a shovel, false otherwise
*/ */
public static boolean isShovel(ItemStack item) { public static boolean isShovel(ItemStack item) {
switch (item.getType()) { Material type = item.getType();
switch (type) {
case DIAMOND_SPADE: case DIAMOND_SPADE:
case GOLD_SPADE: case GOLD_SPADE:
case IRON_SPADE: case IRON_SPADE:
@ -70,7 +76,7 @@ public class ItemUtils {
return true; return true;
default: default:
return (Config.getInstance().getToolModsEnabled() && CustomToolConfig.getInstance().customShovelIDs.contains(item.getTypeId())); return (Config.getInstance().getToolModsEnabled() && CustomToolConfig.getInstance().customShovels.contains(type));
} }
} }
@ -81,7 +87,9 @@ public class ItemUtils {
* @return true if the item is an axe, false otherwise * @return true if the item is an axe, false otherwise
*/ */
public static boolean isAxe(ItemStack item) { public static boolean isAxe(ItemStack item) {
switch (item.getType()) { Material type = item.getType();
switch (type) {
case DIAMOND_AXE: case DIAMOND_AXE:
case GOLD_AXE: case GOLD_AXE:
case IRON_AXE: case IRON_AXE:
@ -90,7 +98,7 @@ public class ItemUtils {
return true; return true;
default: default:
return (Config.getInstance().getToolModsEnabled() && CustomToolConfig.getInstance().customAxeIDs.contains(item.getTypeId())); return (Config.getInstance().getToolModsEnabled() && CustomToolConfig.getInstance().customAxes.contains(type));
} }
} }
@ -101,7 +109,9 @@ public class ItemUtils {
* @return true if the item is a pickaxe, false otherwise * @return true if the item is a pickaxe, false otherwise
*/ */
public static boolean isPickaxe(ItemStack item) { public static boolean isPickaxe(ItemStack item) {
switch (item.getType()) { Material type = item.getType();
switch (type) {
case DIAMOND_PICKAXE: case DIAMOND_PICKAXE:
case GOLD_PICKAXE: case GOLD_PICKAXE:
case IRON_PICKAXE: case IRON_PICKAXE:
@ -110,7 +120,7 @@ public class ItemUtils {
return true; return true;
default: default:
return (Config.getInstance().getToolModsEnabled() && CustomToolConfig.getInstance().customPickaxeIDs.contains(item.getTypeId())); return (Config.getInstance().getToolModsEnabled() && CustomToolConfig.getInstance().customPickaxes.contains(type));
} }
} }

View File

@ -31,7 +31,7 @@ public final class ModUtils {
* @return the tool if it exists, null otherwise * @return the tool if it exists, null otherwise
*/ */
public static CustomTool getToolFromItemStack(ItemStack item) { public static CustomTool getToolFromItemStack(ItemStack item) {
return CustomToolConfig.getInstance().customTools.get(item.getTypeId()); return CustomToolConfig.getInstance().customToolMap.get(item.getType());
} }
/** /**
@ -253,7 +253,7 @@ public final class ModUtils {
* @return true if the item is a custom tool, false otherwise * @return true if the item is a custom tool, false otherwise
*/ */
public static boolean isCustomTool(ItemStack item) { public static boolean isCustomTool(ItemStack item) {
if (customToolsEnabled && CustomToolConfig.getInstance().customTools.containsKey(item.getTypeId())) { if (customToolsEnabled && CustomToolConfig.getInstance().customTool.contains(item.getType())) {
return true; return true;
} }

View File

@ -102,9 +102,6 @@ Repairables:
SHEARS: SHEARS:
MinimumLevel: 0 MinimumLevel: 0
XpMultiplier: .5 XpMultiplier: .5
BUCKET:
MinimumLevel: 0
XpMultiplier: 1
FLINT_AND_STEEL: FLINT_AND_STEEL:
MinimumLevel: 0 MinimumLevel: 0
XpMultiplier: .3 XpMultiplier: .3

View File

@ -3,147 +3,130 @@
### ###
Axes: Axes:
Axe_1: Axe_1:
ID: 999
XP_Modifer: 1.0 XP_Modifer: 1.0
Ability_Enabled: true Ability_Enabled: true
Tier: 1 Tier: 1
Repairable: true Repairable: true
Repair_Material_ID: 99 Repair_Material: REPAIR_MATERIAL_NAME
Repair_Material_Data_Value: 0 Repair_Material_Data_Value: 0
Repair_Material_Quantity: 9 Repair_Material_Quantity: 9
Durability: 9999 Durability: 9999
Axe_2: Axe_2:
ID: 999
XP_Modifer: 1.0 XP_Modifer: 1.0
Ability_Enabled: true Ability_Enabled: true
Tier: 1 Tier: 1
Repairable: true Repairable: true
Repair_Material_ID: 99 Repair_Material: REPAIR_MATERIAL_NAME
Repair_Material_Data_Value: 0 Repair_Material_Data_Value: 0
Repair_Material_Quantity: 9 Repair_Material_Quantity: 9
Durability: 9999 Durability: 9999
# #
# Settings for Bows # Settings for Bows
### ###
Bows: Bows:
Bow_1: Bow_1:
ID: 999
XP_Modifer: 1.0 XP_Modifer: 1.0
Ability_Enabled: true Ability_Enabled: true
Tier: 1 Tier: 1
Repairable: true Repairable: true
Repair_Material_ID: 99 Repair_Material: REPAIR_MATERIAL_NAME
Repair_Material_Data_Value: 0 Repair_Material_Data_Value: 0
Repair_Material_Quantity: 9 Repair_Material_Quantity: 9
Durability: 9999 Durability: 9999
Bow_2: Bow_2:
ID: 999
XP_Modifer: 1.0 XP_Modifer: 1.0
Ability_Enabled: true Ability_Enabled: true
Tier: 1 Tier: 1
Repairable: true Repairable: true
Repair_Material_ID: 99 Repair_Material: REPAIR_MATERIAL_NAME
Repair_Material_Data_Value: 0 Repair_Material_Data_Value: 0
Repair_Material_Quantity: 9 Repair_Material_Quantity: 9
Durability: 9999 Durability: 9999
# #
# Settings for Hoes # Settings for Hoes
### ###
Hoes: Hoes:
Hoe_1: Hoe_1:
ID: 999
XP_Modifer: 1.0 XP_Modifer: 1.0
Ability_Enabled: true Ability_Enabled: true
Tier: 1 Tier: 1
Repairable: true Repairable: true
Repair_Material_ID: 99 Repair_Material: REPAIR_MATERIAL_NAME
Repair_Material_Data_Value: 0 Repair_Material_Data_Value: 0
Repair_Material_Quantity: 9 Repair_Material_Quantity: 9
Durability: 9999 Durability: 9999
Hoe_2: Hoe_2:
ID: 999
XP_Modifer: 1.0 XP_Modifer: 1.0
Ability_Enabled: true Ability_Enabled: true
Tier: 1 Tier: 1
Repairable: true Repairable: true
Repair_Material_ID: 99 Repair_Material: REPAIR_MATERIAL_NAME
Repair_Material_Data_Value: 0 Repair_Material_Data_Value: 0
Repair_Material_Quantity: 9 Repair_Material_Quantity: 9
Durability: 9999 Durability: 9999
# #
# Settings for Pickaxes # Settings for Pickaxes
### ###
Pickaxes: Pickaxes:
Pickaxe_1: Pickaxe_1:
ID: 999
XP_Modifer: 1.0 XP_Modifer: 1.0
Ability_Enabled: true Ability_Enabled: true
Tier: 1 Tier: 1
Repairable: true Repairable: true
Repair_Material_ID: 99 Repair_Material: REPAIR_MATERIAL_NAME
Repair_Material_Data_Value: 0 Repair_Material_Data_Value: 0
Repair_Material_Quantity: 9 Repair_Material_Quantity: 9
Durability: 9999 Durability: 9999
Pickaxe_2: Pickaxe_2:
ID: 999
XP_Modifer: 1.0 XP_Modifer: 1.0
Ability_Enabled: true Ability_Enabled: true
Tier: 1 Tier: 1
Repairable: true Repairable: true
Repair_Material_ID: 99 Repair_Material: REPAIR_MATERIAL_NAME
Repair_Material_Data_Value: 0 Repair_Material_Data_Value: 0
Repair_Material_Quantity: 9 Repair_Material_Quantity: 9
Durability: 9999 Durability: 9999
# #
# Settings for Shovels # Settings for Shovels
### ###
Shovels: Shovels:
Shovel_1: Shovel_1:
ID: 999
XP_Modifer: 1.0 XP_Modifer: 1.0
Ability_Enabled: true Ability_Enabled: true
Tier: 1 Tier: 1
Repairable: true Repairable: true
Repair_Material_ID: 99 Repair_Material: REPAIR_MATERIAL_NAME
Repair_Material_Data_Value: 0 Repair_Material_Data_Value: 0
Repair_Material_Quantity: 9 Repair_Material_Quantity: 9
Durability: 9999 Durability: 9999
Shovel_2: Shovel_2:
ID: 999
XP_Modifer: 1.0 XP_Modifer: 1.0
Ability_Enabled: true Ability_Enabled: true
Tier: 1 Tier: 1
Repairable: true Repairable: true
Repair_Material_ID: 99 Repair_Material: REPAIR_MATERIAL_NAME
Repair_Material_Data_Value: 0 Repair_Material_Data_Value: 0
Repair_Material_Quantity: 9 Repair_Material_Quantity: 9
Durability: 9999 Durability: 9999
# #
# Settings for Swords # Settings for Swords
### ###
Swords: Swords:
Sword_1: Sword_1:
ID: 999
XP_Modifer: 1.0 XP_Modifer: 1.0
Ability_Enabled: true Ability_Enabled: true
Tier: 1 Tier: 1
Repairable: true Repairable: true
Repair_Material_ID: 99 Repair_Material: REPAIR_MATERIAL_NAME
Repair_Material_Data_Value: 0 Repair_Material_Data_Value: 0
Repair_Material_Quantity: 9 Repair_Material_Quantity: 9
Durability: 9999 Durability: 9999
Sword_2: Sword_2:
ID: 999
XP_Modifer: 1.0 XP_Modifer: 1.0
Ability_Enabled: true Ability_Enabled: true
Tier: 1 Tier: 1
Repairable: true Repairable: true
Repair_Material_ID: 99 Repair_Material: REPAIR_MATERIAL_NAME
Repair_Material_Data_Value: 0 Repair_Material_Data_Value: 0
Repair_Material_Quantity: 9 Repair_Material_Quantity: 9
Durability: 9999 Durability: 9999