diff --git a/Spigot-API-Patches/0269-Add-dropLeash-variable-to-EntityUnleashEvent.patch b/Spigot-API-Patches/0269-Add-dropLeash-variable-to-EntityUnleashEvent.patch new file mode 100644 index 000000000..492a8d521 --- /dev/null +++ b/Spigot-API-Patches/0269-Add-dropLeash-variable-to-EntityUnleashEvent.patch @@ -0,0 +1,78 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: KennyTV +Date: Fri, 29 Jan 2021 15:13:04 +0100 +Subject: [PATCH] Add dropLeash variable to EntityUnleashEvent + + +diff --git a/src/main/java/org/bukkit/event/entity/EntityUnleashEvent.java b/src/main/java/org/bukkit/event/entity/EntityUnleashEvent.java +index a33986a0c437a673435206fc337031a7eebdab3b..bcf773ec65d9fc27bb8e433c2f676ab0d60c35ee 100644 +--- a/src/main/java/org/bukkit/event/entity/EntityUnleashEvent.java ++++ b/src/main/java/org/bukkit/event/entity/EntityUnleashEvent.java +@@ -10,10 +10,19 @@ import org.jetbrains.annotations.NotNull; + public class EntityUnleashEvent extends EntityEvent { + private static final HandlerList handlers = new HandlerList(); + private final UnleashReason reason; ++ private boolean dropLeash; // Paper + ++ // Paper start - drop leash variable ++ @Deprecated + public EntityUnleashEvent(@NotNull Entity entity, @NotNull UnleashReason reason) { ++ this(entity, reason, false); ++ } ++ ++ public EntityUnleashEvent(@NotNull Entity entity, @NotNull UnleashReason reason, boolean dropLeash) { + super(entity); ++ // Paper end + this.reason = reason; ++ this.dropLeash = dropLeash; // Paper + } + + /** +@@ -26,6 +35,26 @@ public class EntityUnleashEvent extends EntityEvent { + return reason; + } + ++ // Paper start ++ /** ++ * Returns whether a leash item will be dropped. ++ * ++ * @return Whether the leash item will be dropped ++ */ ++ public boolean isDropLeash() { ++ return dropLeash; ++ } ++ ++ /** ++ * Sets whether a leash item should be dropped. ++ * ++ * @return Whether the leash item should be dropped ++ */ ++ public void setDropLeash(boolean dropLeash) { ++ this.dropLeash = dropLeash; ++ } ++ // Paper end ++ + @NotNull + @Override + public HandlerList getHandlers() { +diff --git a/src/main/java/org/bukkit/event/player/PlayerUnleashEntityEvent.java b/src/main/java/org/bukkit/event/player/PlayerUnleashEntityEvent.java +index cf78950b56d4977f6c4d9d98d183bfc5ba3bacc0..68eab1563caba1ee4f52b308f390e4e172667fc5 100644 +--- a/src/main/java/org/bukkit/event/player/PlayerUnleashEntityEvent.java ++++ b/src/main/java/org/bukkit/event/player/PlayerUnleashEntityEvent.java +@@ -13,8 +13,15 @@ public class PlayerUnleashEntityEvent extends EntityUnleashEvent implements Canc + private final Player player; + private boolean cancelled = false; + ++ // Paper start - drop leash variable ++ @Deprecated + public PlayerUnleashEntityEvent(@NotNull Entity entity, @NotNull Player player) { +- super(entity, UnleashReason.PLAYER_UNLEASH); ++ this(entity, player, false); ++ } ++ ++ public PlayerUnleashEntityEvent(@NotNull Entity entity, @NotNull Player player, boolean dropLeash) { ++ super(entity, UnleashReason.PLAYER_UNLEASH, dropLeash); ++ // Paper end + this.player = player; + } + diff --git a/Spigot-Server-Patches/0667-Add-dropLeash-variable-to-EntityUnleashEvent.patch b/Spigot-Server-Patches/0667-Add-dropLeash-variable-to-EntityUnleashEvent.patch new file mode 100644 index 000000000..c5a094af2 --- /dev/null +++ b/Spigot-Server-Patches/0667-Add-dropLeash-variable-to-EntityUnleashEvent.patch @@ -0,0 +1,155 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: KennyTV +Date: Fri, 29 Jan 2021 15:13:11 +0100 +Subject: [PATCH] Add dropLeash variable to EntityUnleashEvent + + +diff --git a/src/main/java/net/minecraft/server/EntityCreature.java b/src/main/java/net/minecraft/server/EntityCreature.java +index eaa10d6e3a3c37b83fed58637941273fee9b0be8..2a5160a937a6a9968f9357c5ea3e4ced739dc0f4 100644 +--- a/src/main/java/net/minecraft/server/EntityCreature.java ++++ b/src/main/java/net/minecraft/server/EntityCreature.java +@@ -41,8 +41,11 @@ public abstract class EntityCreature extends EntityInsentient { + + if (this instanceof EntityTameableAnimal && ((EntityTameableAnimal) this).isSitting()) { + if (f > entity.world.paperConfig.maxLeashDistance) { // Paper +- this.world.getServer().getPluginManager().callEvent(new EntityUnleashEvent(this.getBukkitEntity(), EntityUnleashEvent.UnleashReason.DISTANCE)); // CraftBukkit +- this.unleash(true, true); ++ // Paper start - drop leash variable ++ EntityUnleashEvent event = new EntityUnleashEvent(this.getBukkitEntity(), EntityUnleashEvent.UnleashReason.DISTANCE, true); ++ this.world.getServer().getPluginManager().callEvent(event); // CraftBukkit ++ this.unleash(true, event.isDropLeash()); ++ // Paper end + } + + return; +@@ -50,8 +53,11 @@ public abstract class EntityCreature extends EntityInsentient { + + this.x(f); + if (f > entity.world.paperConfig.maxLeashDistance) { // Paper +- this.world.getServer().getPluginManager().callEvent(new EntityUnleashEvent(this.getBukkitEntity(), EntityUnleashEvent.UnleashReason.DISTANCE)); // CraftBukkit +- this.unleash(true, true); ++ // Paper start - drop leash variable ++ EntityUnleashEvent event = new EntityUnleashEvent(this.getBukkitEntity(), EntityUnleashEvent.UnleashReason.DISTANCE, true); ++ this.world.getServer().getPluginManager().callEvent(event); // CraftBukkit ++ this.unleash(true, event.isDropLeash()); ++ // Paper end + this.goalSelector.a(PathfinderGoal.Type.MOVE); + } else if (f > 6.0F) { + double d0 = (entity.locX() - this.locX()) / (double) f; +diff --git a/src/main/java/net/minecraft/server/EntityInsentient.java b/src/main/java/net/minecraft/server/EntityInsentient.java +index eb5c3a1f0d9ff665631caf5bf579e83d1ed25e4f..54bb846fe07f232f3bfb53353064d9a572fdd803 100644 +--- a/src/main/java/net/minecraft/server/EntityInsentient.java ++++ b/src/main/java/net/minecraft/server/EntityInsentient.java +@@ -20,6 +20,7 @@ import org.bukkit.event.entity.EntityTargetEvent; + import org.bukkit.event.entity.EntityTransformEvent; + import org.bukkit.event.entity.EntityUnleashEvent; + import org.bukkit.event.entity.EntityUnleashEvent.UnleashReason; ++import org.bukkit.event.player.PlayerUnleashEntityEvent; // Paper + // CraftBukkit end + + public abstract class EntityInsentient extends EntityLiving { +@@ -1139,12 +1140,15 @@ public abstract class EntityInsentient extends EntityLiving { + return EnumInteractionResult.PASS; + } else if (this.getLeashHolder() == entityhuman) { + // CraftBukkit start - fire PlayerUnleashEntityEvent +- if (CraftEventFactory.callPlayerUnleashEntityEvent(this, entityhuman).isCancelled()) { ++ // Paper start - drop leash variable ++ PlayerUnleashEntityEvent event = CraftEventFactory.callPlayerUnleashEntityEvent(this, entityhuman, !entityhuman.abilities.canInstantlyBuild); ++ if (event.isCancelled()) { ++ // Paper end + ((EntityPlayer) entityhuman).playerConnection.sendPacket(new PacketPlayOutAttachEntity(this, this.getLeashHolder())); + return EnumInteractionResult.PASS; + } + // CraftBukkit end +- this.unleash(true, !entityhuman.abilities.canInstantlyBuild); ++ this.unleash(true, event.isDropLeash()); // Paper - drop leash variable + return EnumInteractionResult.a(this.world.isClientSide); + } else { + EnumInteractionResult enuminteractionresult = this.c(entityhuman, enumhand); +@@ -1298,8 +1302,11 @@ public abstract class EntityInsentient extends EntityLiving { + + if (this.leashHolder != null) { + if (!this.isAlive() || !this.leashHolder.isAlive()) { +- this.world.getServer().getPluginManager().callEvent(new EntityUnleashEvent(this.getBukkitEntity(), (!this.isAlive()) ? UnleashReason.PLAYER_UNLEASH : UnleashReason.HOLDER_GONE)); // CraftBukkit +- this.unleash(true, true); ++ // Paper start - drop leash variable ++ EntityUnleashEvent event = new EntityUnleashEvent(this.getBukkitEntity(), (!this.isAlive()) ? UnleashReason.PLAYER_UNLEASH : UnleashReason.HOLDER_GONE, true); ++ this.world.getServer().getPluginManager().callEvent(event); // CraftBukkit ++ this.unleash(true, event.isDropLeash()); ++ // Paper end + } + + } +@@ -1367,8 +1374,11 @@ public abstract class EntityInsentient extends EntityLiving { + boolean flag1 = super.a(entity, flag); + + if (flag1 && this.isLeashed()) { +- this.world.getServer().getPluginManager().callEvent(new EntityUnleashEvent(this.getBukkitEntity(), UnleashReason.UNKNOWN)); // CraftBukkit +- this.unleash(true, true); ++ // Paper start - drop leash variable ++ EntityUnleashEvent event = new EntityUnleashEvent(this.getBukkitEntity(), UnleashReason.UNKNOWN, true); ++ this.world.getServer().getPluginManager().callEvent(event); // CraftBukkit ++ this.unleash(true, event.isDropLeash()); ++ // Paper end + } + + return flag1; +@@ -1570,7 +1580,10 @@ public abstract class EntityInsentient extends EntityLiving { + @Override + protected void bN() { + super.bN(); +- this.world.getServer().getPluginManager().callEvent(new EntityUnleashEvent(this.getBukkitEntity(), UnleashReason.UNKNOWN)); // CraftBukkit +- this.unleash(true, false); ++ // Paper start - drop leash variable ++ EntityUnleashEvent event = new EntityUnleashEvent(this.getBukkitEntity(), UnleashReason.UNKNOWN, false); ++ this.world.getServer().getPluginManager().callEvent(event); // CraftBukkit ++ this.unleash(true, event.isDropLeash()); ++ // Paper end + } + } +diff --git a/src/main/java/net/minecraft/server/EntityLeash.java b/src/main/java/net/minecraft/server/EntityLeash.java +index 6bd25833bc3ff3ca46367a48da001ed9bda8c19d..4d64bd3da64af122fe966d37367f87140447df83 100644 +--- a/src/main/java/net/minecraft/server/EntityLeash.java ++++ b/src/main/java/net/minecraft/server/EntityLeash.java +@@ -5,6 +5,7 @@ import java.util.List; + import javax.annotation.Nullable; + + import org.bukkit.craftbukkit.event.CraftEventFactory; // CraftBukkit ++import org.bukkit.event.player.PlayerUnleashEntityEvent; // Paper + + public class EntityLeash extends EntityHanging { + +@@ -101,11 +102,14 @@ public class EntityLeash extends EntityHanging { + entityinsentient = (EntityInsentient) iterator.next(); + if (entityinsentient.isLeashed() && entityinsentient.getLeashHolder() == this) { + // CraftBukkit start +- if (CraftEventFactory.callPlayerUnleashEntityEvent(entityinsentient, entityhuman).isCancelled()) { ++ // Paper start - drop leash variable ++ PlayerUnleashEntityEvent event = CraftEventFactory.callPlayerUnleashEntityEvent(entityinsentient, entityhuman, !entityhuman.abilities.canInstantlyBuild); ++ if (event.isCancelled()) { ++ // Paper end + die = false; + continue; + } +- entityinsentient.unleash(true, !entityhuman.abilities.canInstantlyBuild); // false -> survival mode boolean ++ entityinsentient.unleash(true, event.isDropLeash()); // false -> survival mode boolean // Paper - drop leash variable + // CraftBukkit end + } + } +diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java +index 696ded96e6018bc5289cc20f72d6dc9395d3b6a6..c9e2d2f0eb1f4075da2b5fa05198de4940ebf354 100644 +--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java ++++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java +@@ -1447,8 +1447,10 @@ public class CraftEventFactory { + return itemInHand; + } + +- public static PlayerUnleashEntityEvent callPlayerUnleashEntityEvent(EntityInsentient entity, EntityHuman player) { +- PlayerUnleashEntityEvent event = new PlayerUnleashEntityEvent(entity.getBukkitEntity(), (Player) player.getBukkitEntity()); ++ // Paper start - drop leash variable ++ public static PlayerUnleashEntityEvent callPlayerUnleashEntityEvent(EntityInsentient entity, EntityHuman player, boolean dropLeash) { ++ PlayerUnleashEntityEvent event = new PlayerUnleashEntityEvent(entity.getBukkitEntity(), (Player) player.getBukkitEntity(), dropLeash); ++ // Paper end + entity.world.getServer().getPluginManager().callEvent(event); + return event; + }