#788: Add getHand() to all relevant events

By: Parker Hawke <hawkeboyz2@hotmail.com>
This commit is contained in:
Bukkit/Spigot 2022-10-02 09:07:09 +11:00
parent 273e3081de
commit 385b26cb81
15 changed files with 251 additions and 18 deletions

View File

@ -6,6 +6,7 @@ import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.bukkit.inventory.EquipmentSlot;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@ -23,12 +24,19 @@ public class EntityPlaceEvent extends EntityEvent implements Cancellable {
private final Player player;
private final Block block;
private final BlockFace blockFace;
private final EquipmentSlot hand;
public EntityPlaceEvent(@NotNull final Entity entity, @Nullable final Player player, @NotNull final Block block, @NotNull final BlockFace blockFace) {
public EntityPlaceEvent(@NotNull final Entity entity, @Nullable final Player player, @NotNull final Block block, @NotNull final BlockFace blockFace, @NotNull final EquipmentSlot hand) {
super(entity);
this.player = player;
this.block = block;
this.blockFace = blockFace;
this.hand = hand;
}
@Deprecated
public EntityPlaceEvent(@NotNull final Entity entity, @Nullable final Player player, @NotNull final Block block, @NotNull final BlockFace blockFace) {
this(entity, player, block, blockFace, EquipmentSlot.HAND);
}
/**
@ -61,6 +69,16 @@ public class EntityPlaceEvent extends EntityEvent implements Cancellable {
return blockFace;
}
/**
* Get the hand used to place the entity.
*
* @return the hand
*/
@NotNull
public EquipmentSlot getHand() {
return hand;
}
@Override
public boolean isCancelled() {
return cancelled;

View File

@ -3,7 +3,9 @@ package org.bukkit.event.entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.bukkit.inventory.EquipmentSlot;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* Called when an entity dies and may have the opportunity to be resurrected.
@ -16,8 +18,16 @@ public class EntityResurrectEvent extends EntityEvent implements Cancellable {
//
private boolean cancelled;
public EntityResurrectEvent(@NotNull LivingEntity what) {
private final EquipmentSlot hand;
public EntityResurrectEvent(@NotNull LivingEntity what, @Nullable EquipmentSlot hand) {
super(what);
this.hand = hand;
}
@Deprecated
public EntityResurrectEvent(@NotNull LivingEntity what) {
this(what, null);
}
@NotNull
@ -26,6 +36,17 @@ public class EntityResurrectEvent extends EntityEvent implements Cancellable {
return (LivingEntity) entity;
}
/**
* Get the hand in which the totem of undying was found, or null if the
* entity did not have a totem of undying.
*
* @return the hand, or null
*/
@Nullable
public EquipmentSlot getHand() {
return hand;
}
@Override
public boolean isCancelled() {
return cancelled;

View File

@ -5,6 +5,7 @@ import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.bukkit.inventory.EquipmentSlot;
import org.jetbrains.annotations.NotNull;
/**
@ -16,11 +17,18 @@ public class PlayerLeashEntityEvent extends Event implements Cancellable {
private final Entity entity;
private boolean cancelled = false;
private final Player player;
private final EquipmentSlot hand;
public PlayerLeashEntityEvent(@NotNull Entity what, @NotNull Entity leashHolder, @NotNull Player leasher) {
public PlayerLeashEntityEvent(@NotNull Entity what, @NotNull Entity leashHolder, @NotNull Player leasher, @NotNull EquipmentSlot hand) {
this.leashHolder = leashHolder;
this.entity = what;
this.player = leasher;
this.hand = hand;
}
@Deprecated
public PlayerLeashEntityEvent(@NotNull Entity what, @NotNull Entity leashHolder, @NotNull Player leasher) {
this(what, leashHolder, leasher, EquipmentSlot.HAND);
}
/**
@ -53,6 +61,16 @@ public class PlayerLeashEntityEvent extends Event implements Cancellable {
return player;
}
/**
* Returns the hand used by the player to leash the entity.
*
* @return the hand
*/
@NotNull
public EquipmentSlot getHand() {
return hand;
}
@NotNull
@Override
public HandlerList getHandlers() {

View File

@ -6,6 +6,7 @@ import org.bukkit.entity.Hanging;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@ -19,18 +20,20 @@ public class HangingPlaceEvent extends HangingEvent implements Cancellable {
private final Player player;
private final Block block;
private final BlockFace blockFace;
private final EquipmentSlot hand;
private final ItemStack itemStack;
@Deprecated
public HangingPlaceEvent(@NotNull final Hanging hanging, @Nullable final Player player, @NotNull final Block block, @NotNull final BlockFace blockFace) {
this(hanging, player, block, blockFace, null);
public HangingPlaceEvent(@NotNull final Hanging hanging, @Nullable final Player player, @NotNull final Block block, @NotNull final BlockFace blockFace, @Nullable final EquipmentSlot hand) {
this(hanging, player, block, blockFace, hand, null);
}
public HangingPlaceEvent(@NotNull final Hanging hanging, @Nullable final Player player, @NotNull final Block block, @NotNull final BlockFace blockFace, @Nullable ItemStack itemStack) {
public HangingPlaceEvent(@NotNull final Hanging hanging, @Nullable final Player player, @NotNull final Block block, @NotNull final BlockFace blockFace, @Nullable final EquipmentSlot hand, @Nullable ItemStack itemStack) {
super(hanging);
this.player = player;
this.block = block;
this.blockFace = blockFace;
this.hand = hand;
this.itemStack = itemStack;
}
@ -64,6 +67,17 @@ public class HangingPlaceEvent extends HangingEvent implements Cancellable {
return blockFace;
}
/**
* Returns the hand that was used to place the hanging entity, or null
* if a player did not place the hanging entity.
*
* @return the hand
*/
@Nullable
public EquipmentSlot getHand() {
return hand;
}
/**
* Gets the item from which the hanging entity originated
*

View File

@ -19,13 +19,18 @@ public class PlayerArmorStandManipulateEvent extends PlayerInteractEntityEvent {
private final ItemStack armorStandItem;
private final EquipmentSlot slot;
public PlayerArmorStandManipulateEvent(@NotNull final Player who, @NotNull final ArmorStand clickedEntity, @NotNull final ItemStack playerItem, @NotNull final ItemStack armorStandItem, @NotNull final EquipmentSlot slot) {
super(who, clickedEntity);
public PlayerArmorStandManipulateEvent(@NotNull final Player who, @NotNull final ArmorStand clickedEntity, @NotNull final ItemStack playerItem, @NotNull final ItemStack armorStandItem, @NotNull final EquipmentSlot slot, @NotNull EquipmentSlot hand) {
super(who, clickedEntity, hand);
this.playerItem = playerItem;
this.armorStandItem = armorStandItem;
this.slot = slot;
}
@Deprecated
public PlayerArmorStandManipulateEvent(@NotNull final Player who, @NotNull final ArmorStand clickedEntity, @NotNull final ItemStack playerItem, @NotNull final ItemStack armorStandItem, @NotNull final EquipmentSlot slot) {
this(who, clickedEntity, playerItem, armorStandItem, slot, EquipmentSlot.HAND);
}
/**
* Returns the item held by the player.
* <p>
@ -70,6 +75,18 @@ public class PlayerArmorStandManipulateEvent extends PlayerInteractEntityEvent {
return this.slot;
}
/**
* {@inheritDoc}
* <p>
* Note that this is not the hand of the armor stand that was changed, but rather
* the hand used by the player to swap items with the armor stand.
*/
@NotNull
@Override
public EquipmentSlot getHand() {
return super.getHand();
}
@NotNull
@Override
public ArmorStand getRightClicked() {

View File

@ -5,6 +5,7 @@ import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
@ -19,10 +20,15 @@ public class PlayerBucketEmptyEvent extends PlayerBucketEvent {
super(who, blockClicked, blockFace, bucket, itemInHand);
}
@Deprecated
public PlayerBucketEmptyEvent(@NotNull final Player who, @NotNull final Block block, @NotNull final Block blockClicked, @NotNull final BlockFace blockFace, @NotNull final Material bucket, @NotNull final ItemStack itemInHand) {
super(who, block, blockClicked, blockFace, bucket, itemInHand);
}
public PlayerBucketEmptyEvent(@NotNull final Player who, @NotNull final Block block, @NotNull final Block blockClicked, @NotNull final BlockFace blockFace, @NotNull final Material bucket, @NotNull final ItemStack itemInHand, @NotNull final EquipmentSlot hand) {
super(who, block, blockClicked, blockFace, bucket, itemInHand, hand);
}
@NotNull
@Override
public HandlerList getHandlers() {

View File

@ -5,6 +5,7 @@ import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
@ -18,12 +19,14 @@ public class PlayerBucketEntityEvent extends PlayerEvent implements Cancellable
private final Entity entity;
private final ItemStack originalBucket;
private final ItemStack entityBucket;
private final EquipmentSlot hand;
public PlayerBucketEntityEvent(@NotNull Player player, @NotNull Entity entity, @NotNull ItemStack originalBucket, @NotNull ItemStack entityBucket) {
public PlayerBucketEntityEvent(@NotNull Player player, @NotNull Entity entity, @NotNull ItemStack originalBucket, @NotNull ItemStack entityBucket, @NotNull EquipmentSlot hand) {
super(player);
this.entity = entity;
this.originalBucket = originalBucket;
this.entityBucket = entityBucket;
this.hand = hand;
}
/**
@ -61,6 +64,16 @@ public class PlayerBucketEntityEvent extends PlayerEvent implements Cancellable
return entityBucket;
}
/**
* Get the hand that was used to bucket the entity.
*
* @return the hand
*/
@NotNull
public EquipmentSlot getHand() {
return hand;
}
@Override
public boolean isCancelled() {
return cancelled;

View File

@ -5,6 +5,7 @@ import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@ -19,19 +20,26 @@ public abstract class PlayerBucketEvent extends PlayerEvent implements Cancellab
private final Block blockClicked;
private final BlockFace blockFace;
private final Material bucket;
private final EquipmentSlot hand;
@Deprecated
public PlayerBucketEvent(@NotNull final Player who, @NotNull final Block blockClicked, @NotNull final BlockFace blockFace, @NotNull final Material bucket, @NotNull final ItemStack itemInHand) {
this(who, null, blockClicked.getRelative(blockFace), blockFace, bucket, itemInHand);
this(who, null, blockClicked.getRelative(blockFace), blockFace, bucket, itemInHand, EquipmentSlot.HAND);
}
@Deprecated
public PlayerBucketEvent(@NotNull final Player who, @NotNull final Block block, @NotNull final Block blockClicked, @NotNull final BlockFace blockFace, @NotNull final Material bucket, @NotNull final ItemStack itemInHand) {
this(who, block, blockClicked, blockFace, bucket, itemInHand, EquipmentSlot.HAND);
}
public PlayerBucketEvent(@NotNull final Player who, @NotNull final Block block, @NotNull final Block blockClicked, @NotNull final BlockFace blockFace, @NotNull final Material bucket, @NotNull final ItemStack itemInHand, @NotNull final EquipmentSlot hand) {
super(who);
this.block = block;
this.blockClicked = blockClicked;
this.blockFace = blockFace;
this.itemStack = itemInHand;
this.bucket = bucket;
this.hand = hand;
}
/**
@ -93,6 +101,16 @@ public abstract class PlayerBucketEvent extends PlayerEvent implements Cancellab
return blockFace;
}
/**
* Get the hand that was used in this event.
*
* @return the hand
*/
@NotNull
public EquipmentSlot getHand() {
return hand;
}
@Override
public boolean isCancelled() {
return cancelled;

View File

@ -5,6 +5,7 @@ import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
@ -19,10 +20,15 @@ public class PlayerBucketFillEvent extends PlayerBucketEvent {
super(who, blockClicked, blockFace, bucket, itemInHand);
}
@Deprecated
public PlayerBucketFillEvent(@NotNull final Player who, @NotNull final Block block, @NotNull final Block blockClicked, @NotNull final BlockFace blockFace, @NotNull final Material bucket, @NotNull final ItemStack itemInHand) {
super(who, block, blockClicked, blockFace, bucket, itemInHand);
}
public PlayerBucketFillEvent(@NotNull final Player who, @NotNull final Block block, @NotNull final Block blockClicked, @NotNull final BlockFace blockFace, @NotNull final Material bucket, @NotNull final ItemStack itemInHand, @NotNull final EquipmentSlot hand) {
super(who, block, blockClicked, blockFace, bucket, itemInHand, hand);
}
@NotNull
@Override
public HandlerList getHandlers() {

View File

@ -4,6 +4,7 @@ import org.bukkit.Material;
import org.bukkit.Warning;
import org.bukkit.entity.Fish;
import org.bukkit.entity.Player;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
@ -16,8 +17,8 @@ import org.jetbrains.annotations.NotNull;
@Warning(false)
public class PlayerBucketFishEvent extends PlayerBucketEntityEvent {
public PlayerBucketFishEvent(@NotNull Player player, @NotNull Fish fish, @NotNull ItemStack waterBucket, @NotNull ItemStack fishBucket) {
super(player, fish, waterBucket, fishBucket);
public PlayerBucketFishEvent(@NotNull Player player, @NotNull Fish fish, @NotNull ItemStack waterBucket, @NotNull ItemStack fishBucket, @NotNull EquipmentSlot hand) {
super(player, fish, waterBucket, fishBucket, hand);
}
/**

View File

@ -5,6 +5,7 @@ import org.bukkit.entity.FishHook;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.bukkit.inventory.EquipmentSlot;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@ -18,14 +19,20 @@ public class PlayerFishEvent extends PlayerEvent implements Cancellable {
private int exp;
private final State state;
private final FishHook hookEntity;
private final EquipmentSlot hand;
public PlayerFishEvent(@NotNull final Player player, @Nullable final Entity entity, @NotNull final FishHook hookEntity, @NotNull final State state) {
public PlayerFishEvent(@NotNull final Player player, @Nullable final Entity entity, @NotNull final FishHook hookEntity, @Nullable EquipmentSlot hand, @NotNull final State state) {
super(player);
this.entity = entity;
this.hookEntity = hookEntity;
this.hand = hand;
this.state = state;
}
public PlayerFishEvent(@NotNull final Player player, @Nullable final Entity entity, @NotNull final FishHook hookEntity, @NotNull final State state) {
this(player, entity, hookEntity, null, state);
}
/**
* Gets the entity caught by the player.
* <p>
@ -84,6 +91,19 @@ public class PlayerFishEvent extends PlayerEvent implements Cancellable {
exp = amount;
}
/**
* Get the hand that was used in this event.
* <p>
* The hand used is only present when the event state is {@link State#FISHING}.
* In all other states, the hand is null.
*
* @return the hand
*/
@Nullable
public EquipmentSlot getHand() {
return hand;
}
/**
* Gets the state of the fishing
*

View File

@ -5,6 +5,7 @@ import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
@ -23,14 +24,21 @@ public class PlayerHarvestBlockEvent extends PlayerEvent implements Cancellable
private static final HandlerList handlers = new HandlerList();
private boolean cancel = false;
private final Block harvestedBlock;
private final EquipmentSlot hand;
private final List<ItemStack> itemsHarvested;
public PlayerHarvestBlockEvent(@NotNull Player player, @NotNull Block harvestedBlock, @NotNull List<ItemStack> itemsHarvested) {
public PlayerHarvestBlockEvent(@NotNull Player player, @NotNull Block harvestedBlock, @NotNull EquipmentSlot hand, @NotNull List<ItemStack> itemsHarvested) {
super(player);
this.harvestedBlock = harvestedBlock;
this.hand = hand;
this.itemsHarvested = itemsHarvested;
}
@Deprecated
public PlayerHarvestBlockEvent(@NotNull Player player, @NotNull Block harvestedBlock, @NotNull List<ItemStack> itemsHarvested) {
this(player, harvestedBlock, EquipmentSlot.HAND, itemsHarvested);
}
/**
* Gets the block that is being harvested.
*
@ -41,6 +49,16 @@ public class PlayerHarvestBlockEvent extends PlayerEvent implements Cancellable
return harvestedBlock;
}
/**
* Get the hand used to harvest the block.
*
* @return the hand
*/
@NotNull
public EquipmentSlot getHand() {
return hand;
}
/**
* Gets a list of items that are being harvested from this block.
*

View File

@ -4,6 +4,7 @@ import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@ -22,15 +23,28 @@ public class PlayerItemConsumeEvent extends PlayerEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private boolean isCancelled = false;
private ItemStack item;
private final EquipmentSlot hand;
/**
* @param player the player consuming
* @param item the ItemStack being consumed
* @param hand the hand that was used
*/
public PlayerItemConsumeEvent(@NotNull final Player player, @NotNull final ItemStack item) {
public PlayerItemConsumeEvent(@NotNull final Player player, @NotNull final ItemStack item, @NotNull final EquipmentSlot hand) {
super(player);
this.item = item;
this.hand = hand;
}
/**
* @param player the player consuming
* @param item the ItemStack being consumed
* @deprecated use {@link #PlayerItemConsumeEvent(Player, ItemStack, EquipmentSlot)}
*/
@Deprecated
public PlayerItemConsumeEvent(@NotNull final Player player, @NotNull final ItemStack item) {
this(player, item, EquipmentSlot.HAND);
}
/**
@ -58,6 +72,16 @@ public class PlayerItemConsumeEvent extends PlayerEvent implements Cancellable {
}
}
/**
* Get the hand used to consume the item.
*
* @return the hand
*/
@NotNull
public EquipmentSlot getHand() {
return hand;
}
@Override
public boolean isCancelled() {
return this.isCancelled;

View File

@ -4,6 +4,7 @@ import org.bukkit.entity.ExperienceOrb;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
@ -18,17 +19,24 @@ public class PlayerItemMendEvent extends PlayerEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
//
private final ItemStack item;
private final EquipmentSlot slot;
private final ExperienceOrb experienceOrb;
private int repairAmount;
private boolean cancelled;
public PlayerItemMendEvent(@NotNull Player who, @NotNull ItemStack item, @NotNull ExperienceOrb experienceOrb, int repairAmount) {
public PlayerItemMendEvent(@NotNull Player who, @NotNull ItemStack item, @NotNull EquipmentSlot slot, @NotNull ExperienceOrb experienceOrb, int repairAmount) {
super(who);
this.item = item;
this.slot = slot;
this.experienceOrb = experienceOrb;
this.repairAmount = repairAmount;
}
@Deprecated
public PlayerItemMendEvent(@NotNull Player who, @NotNull ItemStack item, @NotNull ExperienceOrb experienceOrb, int repairAmount) {
this(who, item, null, experienceOrb, repairAmount);
}
/**
* Get the {@link ItemStack} to be repaired.
*
@ -41,6 +49,17 @@ public class PlayerItemMendEvent extends PlayerEvent implements Cancellable {
return item;
}
/**
* Get the {@link EquipmentSlot} in which the repaired {@link ItemStack}
* may be found.
*
* @return the repaired slot
*/
@NotNull
public EquipmentSlot getSlot() {
return slot;
}
/**
* Get the experience orb triggering the event.
*

View File

@ -4,18 +4,28 @@ import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.entity.EntityUnleashEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.jetbrains.annotations.NotNull;
/**
* Called prior to an entity being unleashed due to a player's action.
*/
public class PlayerUnleashEntityEvent extends EntityUnleashEvent implements Cancellable {
private final Player player;
private boolean cancelled = false;
public PlayerUnleashEntityEvent(@NotNull Entity entity, @NotNull Player player) {
private final Player player;
private final EquipmentSlot hand;
public PlayerUnleashEntityEvent(@NotNull Entity entity, @NotNull Player player, @NotNull EquipmentSlot hand) {
super(entity, UnleashReason.PLAYER_UNLEASH);
this.player = player;
this.hand = hand;
}
@Deprecated
public PlayerUnleashEntityEvent(@NotNull Entity entity, @NotNull Player player) {
this(entity, player, EquipmentSlot.HAND);
}
/**
@ -28,6 +38,16 @@ public class PlayerUnleashEntityEvent extends EntityUnleashEvent implements Canc
return player;
}
/**
* Get the hand used by the player to unleash the entity.
*
* @return the hand
*/
@NotNull
public EquipmentSlot getHand() {
return hand;
}
@Override
public boolean isCancelled() {
return cancelled;