Add access to hit entity and previous item.

Signed-off-by: ShreyasAyyengar <shreyas.ayyengar@gmail.com>
This commit is contained in:
ShreyasAyyengar 2024-09-14 11:08:48 -07:00
parent 68f57296d4
commit b351a7f0ab

View file

@ -1,9 +1,12 @@
package org.bukkit.event.player;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* Called when a player's attack cooldown ticker starts. If cancelled, the damage inflicted upon the next hit
@ -15,13 +18,38 @@ import org.jetbrains.annotations.NotNull;
public class PlayerAttackCooldownEvent extends PlayerEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private boolean cancelled;
private final Entity hitEntity;
private final ItemStack previousItem;
private final AttackCooldownCause cause;
public PlayerAttackCooldownEvent(@NotNull Player who, @NotNull AttackCooldownCause cause) {
public PlayerAttackCooldownEvent(@NotNull Player who, @NotNull AttackCooldownCause cause, @Nullable Entity hitEntity, @Nullable ItemStack previousItem) {
super(who);
this.cause = cause;
this.hitEntity = hitEntity;
this.previousItem = previousItem;
}
/**
* Returns the entity that was hit which triggered the attack cooldown.
* @return the hit entity, or null if the cause is not {@link AttackCooldownCause#ATTACK_ENTITY}
*/
@Nullable
public Entity getHitEntity() {
return hitEntity;
}
/**
* Returns the item that was previously held by the player.
* @return the item that was previously held, or null if the cause is not {@link AttackCooldownCause#ITEM_SWITCH}
*/
@Nullable
public ItemStack getPreviousItem() {
return previousItem;
}
/**
* @return the cause of the attack cooldown
*/
@NotNull
public AttackCooldownCause getCause() {
return cause;
@ -50,7 +78,7 @@ public class PlayerAttackCooldownEvent extends PlayerEvent implements Cancellabl
public enum AttackCooldownCause {
/**
* Indicates the player switched items
* Indicates the player switched hand-held items.
*/
ITEM_SWITCH,
/**