Pass hand to entity unleash event

This commit is contained in:
Bjarne Koll
2025-06-04 21:10:37 +02:00
parent b81bb10233
commit 39ff9ed2c8
2 changed files with 16 additions and 1 deletions

View File

@@ -1037,6 +1037,15 @@
leashable1.setLeashedTo(this, true);
flag = true;
}
@@ -2103,7 +_,7 @@
}
ItemStack itemInHand = player.getItemInHand(hand);
- if (itemInHand.is(Items.SHEARS) && this.shearOffAllLeashConnections(player)) {
+ if (itemInHand.is(Items.SHEARS) && this.shearOffAllLeashConnections(player, hand)) { // Paper - PlayerUnleashEntityEvent - pass used hand
itemInHand.hurtAndBreak(1, player, hand);
return InteractionResult.SUCCESS;
} else if (this instanceof Mob mob
@@ -2116,11 +_,14 @@
if (this.isAlive() && this instanceof Leashable leashable2) {
if (leashable2.getLeashHolder() == player) {

View File

@@ -1497,7 +1497,13 @@ public class CraftEventFactory {
}
public static boolean handlePlayerUnleashEntityEvent(Entity entity, net.minecraft.world.entity.player.@Nullable Player player, @Nullable InteractionHand hand, boolean dropLeash) {
if (player == null || hand == null) return true;
if (player == null || hand == null) {
if (entity instanceof final Leashable leashable) {
if (dropLeash) leashable.dropLeash();
else leashable.removeLeash();
}
return true;
}
PlayerUnleashEntityEvent event = new PlayerUnleashEntityEvent(entity.getBukkitEntity(), (Player) player.getBukkitEntity(), CraftEquipmentSlot.getHand(hand), dropLeash);
entity.level().getCraftServer().getPluginManager().callEvent(event);