Skip to content

Commit 38e5496

Browse files
author
Harry Bridgen
committed
Fix EntityUnleashEvent not respecting cancellation
1 parent a5cf227 commit 38e5496

1 file changed

Lines changed: 17 additions & 8 deletions

File tree

paper-server/patches/sources/net/minecraft/world/entity/Leashable.java.patch

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,33 @@
3232
}
3333

3434
if (broadcastPacket) {
35-
@@ -142,7 +_,15 @@
35+
@@ -142,19 +_,28 @@
3636

3737
if (leashData != null && leashData.leashHolder != null) {
3838
if (!entity.canInteractWithLevel() || !leashData.leashHolder.canInteractWithLevel()) {
3939
- if (level.getGameRules().get(GameRules.ENTITY_DROPS)) {
40+
- entity.dropLeash();
41+
- } else {
42+
- entity.removeLeash();
43+
- }
4044
+ // Paper start - Expand EntityUnleashEvent
4145
+ final org.bukkit.event.entity.EntityUnleashEvent event = new org.bukkit.event.entity.EntityUnleashEvent(
4246
+ entity.getBukkitEntity(),
4347
+ !entity.isAlive() ? org.bukkit.event.entity.EntityUnleashEvent.UnleashReason.PLAYER_UNLEASH : org.bukkit.event.entity.EntityUnleashEvent.UnleashReason.HOLDER_GONE,
4448
+ level.getGameRules().get(GameRules.ENTITY_DROPS) && !entity.pluginRemoved
4549
+ );
46-
+ event.callEvent();
47-
+ if (event.isDropLeash()) { // CraftBukkit - SPIGOT-7487: Don't drop leash, when the holder was removed by a plugin
48-
+ // Paper end - Expand EntityUnleashEvent
49-
entity.dropLeash();
50-
} else {
51-
entity.removeLeash();
52-
@@ -153,8 +_,7 @@
50+
+ // Paper start - Fix leash event; respect cancellation
51+
+ if (event.callEvent()) {
52+
+ if (event.isDropLeash()) { // CraftBukkit - SPIGOT-7487: Don't drop leash, when the holder was removed by a plugin
53+
+ // Paper end - Expand EntityUnleashEvent
54+
+ entity.dropLeash();
55+
+ } else {
56+
+ entity.removeLeash();
57+
+ }
58+
+ } // Paper end - Fix leash event; respect cancellation
59+
}
60+
61+
Entity leashHolder = entity.getLeashHolder();
5362
if (leashHolder != null && leashHolder.level() == entity.level()) {
5463
double d = entity.leashDistanceTo(leashHolder);
5564
entity.whenLeashedTo(leashHolder);

0 commit comments

Comments
 (0)