mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-08 19:34:09 +01:00
eed041d629
By: md_5 <git@md-5.net>
121 lines
5 KiB
Diff
121 lines
5 KiB
Diff
--- a/net/minecraft/world/entity/Leashable.java
|
|
+++ b/net/minecraft/world/entity/Leashable.java
|
|
@@ -15,6 +15,11 @@
|
|
import net.minecraft.world.level.IMaterial;
|
|
import net.minecraft.world.level.World;
|
|
|
|
+// CraftBukkit start
|
|
+import org.bukkit.event.entity.EntityUnleashEvent;
|
|
+import org.bukkit.event.entity.EntityUnleashEvent.UnleashReason;
|
|
+// CraftBukkit end
|
|
+
|
|
public interface Leashable {
|
|
|
|
String LEASH_TAG = "leash";
|
|
@@ -44,7 +49,7 @@
|
|
|
|
default void setDelayedLeashHolderId(int i) {
|
|
this.setLeashData(new Leashable.a(i));
|
|
- dropLeash((Entity) this, false, false);
|
|
+ dropLeash((Entity & Leashable) this, false, false); // CraftBukkit - decompile error
|
|
}
|
|
|
|
@Nullable
|
|
@@ -53,7 +58,7 @@
|
|
return new Leashable.a(Either.left(nbttagcompound.getCompound("leash").getUUID("UUID")));
|
|
} else {
|
|
if (nbttagcompound.contains("leash", 11)) {
|
|
- Either<UUID, BlockPosition> either = (Either) GameProfileSerializer.readBlockPos(nbttagcompound, "leash").map(Either::right).orElse((Object) null);
|
|
+ Either<UUID, BlockPosition> either = (Either) GameProfileSerializer.readBlockPos(nbttagcompound, "leash").map(Either::right).orElse(null); // CraftBukkit - decompile error
|
|
|
|
if (either != null) {
|
|
return new Leashable.a(either);
|
|
@@ -68,6 +73,11 @@
|
|
if (leashable_a != null) {
|
|
Either<UUID, BlockPosition> either = leashable_a.delayedLeashInfo;
|
|
Entity entity = leashable_a.leashHolder;
|
|
+ // CraftBukkit start - SPIGOT-7487: Don't save (and possible drop) leash, when the holder was removed by a plugin
|
|
+ if (entity != null && entity.pluginRemoved) {
|
|
+ return;
|
|
+ }
|
|
+ // CraftBukkit end
|
|
|
|
if (entity instanceof EntityLeash) {
|
|
EntityLeash entityleash = (EntityLeash) entity;
|
|
@@ -110,7 +120,9 @@
|
|
}
|
|
|
|
if (e0.tickCount > 100) {
|
|
+ e0.forceDrops = true; // CraftBukkit
|
|
e0.spawnAtLocation((IMaterial) Items.LEAD);
|
|
+ e0.forceDrops = false; // CraftBukkit
|
|
((Leashable) e0).setLeashData((Leashable.a) null);
|
|
}
|
|
}
|
|
@@ -119,7 +131,7 @@
|
|
}
|
|
|
|
default void dropLeash(boolean flag, boolean flag1) {
|
|
- dropLeash((Entity) this, flag, flag1);
|
|
+ dropLeash((Entity & Leashable) this, flag, flag1); // CraftBukkit - decompile error
|
|
}
|
|
|
|
private static <E extends Entity & Leashable> void dropLeash(E e0, boolean flag, boolean flag1) {
|
|
@@ -128,7 +140,9 @@
|
|
if (leashable_a != null && leashable_a.leashHolder != null) {
|
|
((Leashable) e0).setLeashData((Leashable.a) null);
|
|
if (!e0.level().isClientSide && flag1) {
|
|
+ e0.forceDrops = true; // CraftBukkit
|
|
e0.spawnAtLocation((IMaterial) Items.LEAD);
|
|
+ e0.forceDrops = false; // CraftBukkit
|
|
}
|
|
|
|
if (flag) {
|
|
@@ -153,7 +167,8 @@
|
|
|
|
if (leashable_a != null && leashable_a.leashHolder != null) {
|
|
if (!e0.isAlive() || !leashable_a.leashHolder.isAlive()) {
|
|
- dropLeash(e0, true, true);
|
|
+ e0.level().getCraftServer().getPluginManager().callEvent(new EntityUnleashEvent(e0.getBukkitEntity(), (!e0.isAlive()) ? UnleashReason.PLAYER_UNLEASH : UnleashReason.HOLDER_GONE)); // CraftBukkit
|
|
+ dropLeash(e0, true, !e0.pluginRemoved); // CraftBukkit - SPIGOT-7487: Don't drop leash, when the holder was removed by a plugin
|
|
}
|
|
|
|
Entity entity = ((Leashable) e0).getLeashHolder();
|
|
@@ -183,13 +198,18 @@
|
|
}
|
|
|
|
default void leashTooFarBehaviour() {
|
|
+ // CraftBukkit start
|
|
+ if (this instanceof Entity entity) {
|
|
+ entity.level().getCraftServer().getPluginManager().callEvent(new EntityUnleashEvent(entity.getBukkitEntity(), EntityUnleashEvent.UnleashReason.DISTANCE));
|
|
+ }
|
|
+ // CraftBukkit end
|
|
this.dropLeash(true, true);
|
|
}
|
|
|
|
default void closeRangeLeashBehaviour(Entity entity) {}
|
|
|
|
default void elasticRangeLeashBehaviour(Entity entity, float f) {
|
|
- legacyElasticRangeLeashBehaviour((Entity) this, entity, f);
|
|
+ legacyElasticRangeLeashBehaviour((Entity & Leashable) this, entity, f); // CraftBukkit - decompile error
|
|
}
|
|
|
|
private static <E extends Entity & Leashable> void legacyElasticRangeLeashBehaviour(E e0, Entity entity, float f) {
|
|
@@ -201,7 +221,7 @@
|
|
}
|
|
|
|
default void setLeashedTo(Entity entity, boolean flag) {
|
|
- setLeashedTo((Entity) this, entity, flag);
|
|
+ setLeashedTo((Entity & Leashable) this, entity, flag); // CraftBukkit - decompile error
|
|
}
|
|
|
|
private static <E extends Entity & Leashable> void setLeashedTo(E e0, Entity entity, boolean flag) {
|
|
@@ -232,7 +252,7 @@
|
|
|
|
@Nullable
|
|
default Entity getLeashHolder() {
|
|
- return getLeashHolder((Entity) this);
|
|
+ return getLeashHolder((Entity & Leashable) this); // CraftBukkit - decompile error
|
|
}
|
|
|
|
@Nullable
|