From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Jake Potrebic Date: Sat, 15 May 2021 22:10:50 -0700 Subject: [PATCH] ItemStack repair check API diff --git a/src/main/java/org/bukkit/UnsafeValues.java b/src/main/java/org/bukkit/UnsafeValues.java index 6dbd520182b1e7713a68baad09b7f613424ef619..e504567cf755557be8511f2c93c171572b78e722 100644 --- a/src/main/java/org/bukkit/UnsafeValues.java +++ b/src/main/java/org/bukkit/UnsafeValues.java @@ -155,6 +155,16 @@ public interface UnsafeValues { */ public io.papermc.paper.inventory.ItemRarity getItemStackRarity(ItemStack itemStack); + /** + * Checks if an itemstack can be repaired with another itemstack. + * Returns false if either argument's type is not an item ({@link Material#isItem()}). + * + * @param itemToBeRepaired the itemstack to be repaired + * @param repairMaterial the repair material + * @return true if valid repair, false if not + */ + public boolean isValidRepairItemStack(@org.jetbrains.annotations.NotNull ItemStack itemToBeRepaired, @org.jetbrains.annotations.NotNull ItemStack repairMaterial); + /** * Returns the server's protocol version. * diff --git a/src/main/java/org/bukkit/inventory/ItemStack.java b/src/main/java/org/bukkit/inventory/ItemStack.java index e8f4543131d293beaa1fe9b44e2e98f27bc5dc79..b4d55e0d5e605cb6980b555acd42d16e1e65c196 100644 --- a/src/main/java/org/bukkit/inventory/ItemStack.java +++ b/src/main/java/org/bukkit/inventory/ItemStack.java @@ -874,5 +874,27 @@ public class ItemStack implements Cloneable, ConfigurationSerializable, net.kyor public io.papermc.paper.inventory.ItemRarity getRarity() { return Bukkit.getUnsafe().getItemStackRarity(this); } + + /** + * Checks if an itemstack can repair this itemstack. + * Returns false if {@code this} or {@code repairMaterial}'s type is not an item ({@link Material#isItem()}). + * + * @param repairMaterial the repair material + * @return true if it is repairable by, false if not + */ + public boolean isRepairableBy(@NotNull ItemStack repairMaterial) { + return Bukkit.getUnsafe().isValidRepairItemStack(this, repairMaterial); + } + + /** + * Checks if this itemstack can repair another. + * Returns false if {@code this} or {@code toBeRepaired}'s type is not an item ({@link Material#isItem()}). + * + * @param toBeRepaired the itemstack to be repaired + * @return true if it can repair, false if not + */ + public boolean canRepair(@NotNull ItemStack toBeRepaired) { + return Bukkit.getUnsafe().isValidRepairItemStack(toBeRepaired, this); + } // Paper end }