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

This commit is contained in:
DerFrZocker 2024-04-28 07:27:16 +10:00 committed by md_5
parent 7ddb482941
commit f70367d429
No known key found for this signature in database
GPG Key ID: E8E901AC7C617C11

View File

@ -30,7 +30,7 @@
EntityLeash entityleash = null; EntityLeash entityleash = null;
double d0 = 7.0D; double d0 = 7.0D;
int i = blockposition.getX(); int i = blockposition.getX();
@@ -54,12 +59,29 @@ @@ -54,19 +59,50 @@
EntityInsentient entityinsentient; EntityInsentient entityinsentient;
@ -55,13 +55,23 @@
+ +
+ // CraftBukkit start + // CraftBukkit start
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerLeashEntityEvent(entityinsentient, entityleash, entityhuman, enumhand).isCancelled()) { + 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 + // CraftBukkit end
} }
if (!list.isEmpty()) { 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; return EnumInteractionResult.PASS;
} }
} }