From 4a8fef719c79ba79ae67be1db09778c4fdfb0b30 Mon Sep 17 00:00:00 2001 From: ShreyasAyyengar Date: Sat, 7 Sep 2024 01:22:44 -0700 Subject: [PATCH] Add PlayerAttackCooldownEvent. (SPIGOT-7880) Signed-off-by: ShreyasAyyengar --- .../player/PlayerAttackCooldownEvent.java | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 src/main/java/org/bukkit/event/player/PlayerAttackCooldownEvent.java diff --git a/src/main/java/org/bukkit/event/player/PlayerAttackCooldownEvent.java b/src/main/java/org/bukkit/event/player/PlayerAttackCooldownEvent.java new file mode 100644 index 00000000..d1db4c01 --- /dev/null +++ b/src/main/java/org/bukkit/event/player/PlayerAttackCooldownEvent.java @@ -0,0 +1,64 @@ +package org.bukkit.event.player; + +import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; +import org.bukkit.event.HandlerList; +import org.jetbrains.annotations.NotNull; + +/** + * Called when a player's attack cooldown ticker starts. + *

+ * Warning: Cancelling this event has no impact on the cooldown graphic displayed to the client. If cancelled, + * Bukkit will not reset the cooldown ticker, but the client will still display the cooldown graphic regardless. + */ +public class PlayerAttackCooldownEvent extends PlayerEvent implements Cancellable { + private static final HandlerList handlers = new HandlerList(); + private boolean cancelled; + private final AttackCooldownCause cause; + + public PlayerAttackCooldownEvent(@NotNull Player who, @NotNull AttackCooldownCause cause) { + super(who); + this.cause = cause; + } + + @NotNull + public AttackCooldownCause getCause() { + return cause; + } + + @Override + public boolean isCancelled() { + return cancelled; + } + + @Override + public void setCancelled(boolean cancelled) { + this.cancelled = cancelled; + } + + @NotNull + @Override + public HandlerList getHandlers() { + return handlers; + } + + @NotNull + public static HandlerList getHandlerList() { + return handlers; + } + + public enum AttackCooldownCause { + /** + * Indicates the player switched items + */ + ITEM_SWITCH, + /** + * Indicates the player attacked an entity + */ + ATTACK_ENTITY, + /** + * Indicates the player swung their arm + */ + SWING + } +}