From ead13981325993c7d463a1b863cdd7bc02e35789 Mon Sep 17 00:00:00 2001 From: TfT_02 Date: Fri, 9 Aug 2013 22:21:45 +0200 Subject: [PATCH] Super Breaker & Giga Driller now use more durability A configurable amount is added to the vanilla durability loss. Use `Abilities.Tools.Durability_Loss` to disable (set to 0) or set it to -1 for no durability loss while using abilities. Closes #1363 --- Changelog.txt | 1 + .../java/com/gmail/nossr50/config/Config.java | 4 ---- .../skills/excavation/ExcavationManager.java | 3 +++ .../nossr50/skills/mining/MiningManager.java | 4 ++++ .../gmail/nossr50/util/skills/SkillUtils.java | 17 ++++++++++++++++- 5 files changed, 24 insertions(+), 5 deletions(-) diff --git a/Changelog.txt b/Changelog.txt index 0a2a08812..604955921 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -22,6 +22,7 @@ Version 1.4.07-dev ! Improved profile saving ! Updated localization files ! Party item share category states are now saved when the server shuts down. + ! When using Super Breaker or Giga Driller abilities extra tool durability is used (again) - Removed Abilities.Tools.Durability_Loss_Enabled, set Abilities.Tools.Durability_Loss to 0 to disable instead. Version 1.4.06 diff --git a/src/main/java/com/gmail/nossr50/config/Config.java b/src/main/java/com/gmail/nossr50/config/Config.java index 95a658419..47aa1543f 100644 --- a/src/main/java/com/gmail/nossr50/config/Config.java +++ b/src/main/java/com/gmail/nossr50/config/Config.java @@ -133,10 +133,6 @@ public class Config extends AutoUpdateConfigLoader { reason.add("Commands.inspect.Max_Distance should be greater than 0!"); } - if (getAbilityToolDamage() < 0) { - reason.add("Abilities.Tools.Durability_Loss should be at least 0!"); - } - if (getTreeFellerThreshold() <= 0) { reason.add("Abilities.Limits.Tree_Feller_Threshold should be greater than 0!"); } diff --git a/src/main/java/com/gmail/nossr50/skills/excavation/ExcavationManager.java b/src/main/java/com/gmail/nossr50/skills/excavation/ExcavationManager.java index 264691c6c..987e4a309 100644 --- a/src/main/java/com/gmail/nossr50/skills/excavation/ExcavationManager.java +++ b/src/main/java/com/gmail/nossr50/skills/excavation/ExcavationManager.java @@ -5,6 +5,7 @@ import java.util.List; import org.bukkit.Location; import org.bukkit.block.BlockState; +import com.gmail.nossr50.config.Config; import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.datatypes.treasure.ExcavationTreasure; @@ -53,5 +54,7 @@ public class ExcavationManager extends SkillManager { public void gigaDrillBreaker(BlockState blockState) { excavationBlockCheck(blockState); excavationBlockCheck(blockState); + + SkillUtils.handleDurabilityChange(getPlayer().getItemInHand(), Config.getInstance().getAbilityToolDamage()); } } diff --git a/src/main/java/com/gmail/nossr50/skills/mining/MiningManager.java b/src/main/java/com/gmail/nossr50/skills/mining/MiningManager.java index c0d45172f..e7a67f502 100644 --- a/src/main/java/com/gmail/nossr50/skills/mining/MiningManager.java +++ b/src/main/java/com/gmail/nossr50/skills/mining/MiningManager.java @@ -66,6 +66,10 @@ public class MiningManager extends SkillManager { Material material = blockState.getType(); + if (mcMMOPlayer.getAbilityMode(skill.getAbility())) { + SkillUtils.handleDurabilityChange(getPlayer().getItemInHand(), Config.getInstance().getAbilityToolDamage()); + } + if (material != Material.GLOWING_REDSTONE_ORE && !Config.getInstance().getDoubleDropsEnabled(skill, material)) { return; } diff --git a/src/main/java/com/gmail/nossr50/util/skills/SkillUtils.java b/src/main/java/com/gmail/nossr50/util/skills/SkillUtils.java index 58785f35f..1f189ebd3 100644 --- a/src/main/java/com/gmail/nossr50/util/skills/SkillUtils.java +++ b/src/main/java/com/gmail/nossr50/util/skills/SkillUtils.java @@ -14,7 +14,6 @@ import org.bukkit.plugin.PluginManager; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; -import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.config.AdvancedConfig; import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.HiddenConfig; @@ -29,6 +28,7 @@ import com.gmail.nossr50.events.fake.FakeBlockDamageEvent; import com.gmail.nossr50.events.fake.FakePlayerAnimationEvent; import com.gmail.nossr50.events.skills.abilities.McMMOPlayerAbilityActivateEvent; import com.gmail.nossr50.locale.LocaleLoader; +import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.runnables.skills.AbilityDisableTask; import com.gmail.nossr50.runnables.skills.ToolLowerTask; import com.gmail.nossr50.util.ItemUtils; @@ -445,6 +445,21 @@ public class SkillUtils { return item; } + /** + * Modify the durability of an ItemStack. + * + * @param itemStack The ItemStack which durability should be modified + * @return the itemStack with modified durability + */ + public static ItemStack handleDurabilityChange(ItemStack itemStack, int durabilityModifier) { + short finalDurability = (short) (itemStack.getDurability() + durabilityModifier); + short maxDurability = ModUtils.isCustomTool(itemStack) ? ModUtils.getToolFromItemStack(itemStack).getDurability() : itemStack.getType().getMaxDurability(); + boolean overMax = (finalDurability >= maxDurability); + + itemStack.setDurability(overMax ? maxDurability : finalDurability); + return itemStack; + } + /** * Simulate a block break event. *