mirror of
https://hub.spigotmc.org/stash/scm/spigot/bukkit.git
synced 2025-09-18 21:45:12 +00:00
Add access to hit entity and previous item.
Signed-off-by: ShreyasAyyengar <shreyas.ayyengar@gmail.com>
This commit is contained in:
parent
68f57296d4
commit
b351a7f0ab
1 changed files with 30 additions and 2 deletions
|
@ -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,
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue