Browse Source

Merge branch 'master' of github.com:mcMMO-Dev/mcMMO into configurable

nossr50 6 years ago
parent
commit
473e4586c9

+ 4 - 0
Changelog.txt

@@ -164,6 +164,10 @@ Version 2.2.0
     Added API method to grab the level cap of a skill by its PrimarySkillType ENUM definition
     Added API method to check if a skill was being level capped
     Added 'UndefinedSkillBehaviour' for trying to use a method that has no behaviour defined for the provided skill
+Version 2.1.78
+    Shovels no longer take more than 1 diamond to repair
+    Tools with the unbreaking enchantment no longer take extra damage from ability usage, they are still subject to the normal durability damage from breaking blocks though.
+
 Version 2.1.77
     Added minimum quantity back to Repair config
 

+ 4 - 0
src/main/java/com/gmail/nossr50/config/hocon/serializers/RepairableSerializer.java

@@ -57,6 +57,10 @@ public class RepairableSerializer implements TypeSerializer<Repairable> {
         Material repairItem = (Material) getEnum(repairConstant, TypeToken.of(Material.class));*/
 
         int minimumQuantity = value.getNode(MINIMUM_QUANTITY_USED_TO_REPAIR).getValue(TypeToken.of(Integer.class));
+
+        if(minimumQuantity == 0)
+            minimumQuantity = -1;
+
         int minimumLevel = value.getNode(OVERRIDE_LEVEL_REQUIREMENT).getValue(TypeToken.of(Integer.class));
         double xpMultiplier = value.getNode(XP_MULTIPLIER).getValue(TypeToken.of(Double.class));
 

+ 5 - 1
src/main/java/com/gmail/nossr50/skills/repair/repairables/Repairable.java

@@ -3,6 +3,7 @@ package com.gmail.nossr50.skills.repair.repairables;
 import com.gmail.nossr50.datatypes.skills.ItemMaterialCategory;
 import com.gmail.nossr50.datatypes.skills.ItemType;
 import com.gmail.nossr50.util.ItemUtils;
+import com.gmail.nossr50.util.skills.SkillUtils;
 import org.bukkit.Material;
 
 import java.util.Collections;
@@ -61,7 +62,10 @@ public class Repairable {
     }
 
     public int getMinimumQuantity() {
-        return minimumQuantity;
+        if(minimumQuantity == -1)
+            return Math.max(SkillUtils.getRepairAndSalvageQuantities(itemMaterial, repairMaterials), 1);
+        else
+            return minimumQuantity;
     }
 
     public short getMaximumDurability() {

+ 6 - 0
src/main/java/com/gmail/nossr50/skills/woodcutting/Woodcutting.java

@@ -8,6 +8,7 @@ import com.gmail.nossr50.util.skills.SkillUtils;
 import org.bukkit.Material;
 import org.bukkit.block.BlockFace;
 import org.bukkit.block.BlockState;
+import org.bukkit.enchantments.Enchantment;
 import org.bukkit.inventory.ItemStack;
 
 import java.util.ArrayList;
@@ -136,6 +137,11 @@ public final class Woodcutting {
      * @return True if the tool can sustain the durability loss
      */
     protected static boolean handleDurabilityLoss(Set<BlockState> treeFellerBlocks, ItemStack inHand) {
+
+        if(inHand.getItemMeta().getEnchants().get(Enchantment.DURABILITY) >= 1) {
+            return true;
+        }
+
         short durabilityLoss = 0;
         Material type = inHand.getType();
 

+ 41 - 1
src/main/java/com/gmail/nossr50/util/skills/SkillUtils.java

@@ -228,7 +228,7 @@ public class SkillUtils {
      * @param maxDamageModifier  the amount to adjust the max damage by
      */
     public static void handleDurabilityChange(ItemStack itemStack, double durabilityModifier, double maxDamageModifier) {
-        if (itemStack.hasItemMeta() && itemStack.getItemMeta().isUnbreakable()) {
+        if (itemStack.getEnchantments().get(Enchantment.DURABILITY) != null && itemStack.getEnchantments().get(Enchantment.DURABILITY) >= 1) {
             return;
         }
 
@@ -303,4 +303,44 @@ public class SkillUtils {
 
         return quantity;
     }
+
+    public static int getRepairAndSalvageQuantities(Material itemMaterial, List<Material> recipeMaterials) {
+        int quantity = 0;
+
+        for(Iterator<? extends Recipe> recipeIterator = Bukkit.getServer().recipeIterator(); recipeIterator.hasNext();) {
+            Recipe bukkitRecipe = recipeIterator.next();
+
+            if(bukkitRecipe.getResult().getType() != itemMaterial)
+                continue;
+
+            boolean matchedIngredient = false;
+
+            for(Material recipeMaterial : recipeMaterials) {
+                if(matchedIngredient)
+                    break;
+
+                if(bukkitRecipe instanceof ShapelessRecipe) {
+                    for (ItemStack ingredient : ((ShapelessRecipe) bukkitRecipe).getIngredientList()) {
+                        if (ingredient != null
+                                && (recipeMaterial == null || ingredient.getType() == recipeMaterial)
+                                && (ingredient.getType() == recipeMaterial)) {
+                            quantity += ingredient.getAmount();
+                            matchedIngredient = true;
+                        }
+                    }
+                } else if(bukkitRecipe instanceof ShapedRecipe) {
+                    for (ItemStack ingredient : ((ShapedRecipe) bukkitRecipe).getIngredientMap().values()) {
+                        if (ingredient != null
+                                && (recipeMaterial == null || ingredient.getType() == recipeMaterial)
+                                && (ingredient.getType() == recipeMaterial)) {
+                            quantity += ingredient.getAmount();
+                            matchedIngredient = true;
+                        }
+                    }
+                }
+            }
+        }
+
+        return quantity;
+    }
 }