WIP on custom mod support - should now be able to repair custom tools at

an anvil.
This commit is contained in:
GJ 2012-05-15 10:44:57 -04:00
parent ecc68d373f
commit 81ac4e8d01
6 changed files with 230 additions and 85 deletions

View File

@ -8,6 +8,8 @@ Key:
- Removal - Removal
Version 1.3.07 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 functionality which makes a new folder in all world files "mcmmo_data" to store player placed block information in + 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 Hardcore mode functionality to mcMMO
+ Added new configurable Vampirism PVP stat leech for Hardcore mode + Added new configurable Vampirism PVP stat leech for Hardcore mode

View File

@ -30,6 +30,7 @@ public class LoadCustomTools extends ConfigLoader {
public List<CustomTool> customPickaxes = new ArrayList<CustomTool>(); public List<CustomTool> customPickaxes = new ArrayList<CustomTool>();
public List<CustomTool> customShovels = new ArrayList<CustomTool>(); public List<CustomTool> customShovels = new ArrayList<CustomTool>();
public List<CustomTool> customSwords = 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> customAxeIDs = new ArrayList<Integer>();
public List<Integer> customBowIDs = new ArrayList<Integer>(); public List<Integer> customBowIDs = new ArrayList<Integer>();
@ -37,6 +38,7 @@ public class LoadCustomTools extends ConfigLoader {
public List<Integer> customPickaxeIDs = new ArrayList<Integer>(); public List<Integer> customPickaxeIDs = new ArrayList<Integer>();
public List<Integer> customShovelIDs = new ArrayList<Integer>(); public List<Integer> customShovelIDs = new ArrayList<Integer>();
public List<Integer> customSwordIDs = new ArrayList<Integer>(); public List<Integer> customSwordIDs = new ArrayList<Integer>();
public List<Integer> customIDs = new ArrayList<Integer>();
private LoadCustomTools(mcMMO plugin) { private LoadCustomTools(mcMMO plugin) {
super(plugin, "ModConfigs" + File.separator + "tools.yml"); super(plugin, "ModConfigs" + File.separator + "tools.yml");
@ -76,17 +78,19 @@ public class LoadCustomTools extends ConfigLoader {
int id = config.getInt(toolType + "." + toolName + ".ID"); int id = config.getInt(toolType + "." + toolName + ".ID");
double multiplier = config.getDouble(toolType + "." + toolName + ".XP_Modifier", 1.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"); boolean repairable = config.getBoolean(toolType + "." + toolName + ".Repairable");
int repairID = config.getInt(toolType + "." + toolName + ".Repair_Material_ID"); int repairID = config.getInt(toolType + "." + toolName + ".Repair_Material_ID", 0);
byte repairData = (byte) config.getInt(toolType + "." + toolName + ".Repair_Material_Data_Value"); byte repairData = (byte) config.getInt(toolType + "." + toolName + ".Repair_Material_Data_Value", 0);
short durability = (short) config.getInt(toolType + "." + toolName + ".Durability"); int repairQuantity = config.getInt(toolType + "." + toolName + ".Repair_Material_Quantity", 0);
short durability = (short) config.getInt(toolType + "." + toolName + ".Durability", 0);
if (id == 0) { if (id == 0) {
plugin.getLogger().warning("Missing ID. This item will be skipped."); plugin.getLogger().warning("Missing ID. This item will be skipped.");
continue; continue;
} }
if (repairable && (repairID == 0 || durability == 0)) { if (repairable && (repairID == 0 || repairQuantity == 0 || durability == 0 )) {
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;
} }
@ -95,14 +99,16 @@ public class LoadCustomTools extends ConfigLoader {
if (repairable) { if (repairable) {
ItemStack repairMaterial = new ItemStack(repairID, 1, (short) 0, repairData); ItemStack repairMaterial = new ItemStack(repairID, 1, (short) 0, repairData);
tool = new CustomTool(durability, repairMaterial, repairable, multiplier, id); tool = new CustomTool(durability, repairMaterial, repairQuantity, repairable, abilityEnabled, multiplier, id);
} }
else { else {
tool = new CustomTool(durability, null, repairable, multiplier, id); tool = new CustomTool(durability, null, 0, repairable, abilityEnabled, multiplier, id);
} }
toolList.add(tool); toolList.add(tool);
idList.add(id); idList.add(id);
customIDs.add(id);
customTools.add(tool);
} }
} }
} }

View File

@ -5,15 +5,19 @@ import org.bukkit.inventory.ItemStack;
public class CustomTool { public class CustomTool {
private int itemID; private int itemID;
private double xpMultiplier; private double xpMultiplier;
private boolean abilityEnabled;
private boolean repairable; private boolean repairable;
private ItemStack repairMaterial; private ItemStack repairMaterial;
private int repairQuantity;
private short durability; private short durability;
public CustomTool(short durability, ItemStack repairMaterial, boolean repairable, double xpMultiplier, int itemID) { public CustomTool(short durability, ItemStack repairMaterial, int repairQuantity, boolean repairable, boolean abilityEnabled, double xpMultiplier, int itemID) {
this.itemID = itemID; this.itemID = itemID;
this.xpMultiplier = xpMultiplier; this.xpMultiplier = xpMultiplier;
this.abilityEnabled = abilityEnabled;
this.repairable = repairable; this.repairable = repairable;
this.repairMaterial = repairMaterial; this.repairMaterial = repairMaterial;
this.repairQuantity = repairQuantity;
this.durability = durability; this.durability = durability;
} }
@ -33,6 +37,14 @@ public class CustomTool {
this.xpMultiplier = xpMultiplier; this.xpMultiplier = xpMultiplier;
} }
public boolean isAbilityEnabled() {
return abilityEnabled;
}
public void setAbilityEnabled(boolean abilityEnabled) {
this.abilityEnabled = abilityEnabled;
}
public boolean isRepairable() { public boolean isRepairable() {
return repairable; return repairable;
} }
@ -49,6 +61,14 @@ public class CustomTool {
this.repairMaterial = repairMaterial; this.repairMaterial = repairMaterial;
} }
public int getRepairQuantity() {
return repairQuantity;
}
public void setRepairQuantity(int repairQuantity) {
this.repairQuantity = repairQuantity;
}
public short getDurability() { public short getDurability() {
return durability; return durability;
} }

View File

@ -16,6 +16,7 @@ import org.getspout.spoutapi.player.SpoutPlayer;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.config.mods.LoadCustomTools;
import com.gmail.nossr50.spout.SpoutSounds; import com.gmail.nossr50.spout.SpoutSounds;
import com.gmail.nossr50.util.ItemChecks; import com.gmail.nossr50.util.ItemChecks;
import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Misc;
@ -24,12 +25,15 @@ import com.gmail.nossr50.util.Skills;
import com.gmail.nossr50.util.Users; import com.gmail.nossr50.util.Users;
import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.datatypes.SkillType; import com.gmail.nossr50.datatypes.SkillType;
import com.gmail.nossr50.datatypes.mods.CustomTool;
import com.gmail.nossr50.events.skills.McMMOPlayerRepairCheckEvent; import com.gmail.nossr50.events.skills.McMMOPlayerRepairCheckEvent;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
public class Repair { public class Repair {
private static Random random = new Random(); private static Random random = new Random();
private static Config configInstance = Config.getInstance();
private static Permissions permInstance = Permissions.getInstance();
/** /**
* Handle all the item repair checks. * Handle all the item repair checks.
@ -48,21 +52,21 @@ public class Repair {
/* /*
* REPAIR ARMOR * REPAIR ARMOR
*/ */
if (ItemChecks.isArmor(is) && Permissions.getInstance().armorRepair(player)) { if (ItemChecks.isArmor(is) && permInstance.armorRepair(player)) {
if (ItemChecks.isDiamondArmor(is) && inventory.contains(Config.getInstance().getRepairDiamondMaterial()) && skillLevel >= Config.getInstance().getRepairDiamondLevelRequirement() && Permissions.getInstance().diamondRepair(player)) { if (ItemChecks.isDiamondArmor(is) && inventory.contains(configInstance.getRepairDiamondMaterial()) && skillLevel >= configInstance.getRepairDiamondLevelRequirement() && permInstance.diamondRepair(player)) {
repairItem(player, is, new ItemStack(Config.getInstance().getRepairDiamondMaterial())); repairItem(player, is, new ItemStack(configInstance.getRepairDiamondMaterial()));
xpHandler(player, PP, is, durabilityBefore, 6, true); xpHandler(player, PP, is, durabilityBefore, 6, true);
} }
else if (ItemChecks.isIronArmor(is) && inventory.contains(Config.getInstance().getRepairIronMaterial()) && skillLevel >= Config.getInstance().getRepairIronLevelRequirement() && Permissions.getInstance().ironRepair(player)) { else if (ItemChecks.isIronArmor(is) && inventory.contains(configInstance.getRepairIronMaterial()) && skillLevel >= configInstance.getRepairIronLevelRequirement() && permInstance.ironRepair(player)) {
repairItem(player, is, new ItemStack(Config.getInstance().getRepairIronMaterial())); repairItem(player, is, new ItemStack(configInstance.getRepairIronMaterial()));
xpHandler(player, PP, is, durabilityBefore, 2, true); xpHandler(player, PP, is, durabilityBefore, 2, true);
} }
else if (ItemChecks.isGoldArmor(is) && inventory.contains(Config.getInstance().getRepairGoldMaterial()) && skillLevel >= Config.getInstance().getRepairGoldLevelRequirement() && Permissions.getInstance().goldRepair(player)) { else if (ItemChecks.isGoldArmor(is) && inventory.contains(configInstance.getRepairGoldMaterial()) && skillLevel >= configInstance.getRepairGoldLevelRequirement() && permInstance.goldRepair(player)) {
repairItem(player, is, new ItemStack(Config.getInstance().getRepairGoldMaterial())); repairItem(player, is, new ItemStack(configInstance.getRepairGoldMaterial()));
xpHandler(player, PP, is, durabilityBefore, 4, true); xpHandler(player, PP, is, durabilityBefore, 4, true);
} }
else if (ItemChecks.isLeatherArmor(is) && inventory.contains(Config.getInstance().getRepairLeatherMaterial()) && Permissions.getInstance().leatherRepair(player)) { else if (ItemChecks.isLeatherArmor(is) && inventory.contains(configInstance.getRepairLeatherMaterial()) && permInstance.leatherRepair(player)) {
repairItem(player, is, new ItemStack(Config.getInstance().getRepairLeatherMaterial())); repairItem(player, is, new ItemStack(configInstance.getRepairLeatherMaterial()));
xpHandler(player, PP, is, durabilityBefore, 1, true); xpHandler(player, PP, is, durabilityBefore, 1, true);
} }
else { else {
@ -73,35 +77,56 @@ public class Repair {
/* /*
* REPAIR TOOLS * REPAIR TOOLS
*/ */
else if (ItemChecks.isTool(is) && Permissions.getInstance().toolRepair(player)) { else if (ItemChecks.isTool(is) && permInstance.toolRepair(player)) {
if (ItemChecks.isStoneTool(is) && inventory.contains(Config.getInstance().getRepairStoneMaterial()) && skillLevel >= Config.getInstance().getRepairStoneLevelRequirement() && Permissions.getInstance().stoneRepair(player)) { if (ItemChecks.isStoneTool(is) && inventory.contains(configInstance.getRepairStoneMaterial()) && skillLevel >= configInstance.getRepairStoneLevelRequirement() && permInstance.stoneRepair(player)) {
repairItem(player, is, new ItemStack(Config.getInstance().getRepairStoneMaterial())); repairItem(player, is, new ItemStack(configInstance.getRepairStoneMaterial()));
xpHandler(player, PP, is, durabilityBefore, 2, false); xpHandler(player, PP, is, durabilityBefore, 2, false);
} }
else if (ItemChecks.isWoodTool(is) && inventory.contains(Config.getInstance().getRepairWoodMaterial()) && Permissions.getInstance().woodRepair(player)) { else if (ItemChecks.isWoodTool(is) && inventory.contains(configInstance.getRepairWoodMaterial()) && permInstance.woodRepair(player)) {
repairItem(player, is, new ItemStack(Config.getInstance().getRepairWoodMaterial())); repairItem(player, is, new ItemStack(configInstance.getRepairWoodMaterial()));
xpHandler(player, PP, is, durabilityBefore, 2, false); xpHandler(player, PP, is, durabilityBefore, 2, false);
} }
else if (ItemChecks.isIronTool(is) && inventory.contains(Config.getInstance().getRepairIronMaterial()) && skillLevel >= Config.getInstance().getRepairIronLevelRequirement() && Permissions.getInstance().ironRepair(player)) { else if (ItemChecks.isIronTool(is) && inventory.contains(configInstance.getRepairIronMaterial()) && skillLevel >= configInstance.getRepairIronLevelRequirement() && permInstance.ironRepair(player)) {
repairItem(player, is, new ItemStack(Config.getInstance().getRepairIronMaterial())); repairItem(player, is, new ItemStack(configInstance.getRepairIronMaterial()));
xpHandler(player, PP, is, durabilityBefore, 1, true); xpHandler(player, PP, is, durabilityBefore, 1, true);
} }
else if (ItemChecks.isDiamondTool(is) && inventory.contains(Config.getInstance().getRepairDiamondMaterial()) && skillLevel >= Config.getInstance().getRepairDiamondLevelRequirement() && Permissions.getInstance().diamondRepair(player)) { else if (ItemChecks.isDiamondTool(is) && inventory.contains(configInstance.getRepairDiamondMaterial()) && skillLevel >= configInstance.getRepairDiamondLevelRequirement() && permInstance.diamondRepair(player)) {
repairItem(player, is, new ItemStack(Config.getInstance().getRepairDiamondMaterial())); repairItem(player, is, new ItemStack(configInstance.getRepairDiamondMaterial()));
xpHandler(player, PP, is, durabilityBefore, 1, true); xpHandler(player, PP, is, durabilityBefore, 1, true);
} }
else if (ItemChecks.isGoldTool(is) && inventory.contains(Config.getInstance().getRepairGoldMaterial()) && skillLevel >= Config.getInstance().getRepairGoldLevelRequirement() && Permissions.getInstance().goldRepair(player)) { else if (ItemChecks.isGoldTool(is) && inventory.contains(configInstance.getRepairGoldMaterial()) && skillLevel >= configInstance.getRepairGoldLevelRequirement() && permInstance.goldRepair(player)) {
repairItem(player, is, new ItemStack(Config.getInstance().getRepairGoldMaterial())); repairItem(player, is, new ItemStack(configInstance.getRepairGoldMaterial()));
xpHandler(player, PP, is, durabilityBefore, 8, true); xpHandler(player, PP, is, durabilityBefore, 8, true);
} }
else if (ItemChecks.isStringTool(is) && inventory.contains(Config.getInstance().getRepairStringMaterial()) && Permissions.getInstance().stringRepair(player)){ else if (ItemChecks.isStringTool(is) && inventory.contains(configInstance.getRepairStringMaterial()) && permInstance.stringRepair(player)){
repairItem(player, is, new ItemStack(Config.getInstance().getRepairStringMaterial())); repairItem(player, is, new ItemStack(configInstance.getRepairStringMaterial()));
xpHandler(player, PP, is, durabilityBefore, 2, false); xpHandler(player, PP, is, durabilityBefore, 2, false);
} }
else { else {
needMoreVespeneGas(is, player); //UNABLE TO REPAIR needMoreVespeneGas(is, player); //UNABLE TO REPAIR
} }
} }
/*
* REPAIR CUSTOM TOOLS
*/
else if (ItemChecks.isCustomTool(is) && permInstance.toolRepair(player)) {
LoadCustomTools toolsInstance = LoadCustomTools.getInstance();
for (CustomTool tool : toolsInstance.customTools) {
if (tool.getItemID() == is.getTypeId()) {
if (inventory.contains(tool.getRepairMaterial())) {
repairCustomItem(player, is, tool.getRepairMaterial());
xpHandler(player, PP, is, durabilityBefore, 1, true);
}
else {
needMoreVespeneGas(is, player);
}
break;
}
}
}
} }
else { else {
player.sendMessage(LocaleLoader.getString("Repair.Skills.FullDurability")); player.sendMessage(LocaleLoader.getString("Repair.Skills.FullDurability"));
@ -129,6 +154,7 @@ public class Repair {
dif = (short) (dif / modify); dif = (short) (dif / modify);
} }
//TODO: What exactly is this for, and should we have it for armor as well?
if (ItemChecks.isShovel(is)) { if (ItemChecks.isShovel(is)) {
dif = (short) (dif / 3); dif = (short) (dif / 3);
} }
@ -143,7 +169,7 @@ public class Repair {
Skills.XpCheckSkill(SkillType.REPAIR, player); Skills.XpCheckSkill(SkillType.REPAIR, player);
//CLANG CLANG //CLANG CLANG
if (Config.getInstance().spoutEnabled) { if (configInstance.spoutEnabled) {
SpoutSounds.playRepairNoise(player, mcMMO.p); SpoutSounds.playRepairNoise(player, mcMMO.p);
} }
} }
@ -157,16 +183,16 @@ public class Repair {
public static int getArcaneForgingRank(PlayerProfile PP) { public static int getArcaneForgingRank(PlayerProfile PP) {
int skillLevel = PP.getSkillLevel(SkillType.REPAIR); int skillLevel = PP.getSkillLevel(SkillType.REPAIR);
if (skillLevel >= Config.getInstance().getArcaneForgingRankLevels4()) { if (skillLevel >= configInstance.getArcaneForgingRankLevels4()) {
return 4; return 4;
} }
else if (skillLevel >= Config.getInstance().getArcaneForgingRankLevels3()) { else if (skillLevel >= configInstance.getArcaneForgingRankLevels3()) {
return 3; return 3;
} }
else if (skillLevel >= Config.getInstance().getArcaneForgingRankLevels2()) { else if (skillLevel >= configInstance.getArcaneForgingRankLevels2()) {
return 2; return 2;
} }
else if (skillLevel >= Config.getInstance().getArcaneForgingRankLevels1()) { else if (skillLevel >= configInstance.getArcaneForgingRankLevels1()) {
return 1; return 1;
} }
else { else {
@ -189,7 +215,7 @@ public class Repair {
int rank = getArcaneForgingRank(Users.getProfile(player)); int rank = getArcaneForgingRank(Users.getProfile(player));
if (rank == 0 || !Permissions.getInstance().arcaneForging(player)) { if (rank == 0 || !permInstance.arcaneForging(player)) {
for (Enchantment x : enchants.keySet()) { for (Enchantment x : enchants.keySet()) {
is.removeEnchantment(x); is.removeEnchantment(x);
} }
@ -205,7 +231,7 @@ public class Repair {
if (random.nextInt(100) <= getEnchantChance(rank)) { if (random.nextInt(100) <= getEnchantChance(rank)) {
int enchantLevel = enchant.getValue(); int enchantLevel = enchant.getValue();
if (Config.getInstance().getArcaneForgingDowngradeEnabled() && enchantLevel > 1) { if (configInstance.getArcaneForgingDowngradeEnabled() && enchantLevel > 1) {
if (random.nextInt(100) <= getDowngradeChance(rank)) { if (random.nextInt(100) <= getDowngradeChance(rank)) {
is.addEnchantment(enchantment, enchantLevel--); is.addEnchantment(enchantment, enchantLevel--);
downgraded = true; downgraded = true;
@ -239,16 +265,16 @@ public class Repair {
public static int getEnchantChance(int rank) { public static int getEnchantChance(int rank) {
switch (rank) { switch (rank) {
case 4: case 4:
return Config.getInstance().getArcaneForgingKeepEnchantsChanceRank4(); return configInstance.getArcaneForgingKeepEnchantsChanceRank4();
case 3: case 3:
return Config.getInstance().getArcaneForgingKeepEnchantsChanceRank3(); return configInstance.getArcaneForgingKeepEnchantsChanceRank3();
case 2: case 2:
return Config.getInstance().getArcaneForgingKeepEnchantsChanceRank2(); return configInstance.getArcaneForgingKeepEnchantsChanceRank2();
case 1: case 1:
return Config.getInstance().getArcaneForgingKeepEnchantsChanceRank1(); return configInstance.getArcaneForgingKeepEnchantsChanceRank1();
default: default:
return 0; return 0;
@ -264,16 +290,16 @@ public class Repair {
public static int getDowngradeChance(int rank) { public static int getDowngradeChance(int rank) {
switch (rank) { switch (rank) {
case 4: case 4:
return Config.getInstance().getArcaneForgingDowngradeChanceRank4(); return configInstance.getArcaneForgingDowngradeChanceRank4();
case 3: case 3:
return Config.getInstance().getArcaneForgingDowngradeChanceRank3(); return configInstance.getArcaneForgingDowngradeChanceRank3();
case 2: case 2:
return Config.getInstance().getArcaneForgingDowngradeChanceRank2(); return configInstance.getArcaneForgingDowngradeChanceRank2();
case 1: case 1:
return Config.getInstance().getArcaneForgingDowngradeChanceRank1(); return configInstance.getArcaneForgingDowngradeChanceRank1();
default: default:
return 100; return 100;
@ -285,23 +311,23 @@ public class Repair {
* *
* @param player The player repairing an item * @param player The player repairing an item
* @param durability The durability of the item being repaired * @param durability The durability of the item being repaired
* @param ramt The base amount of durability repaired to the item * @param repairAmount The base amount of durability repaired to the item
* @return The final amount of durability repaired to the item * @return The final amount of durability repaired to the item
*/ */
private static short repairCalculate(Player player, short durability, int ramt) { private static short repairCalculate(Player player, short durability, int repairAmount) {
int skillLevel = Users.getProfile(player).getSkillLevel(SkillType.REPAIR); int skillLevel = Users.getProfile(player).getSkillLevel(SkillType.REPAIR);
float bonus = (float) skillLevel / 500; float bonus = (float) skillLevel / 500;
if (Permissions.getInstance().repairMastery(player)) { if (permInstance.repairMastery(player)) {
bonus = (ramt * bonus); bonus = (repairAmount * bonus);
ramt += bonus; repairAmount += bonus;
} }
if (checkPlayerProcRepair(player)) { if (checkPlayerProcRepair(player)) {
ramt = (short) (ramt * 2); repairAmount = (short) (repairAmount * 2);
} }
durability -= ramt; durability -= repairAmount;
if (durability < 0) { if (durability < 0) {
durability = 0; durability = 0;
@ -319,31 +345,56 @@ public class Repair {
*/ */
private static short getRepairAmount(ItemStack is, Player player){ private static short getRepairAmount(ItemStack is, Player player){
short maxDurability = is.getType().getMaxDurability(); short maxDurability = is.getType().getMaxDurability();
int ramt = 0; int repairAmount = 0;
if (ItemChecks.isShovel(is)) { if (ItemChecks.isShovel(is)) {
ramt = maxDurability; repairAmount = maxDurability;
} }
else if (ItemChecks.isHoe(is) || ItemChecks.isSword(is) || is.getType().equals(Material.SHEARS)) { else if (ItemChecks.isHoe(is) || ItemChecks.isSword(is) || is.getType().equals(Material.SHEARS) || is.getType().equals(Material.FISHING_ROD)) {
ramt = maxDurability / 2; repairAmount = maxDurability / 2;
} }
else if (ItemChecks.isAxe(is) || ItemChecks.isPickaxe(is) || ItemChecks.isStringTool(is)) { else if (ItemChecks.isAxe(is) || ItemChecks.isPickaxe(is) || is.getType().equals(Material.BOW)) {
ramt = maxDurability / 3; repairAmount = maxDurability / 3;
} }
else if (ItemChecks.isBoots(is)) { else if (ItemChecks.isBoots(is)) {
ramt = maxDurability / 4; repairAmount = maxDurability / 4;
} }
else if (ItemChecks.isHelmet(is)) { else if (ItemChecks.isHelmet(is)) {
ramt = maxDurability / 5; repairAmount = maxDurability / 5;
} }
else if (ItemChecks.isPants(is)) { else if (ItemChecks.isPants(is)) {
ramt = maxDurability / 7; repairAmount = maxDurability / 7;
} }
else if (ItemChecks.isChestplate(is)) { else if (ItemChecks.isChestplate(is)) {
ramt = maxDurability / 8; repairAmount = maxDurability / 8;
} }
return repairCalculate(player, is.getDurability(), ramt); return repairCalculate(player, is.getDurability(), repairAmount);
}
/**
* Gets the base durability amount to repair a custom item.
*
* @param is The custom item being repaired
* @param player The player repairing the custom item
* @return The final amount of durability repaired to the custom item
*/
private static short getCustomRepairAmount(ItemStack is, Player player) {
short maxDurability = 0;
int materialsRequired = 0;
int repairAmount = 0;
for (CustomTool tool : LoadCustomTools.getInstance().customTools) {
if (tool.getItemID() == is.getTypeId()) {
maxDurability = tool.getDurability();
materialsRequired = tool.getRepairQuantity();
break;
}
}
repairAmount = maxDurability / materialsRequired;
return repairCalculate(player, is.getDurability(), repairAmount);
} }
/** /**
@ -360,45 +411,48 @@ public class Repair {
} }
else { else {
if (ItemChecks.isDiamondTool(is) || ItemChecks.isDiamondArmor(is)) { if (ItemChecks.isDiamondTool(is) || ItemChecks.isDiamondArmor(is)) {
if (skillLevel < Config.getInstance().getRepairDiamondLevelRequirement()) { if (skillLevel < configInstance.getRepairDiamondLevelRequirement()) {
player.sendMessage(LocaleLoader.getString("Repair.Skills.AdeptDiamond")); player.sendMessage(LocaleLoader.getString("Repair.Skills.AdeptDiamond"));
} }
else { else {
player.sendMessage(LocaleLoader.getString("Skills.NeedMore") + " " + ChatColor.BLUE + Misc.prettyItemString(Config.getInstance().getRepairDiamondMaterial())); player.sendMessage(LocaleLoader.getString("Skills.NeedMore") + " " + ChatColor.BLUE + Misc.prettyItemString(configInstance.getRepairDiamondMaterial()));
} }
} }
else if (ItemChecks.isIronTool(is) || ItemChecks.isIronArmor(is)) { else if (ItemChecks.isIronTool(is) || ItemChecks.isIronArmor(is)) {
if (skillLevel < Config.getInstance().getRepairIronLevelRequirement()) { if (skillLevel < configInstance.getRepairIronLevelRequirement()) {
player.sendMessage(LocaleLoader.getString("Repair.Skills.AdeptIron")); player.sendMessage(LocaleLoader.getString("Repair.Skills.AdeptIron"));
} }
else { else {
player.sendMessage(LocaleLoader.getString("Skills.NeedMore")+ " " + ChatColor.GRAY + Misc.prettyItemString(Config.getInstance().getRepairIronMaterial())); player.sendMessage(LocaleLoader.getString("Skills.NeedMore")+ " " + ChatColor.GRAY + Misc.prettyItemString(configInstance.getRepairIronMaterial()));
} }
} }
else if (ItemChecks.isGoldTool(is) || ItemChecks.isGoldArmor(is)) { else if (ItemChecks.isGoldTool(is) || ItemChecks.isGoldArmor(is)) {
if (skillLevel < Config.getInstance().getRepairGoldLevelRequirement()) { if (skillLevel < configInstance.getRepairGoldLevelRequirement()) {
player.sendMessage(LocaleLoader.getString("Repair.Skills.AdeptGold")); player.sendMessage(LocaleLoader.getString("Repair.Skills.AdeptGold"));
} }
else { else {
player.sendMessage(LocaleLoader.getString("Skills.NeedMore") + " " + ChatColor.GOLD + Misc.prettyItemString(Config.getInstance().getRepairGoldMaterial())); player.sendMessage(LocaleLoader.getString("Skills.NeedMore") + " " + ChatColor.GOLD + Misc.prettyItemString(configInstance.getRepairGoldMaterial()));
} }
} }
else if (ItemChecks.isStoneTool(is)) { else if (ItemChecks.isStoneTool(is)) {
if (skillLevel < Config.getInstance().getRepairStoneLevelRequirement()) { if (skillLevel < configInstance.getRepairStoneLevelRequirement()) {
player.sendMessage(LocaleLoader.getString("Repair.Skills.AdeptStone")); player.sendMessage(LocaleLoader.getString("Repair.Skills.AdeptStone"));
} }
else { else {
player.sendMessage(LocaleLoader.getString("Skills.NeedMore") + " " + ChatColor.GRAY + Misc.prettyItemString(Config.getInstance().getRepairStoneMaterial())); player.sendMessage(LocaleLoader.getString("Skills.NeedMore") + " " + ChatColor.GRAY + Misc.prettyItemString(configInstance.getRepairStoneMaterial()));
} }
} }
else if (ItemChecks.isWoodTool(is)) { else if (ItemChecks.isWoodTool(is)) {
player.sendMessage(LocaleLoader.getString("Skills.NeedMore") + " " + ChatColor.DARK_GREEN + Misc.prettyItemString(Config.getInstance().getRepairWoodMaterial())); player.sendMessage(LocaleLoader.getString("Skills.NeedMore") + " " + ChatColor.DARK_GREEN + Misc.prettyItemString(configInstance.getRepairWoodMaterial()));
} }
else if (ItemChecks.isLeatherArmor(is)) { else if (ItemChecks.isLeatherArmor(is)) {
player.sendMessage(LocaleLoader.getString("Skills.NeedMore") + " " + ChatColor.YELLOW + Misc.prettyItemString(Config.getInstance().getRepairLeatherMaterial())); player.sendMessage(LocaleLoader.getString("Skills.NeedMore") + " " + ChatColor.YELLOW + Misc.prettyItemString(configInstance.getRepairLeatherMaterial()));
} }
else if (ItemChecks.isStringTool(is)) { else if (ItemChecks.isStringTool(is)) {
player.sendMessage(LocaleLoader.getString("Skills.NeedMore") + " " + ChatColor.YELLOW + Misc.prettyItemString(Config.getInstance().getRepairStringMaterial())); player.sendMessage(LocaleLoader.getString("Skills.NeedMore") + " " + ChatColor.YELLOW + Misc.prettyItemString(configInstance.getRepairStringMaterial()));
}
else {
player.sendMessage("You do not have the material needed to repair this item!"); //TODO: Use locale
} }
} }
} }
@ -414,7 +468,7 @@ public class Repair {
int skillLevel = Users.getProfile(player).getSkillLevel(SkillType.REPAIR); int skillLevel = Users.getProfile(player).getSkillLevel(SkillType.REPAIR);
if ((skillLevel > MAX_BONUS_LEVEL || random.nextInt(1000) <= skillLevel) && Permissions.getInstance().repairBonus(player)) { if ((skillLevel > MAX_BONUS_LEVEL || random.nextInt(1000) <= skillLevel) && permInstance.repairBonus(player)) {
player.sendMessage(LocaleLoader.getString("Repair.Skills.FeltEasy")); player.sendMessage(LocaleLoader.getString("Repair.Skills.FeltEasy"));
return true; return true;
} }
@ -429,7 +483,7 @@ public class Repair {
* @param item The item being repaired * @param item The item being repaired
* @param repairMaterial The repair reagent * @param repairMaterial The repair reagent
*/ */
public static void repairItem(Player player, ItemStack item, ItemStack repairMaterial) { private static void repairItem(Player player, ItemStack item, ItemStack repairMaterial) {
short initialDurability = item.getDurability(); short initialDurability = item.getDurability();
short newDurability = getRepairAmount(item, player); short newDurability = getRepairAmount(item, player);
PlayerInventory inventory = player.getInventory(); PlayerInventory inventory = player.getInventory();
@ -449,13 +503,36 @@ public class Repair {
} }
/* Handle the enchants */ /* Handle the enchants */
if (Config.getInstance().getArcaneForgingEnchantLossEnabled() && !Permissions.getInstance().arcaneBypass(player)) { if (configInstance.getArcaneForgingEnchantLossEnabled() && !permInstance.arcaneBypass(player)) {
addEnchants(player, item); addEnchants(player, item);
} }
item.setDurability(newDurability); item.setDurability(newDurability);
} }
/**
* Repairs a custom item.
*
* @param player The player repairing an item
* @param item The custom item being repaired
* @param repairMaterial The repair reagent
*/
private static void repairCustomItem(Player player, ItemStack item, ItemStack repairMaterial) {
short initialDurability = item.getDurability();
short newDurability = getCustomRepairAmount(item, player);
PlayerInventory inventory = player.getInventory();
McMMOPlayerRepairCheckEvent event = new McMMOPlayerRepairCheckEvent(player, (short) (initialDurability - newDurability), repairMaterial, item);
mcMMO.p.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return;
}
inventory.removeItem(repairMaterial);
item.setDurability(newDurability);
}
/** /**
* Handles notifications for placing an anvil. * Handles notifications for placing an anvil.
* *
@ -466,7 +543,7 @@ public class Repair {
PlayerProfile PP = Users.getProfile(player); PlayerProfile PP = Users.getProfile(player);
if (!PP.getPlacedAnvil()) { if (!PP.getPlacedAnvil()) {
if (Config.getInstance().spoutEnabled) { if (configInstance.spoutEnabled) {
SpoutPlayer sPlayer = SpoutManager.getPlayer(player); SpoutPlayer sPlayer = SpoutManager.getPlayer(player);
if (sPlayer.isSpoutCraftEnabled()) { if (sPlayer.isSpoutCraftEnabled()) {

View File

@ -7,6 +7,7 @@ import com.gmail.nossr50.config.mods.LoadCustomTools;
public class ItemChecks { public class ItemChecks {
private static Config configInstance = Config.getInstance(); private static Config configInstance = Config.getInstance();
private static boolean customToolsEnabled = configInstance.getToolModsEnabled();
/** /**
* Checks if the item is a sword. * Checks if the item is a sword.
@ -24,7 +25,7 @@ public class ItemChecks {
return true; return true;
default: default:
if (configInstance.getToolModsEnabled() && LoadCustomTools.getInstance().customSwordIDs.contains(is.getTypeId())) { if (customToolsEnabled && LoadCustomTools.getInstance().customSwordIDs.contains(is.getTypeId())) {
return true; return true;
} }
else { else {
@ -49,7 +50,7 @@ public class ItemChecks {
return true; return true;
default: default:
if (configInstance.getToolModsEnabled() && LoadCustomTools.getInstance().customHoeIDs.contains(is.getTypeId())) { if (customToolsEnabled && LoadCustomTools.getInstance().customHoeIDs.contains(is.getTypeId())) {
return true; return true;
} }
else { else {
@ -74,7 +75,7 @@ public class ItemChecks {
return true; return true;
default: default:
if (configInstance.getToolModsEnabled() && LoadCustomTools.getInstance().customShovelIDs.contains(is.getTypeId())) { if (customToolsEnabled && LoadCustomTools.getInstance().customShovelIDs.contains(is.getTypeId())) {
return true; return true;
} }
else { else {
@ -99,7 +100,7 @@ public class ItemChecks {
return true; return true;
default: default:
if (configInstance.getToolModsEnabled() && LoadCustomTools.getInstance().customAxeIDs.contains(is.getTypeId())) { if (customToolsEnabled && LoadCustomTools.getInstance().customAxeIDs.contains(is.getTypeId())) {
return true; return true;
} }
else { else {
@ -124,7 +125,7 @@ public class ItemChecks {
return true; return true;
default: default:
if (configInstance.getToolModsEnabled() && LoadCustomTools.getInstance().customPickaxeIDs.contains(is.getTypeId())) { if (customToolsEnabled && LoadCustomTools.getInstance().customPickaxeIDs.contains(is.getTypeId())) {
return true; return true;
} }
else { else {
@ -305,6 +306,21 @@ public class ItemChecks {
return isStoneTool(is) || isWoodTool(is) || isGoldTool(is) || isIronTool(is) || isDiamondTool(is) || isStringTool(is); return isStoneTool(is) || isWoodTool(is) || isGoldTool(is) || isIronTool(is) || isDiamondTool(is) || isStringTool(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 isCustomTool(ItemStack is) {
if (customToolsEnabled && LoadCustomTools.getInstance().customIDs.contains(is.getTypeId())) {
return true;
}
else {
return false;
}
}
/** /**
* Checks to see if an item is a stone tool. * Checks to see if an item is a stone tool.
* *

View File

@ -5,16 +5,20 @@ Axes:
Axe_1: Axe_1:
ID: 999 ID: 999
XP_Modifer: 1.0 XP_Modifer: 1.0
Ability_Enabled: true
Repairable: true Repairable: true
Repair_Material_ID: 99 Repair_Material_ID: 99
Repair_Material_Data_Value: 0 Repair_Material_Data_Value: 0
Repair_Material_Quantity: 9
Durability: 9999 Durability: 9999
Axe_2: Axe_2:
ID: 999 ID: 999
XP_Modifer: 1.0 XP_Modifer: 1.0
Ability_Enabled: true
Repairable: true Repairable: true
Repair_Material_ID: 99 Repair_Material_ID: 99
Repair_Material_Data_Value: 0 Repair_Material_Data_Value: 0
Repair_Material_Quantity: 9
Durability: 9999 Durability: 9999
# #
@ -24,16 +28,20 @@ Bows:
Bow_1: Bow_1:
ID: 999 ID: 999
XP_Modifer: 1.0 XP_Modifer: 1.0
Ability_Enabled: true
Repairable: true Repairable: true
Repair_Material_ID: 99 Repair_Material_ID: 99
Repair_Material_Data_Value: 0 Repair_Material_Data_Value: 0
Repair_Material_Quantity: 9
Durability: 9999 Durability: 9999
Bow_2: Bow_2:
ID: 999 ID: 999
XP_Modifer: 1.0 XP_Modifer: 1.0
Ability_Enabled: true
Repairable: true Repairable: true
Repair_Material_ID: 99 Repair_Material_ID: 99
Repair_Material_Data_Value: 0 Repair_Material_Data_Value: 0
Repair_Material_Quantity: 9
Durability: 9999 Durability: 9999
# #
@ -43,16 +51,20 @@ Hoes:
Hoe_1: Hoe_1:
ID: 999 ID: 999
XP_Modifer: 1.0 XP_Modifer: 1.0
Ability_Enabled: true
Repairable: true Repairable: true
Repair_Material_ID: 99 Repair_Material_ID: 99
Repair_Material_Data_Value: 0 Repair_Material_Data_Value: 0
Repair_Material_Quantity: 9
Durability: 9999 Durability: 9999
Hoe_2: Hoe_2:
ID: 999 ID: 999
XP_Modifer: 1.0 XP_Modifer: 1.0
Ability_Enabled: true
Repairable: true Repairable: true
Repair_Material_ID: 99 Repair_Material_ID: 99
Repair_Material_Data_Value: 0 Repair_Material_Data_Value: 0
Repair_Material_Quantity: 9
Durability: 9999 Durability: 9999
# #
@ -62,16 +74,20 @@ Pickaxes:
Pickaxe_1: Pickaxe_1:
ID: 999 ID: 999
XP_Modifer: 1.0 XP_Modifer: 1.0
Ability_Enabled: true
Repairable: true Repairable: true
Repair_Material_ID: 99 Repair_Material_ID: 99
Repair_Material_Data_Value: 0 Repair_Material_Data_Value: 0
Repair_Material_Quantity: 9
Durability: 9999 Durability: 9999
Pickaxe_2: Pickaxe_2:
ID: 999 ID: 999
XP_Modifer: 1.0 XP_Modifer: 1.0
Ability_Enabled: true
Repairable: true Repairable: true
Repair_Material_ID: 99 Repair_Material_ID: 99
Repair_Material_Data_Value: 0 Repair_Material_Data_Value: 0
Repair_Material_Quantity: 9
Durability: 9999 Durability: 9999
# #
@ -81,16 +97,20 @@ Shovels:
Shovel_1: Shovel_1:
ID: 999 ID: 999
XP_Modifer: 1.0 XP_Modifer: 1.0
Ability_Enabled: true
Repairable: true Repairable: true
Repair_Material_ID: 99 Repair_Material_ID: 99
Repair_Material_Data_Value: 0 Repair_Material_Data_Value: 0
Repair_Material_Quantity: 9
Durability: 9999 Durability: 9999
Shovel_2: Shovel_2:
ID: 999 ID: 999
XP_Modifer: 1.0 XP_Modifer: 1.0
Ability_Enabled: true
Repairable: true Repairable: true
Repair_Material_ID: 99 Repair_Material_ID: 99
Repair_Material_Data_Value: 0 Repair_Material_Data_Value: 0
Repair_Material_Quantity: 9
Durability: 9999 Durability: 9999
# #
@ -100,14 +120,18 @@ Swords:
Sword_1: Sword_1:
ID: 999 ID: 999
XP_Modifer: 1.0 XP_Modifer: 1.0
Ability_Enabled: true
Repairable: true Repairable: true
Repair_Material_ID: 99 Repair_Material_ID: 99
Repair_Material_Data_Value: 0 Repair_Material_Data_Value: 0
Repair_Material_Quantity: 9
Durability: 9999 Durability: 9999
Sword_2: Sword_2:
ID: 999 ID: 999
XP_Modifer: 1.0 XP_Modifer: 1.0
Ability_Enabled: true
Repairable: true Repairable: true
Repair_Material_ID: 99 Repair_Material_ID: 99
Repair_Material_Data_Value: 0 Repair_Material_Data_Value: 0
Repair_Material_Quantity: 9
Durability: 9999 Durability: 9999