+ * A SimpleRepairCost can be one or more items, any one of which can be used to pay for a RepairTransaction
+ * If a SimpleRepairCost is more than one item, then only one of the items are required to represent its cost.
+ *
+ * This type is strictly for use with RepairTransaction, which represents the full cost of a Repair.
+ * @see com.gmail.nossr50.skills.repair.RepairTransaction for more details
+ */
+public class SimpleRepairCost implements RepairCost {
+
+ private ItemMatchProperty itemMatchProperty;
+
+ public SimpleRepairCost(ItemMatchProperty itemMatchProperty) {
+ this.itemMatchProperty = itemMatchProperty;
+ }
+
+ @Override
+ public ItemStack findPayment(PlayerInventory playerInventory) {
+ for(ItemStack itemStack : playerInventory.getContents()) {
+ if(itemStack == null || itemStack.getType() == Material.AIR) {
+ continue;
+ }
+
+ //Attempt to match the item in the inventory to any of the compatible repair items
+ if(hasStrictMatching()) {
+ //TODO: Replace with strict matching code
+ if(item)
+ return itemStack;
+ } else {
+ if(itemStack.getType() == itemMatchProperty.getType()) {
+ return itemStack;
+ }
+ }
+ }
+
+ return null;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(itemMatchProperty);
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof SimpleRepairCost)) return false;
+ SimpleRepairCost that = (SimpleRepairCost) o;
+ return itemMatchProperty.equals(that.itemMatchProperty);
+ }
+
+ @Override
+ public boolean hasStrictMatching() {
+ return strictMatching;
+ }
+}
diff --git a/src/main/java/com/gmail/nossr50/skills/repair/repairables/Repairable.java b/src/main/java/com/gmail/nossr50/skills/repair/repairables/Repairable.java
index f70287509..acf4dff93 100644
--- a/src/main/java/com/gmail/nossr50/skills/repair/repairables/Repairable.java
+++ b/src/main/java/com/gmail/nossr50/skills/repair/repairables/Repairable.java
@@ -12,7 +12,7 @@ public class Repairable {
private short maximumDurability;
private RepairTransaction repairTransaction;
private boolean strictMatchingItem = false;
- private boolean strictMatchingRepairTransaction = false;
+// private boolean strictMatchingRepairTransaction = false;
private int baseXP = 0;
private RawNBT rawNBT;
private int repairCount = 1;
@@ -20,13 +20,13 @@ public class Repairable {
private boolean hasPermission = false;
private boolean hasNBT = false;
- public Repairable(ItemStack item, int minimumLevel, short maximumDurability, RepairTransaction repairTransaction, boolean strictMatchingItem, boolean strictMatchingRepairTransaction, int baseXP, int repairCount) {
+ public Repairable(ItemStack item, int minimumLevel, short maximumDurability, RepairTransaction repairTransaction, boolean strictMatchingItem, int baseXP, int repairCount) {
this.item = item;
this.minimumLevel = minimumLevel;
this.maximumDurability = maximumDurability;
this.repairTransaction = repairTransaction;
this.strictMatchingItem = strictMatchingItem;
- this.strictMatchingRepairTransaction = strictMatchingRepairTransaction;
+// this.strictMatchingRepairTransaction = strictMatchingRepairTransaction;
this.baseXP = baseXP;
this.repairCount = repairCount;
}
@@ -67,13 +67,13 @@ public class Repairable {
this.strictMatchingItem = strictMatchingItem;
}
- public boolean isStrictMatchingRepairTransaction() {
- return strictMatchingRepairTransaction;
- }
-
- public void setStrictMatchingRepairTransaction(boolean strictMatchingRepairTransaction) {
- this.strictMatchingRepairTransaction = strictMatchingRepairTransaction;
- }
+// public boolean isStrictMatchingRepairTransaction() {
+// return strictMatchingRepairTransaction;
+// }
+//
+// public void setStrictMatchingRepairTransaction(boolean strictMatchingRepairTransaction) {
+// this.strictMatchingRepairTransaction = strictMatchingRepairTransaction;
+// }
public int getBaseXP() {
return baseXP;
diff --git a/src/main/java/com/gmail/nossr50/skills/repair/repairables/RepairableBuilder.java b/src/main/java/com/gmail/nossr50/skills/repair/repairables/RepairableBuilder.java
index 38c8835a0..7699a03b1 100644
--- a/src/main/java/com/gmail/nossr50/skills/repair/repairables/RepairableBuilder.java
+++ b/src/main/java/com/gmail/nossr50/skills/repair/repairables/RepairableBuilder.java
@@ -12,7 +12,7 @@ public class RepairableBuilder {
private short maximumDurability;
private RepairTransaction repairTransaction;
private boolean strictMatchingItem = false;
- private boolean strictMatchingRepairTransaction = false;
+// private boolean strictMatchingRepairTransaction = false;
private int baseXP = 0;
private RawNBT rawNBT;
private int repairCount = 1;
@@ -43,10 +43,10 @@ public class RepairableBuilder {
return this;
}
- public RepairableBuilder strictMatchingRepairTransaction(Boolean strictMatchingRepairTransaction) {
- this.strictMatchingRepairTransaction = strictMatchingRepairTransaction;
- return this;
- }
+// public RepairableBuilder strictMatchingRepairTransaction(Boolean strictMatchingRepairTransaction) {
+// this.strictMatchingRepairTransaction = strictMatchingRepairTransaction;
+// return this;
+// }
public RepairableBuilder baseXP(Integer baseXP) {
this.baseXP = baseXP;
@@ -74,7 +74,7 @@ public class RepairableBuilder {
private Repairable makeRepairable() {
Repairable repairable = new Repairable(item, minimumLevel, maximumDurability, repairTransaction,
- strictMatchingItem, strictMatchingRepairTransaction, baseXP, repairCount);
+ strictMatchingItem, baseXP, repairCount);
if(permissionWrapper != null) {
repairable.setPermissionWrapper(permissionWrapper);
diff --git a/src/main/java/com/gmail/nossr50/util/nbt/NBTUtils.java b/src/main/java/com/gmail/nossr50/util/nbt/NBTUtils.java
index 3659a75f4..29d2e7c23 100644
--- a/src/main/java/com/gmail/nossr50/util/nbt/NBTUtils.java
+++ b/src/main/java/com/gmail/nossr50/util/nbt/NBTUtils.java
@@ -1,6 +1,26 @@
package com.gmail.nossr50.util.nbt;
+import com.gmail.nossr50.mcMMO;
+import net.minecraft.server.v1_13_R2.NBTBase;
+import org.bukkit.craftbukkit.v1_13_R2.entity.CraftItem;
+import org.bukkit.craftbukkit.v1_13_R2.util.CraftNBTTagConfigSerializer;
+import org.bukkit.inventory.ItemStack;
+
public class NBTUtils {
+ public RawNBT> constructNBT(String nbtString) {
+ try {
+ return new RawNBT