From 6041b5c6b508e03ac6f5a8c9164b57c6caf23971 Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Sun, 28 Apr 2024 07:27:16 +1000 Subject: [PATCH] SPIGOT-7643: Fix inverted leash event cancelled usage and remove leash knot if no entity gets leashed By: DerFrZocker --- .../net/minecraft/world/item/ItemLeash.patch | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/paper-server/nms-patches/net/minecraft/world/item/ItemLeash.patch b/paper-server/nms-patches/net/minecraft/world/item/ItemLeash.patch index 3738eab0b4..6fd18937eb 100644 --- a/paper-server/nms-patches/net/minecraft/world/item/ItemLeash.patch +++ b/paper-server/nms-patches/net/minecraft/world/item/ItemLeash.patch @@ -30,7 +30,7 @@ EntityLeash entityleash = null; double d0 = 7.0D; int i = blockposition.getX(); -@@ -54,12 +59,29 @@ +@@ -54,19 +59,50 @@ EntityInsentient entityinsentient; @@ -55,13 +55,23 @@ + + // CraftBukkit start + if (org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerLeashEntityEvent(entityinsentient, entityleash, entityhuman, enumhand).isCancelled()) { -+ entityinsentient.setLeashedTo(entityleash, true); ++ iterator.remove(); ++ continue; + } ++ ++ entityinsentient.setLeashedTo(entityleash, true); + // CraftBukkit end } if (!list.isEmpty()) { -@@ -69,4 +91,10 @@ + world.gameEvent((Holder) GameEvent.BLOCK_ATTACH, blockposition, GameEvent.a.of((Entity) entityhuman)); + return EnumInteractionResult.SUCCESS; + } else { ++ // CraftBukkit start- remove leash if we do not leash any entity because of the cancelled event ++ if (entityleash != null) { ++ entityleash.discard(null); ++ } ++ // CraftBukkit end return EnumInteractionResult.PASS; } }