From 0efee74644b8803c99b46a86b985323d704aadf9 Mon Sep 17 00:00:00 2001 From: Aikar Date: Tue, 5 Jun 2018 23:00:29 -0400 Subject: [PATCH] ItemStack#getMaxItemUseDuration Allows you to determine how long it takes to use a usable/consumable item --- .../craftbukkit/inventory/CraftItemStack.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java index aea09533fa..60062ea5b1 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java @@ -225,6 +225,21 @@ public final class CraftItemStack extends ItemStack { return (this.handle == null) ? Material.AIR.getMaxStackSize() : this.handle.getMaxStackSize(); } + // Paper start + @Override + public int getMaxItemUseDuration(final org.bukkit.entity.LivingEntity entity) { + if (handle == null) { + return 0; + } + + // Make sure plugins calling the old method don't blow up + if (entity == null && (handle.is(net.minecraft.world.item.Items.CROSSBOW) || handle.is(net.minecraft.world.item.Items.GOAT_HORN))) { + throw new UnsupportedOperationException("This item requires an entity to determine the max use duration"); + } + return handle.getUseDuration(entity != null ? ((org.bukkit.craftbukkit.entity.CraftLivingEntity) entity).getHandle() : null); + } + // Paper end + @Override public void addUnsafeEnchantment(Enchantment ench, int level) { Preconditions.checkArgument(ench != null, "Enchantment cannot be null");