mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-16 14:33:09 +01:00
Add PlayerItemCooldownEvent
This commit is contained in:
parent
791377732e
commit
d1d54d35bf
3 changed files with 60 additions and 1 deletions
|
@ -0,0 +1,16 @@
|
||||||
|
--- a/net/minecraft/world/item/ItemCooldowns.java
|
||||||
|
+++ b/net/minecraft/world/item/ItemCooldowns.java
|
||||||
|
@@ -56,6 +56,13 @@
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
|
@ -0,0 +1,43 @@
|
||||||
|
--- 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));
|
|
@ -619,7 +619,7 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemCooldowns.CooldownInstance cooldown = this.getHandle().getCooldowns().cooldowns.get(group);
|
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
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue