--- a/net/minecraft/world/item/ServerItemCooldowns.java +++ b/net/minecraft/world/item/ServerItemCooldowns.java @@ -11,6 +_,39 @@ this.player = player; } + // Paper start - Add PlayerItemCooldownEvent + @Override + public void addCooldown(ItemStack item, int duration) { + final ResourceLocation cooldownGroup = this.getCooldownGroup(item); + final io.papermc.paper.event.player.PlayerItemCooldownEvent event = new io.papermc.paper.event.player.PlayerItemCooldownEvent( + this.player.getBukkitEntity(), + org.bukkit.craftbukkit.inventory.CraftItemType.minecraftToBukkit(item.getItem()), + org.bukkit.craftbukkit.util.CraftNamespacedKey.fromMinecraft(cooldownGroup), + duration + ); + if (event.callEvent()) { + super.addCooldown(cooldownGroup, event.getCooldown(), false); + } + } + + @Override + public void addCooldown(ResourceLocation groupId, int duration, boolean callEvent) { + if (callEvent) { + final io.papermc.paper.event.player.PlayerItemGroupCooldownEvent event = new io.papermc.paper.event.player.PlayerItemGroupCooldownEvent( + this.player.getBukkitEntity(), + org.bukkit.craftbukkit.util.CraftNamespacedKey.fromMinecraft(groupId), + duration + ); + if (!event.callEvent()) { + return; + } + + duration = event.getCooldown(); + } + super.addCooldown(groupId, duration, false); + } + // Paper end - Add PlayerItemCooldownEvent + @Override protected void onCooldownStarted(ResourceLocation group, int cooldown) { super.onCooldownStarted(group, cooldown);