SPIGOT-7643: Fix inverted leash event cancelled usage and remove leash knot if no entity gets leashed

By: DerFrZocker <derrieple@gmail.com>
This commit is contained in:
CraftBukkit/Spigot 2024-04-28 07:27:16 +10:00
parent 9963078a80
commit 6041b5c6b5

View File

@ -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;
}
}