#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() {