mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-06 10:44:39 +01:00
43 lines
1.8 KiB
Diff
43 lines
1.8 KiB
Diff
--- a/net/minecraft/world/item/ServerItemCooldowns.java
|
|
+++ b/net/minecraft/world/item/ServerItemCooldowns.java
|
|
@@ -11,7 +11,40 @@
|
|
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 groupId, int duration) {
|
|
super.onCooldownStarted(groupId, duration);
|
|
this.player.connection.send(new ClientboundCooldownPacket(groupId, duration));
|