mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-30 16:19:03 +01:00
81 lines
4 KiB
Diff
81 lines
4 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Nassim Jahnke <nassim@njahnke.dev>
|
|
Date: Tue, 25 Aug 2020 13:48:33 +0200
|
|
Subject: [PATCH] Add PlayerItemCooldownEvent
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/item/ItemCooldowns.java b/src/main/java/net/minecraft/world/item/ItemCooldowns.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/net/minecraft/world/item/ItemCooldowns.java
|
|
+++ b/src/main/java/net/minecraft/world/item/ItemCooldowns.java
|
|
@@ -0,0 +0,0 @@ public class ItemCooldowns {
|
|
}
|
|
|
|
public void addCooldown(ResourceLocation groupId, int duration) {
|
|
+ // Paper start - Item cooldown events
|
|
+ this.addCooldown(groupId, duration, true);
|
|
+ }
|
|
+
|
|
+ public void addCooldown(ResourceLocation groupId, int duration, boolean callEvent) {
|
|
+ // Event called in server override
|
|
+ // Paper end - Item cooldown events
|
|
this.cooldowns.put(groupId, new ItemCooldowns.CooldownInstance(this.tickCount, this.tickCount + duration));
|
|
this.onCooldownStarted(groupId, duration);
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/world/item/ServerItemCooldowns.java b/src/main/java/net/minecraft/world/item/ServerItemCooldowns.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/net/minecraft/world/item/ServerItemCooldowns.java
|
|
+++ b/src/main/java/net/minecraft/world/item/ServerItemCooldowns.java
|
|
@@ -0,0 +0,0 @@ public class ServerItemCooldowns extends ItemCooldowns {
|
|
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);
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java
|
|
@@ -0,0 +0,0 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
|
|
}
|
|
|
|
ItemCooldowns.CooldownInstance cooldown = this.getHandle().getCooldowns().cooldowns.get(group);
|
|
- return (cooldown == null) ? 0 : Math.max(0, cooldown.endTime - this.getHandle().getCooldowns().tickCount);
|
|
+ return (cooldown == null) ? 0 : Math.max(0, cooldown.endTime() - this.getHandle().getCooldowns().tickCount);
|
|
}
|
|
|
|
@Override
|