Add PlayerAttackCooldownEvent. (SPIGOT-7880)

Signed-off-by: ShreyasAyyengar <shreyas.ayyengar@gmail.com>
This commit is contained in:
ShreyasAyyengar 2024-09-07 01:22:44 -07:00
parent f6e7dbd76e
commit 4a8fef719c

View file

@ -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.
* <p>
* Warning: <b>Cancelling this event has no impact on the cooldown graphic displayed to the client.</b> 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
}
}