PaperMC/nms-patches/EntityLeash.patch
2016-05-10 21:47:39 +10:00

59 lines
2.8 KiB
Diff

--- a/net/minecraft/server/EntityLeash.java
+++ b/net/minecraft/server/EntityLeash.java
@@ -1,5 +1,7 @@
package net.minecraft.server;
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+
import java.util.Iterator;
import java.util.List;
import javax.annotation.Nullable;
@@ -74,6 +76,12 @@
while (iterator.hasNext()) {
entityinsentient = (EntityInsentient) iterator.next();
if (entityinsentient.isLeashed() && entityinsentient.getLeashHolder() == entityhuman) {
+ // CraftBukkit start
+ if (CraftEventFactory.callPlayerLeashEntityEvent(entityinsentient, this, entityhuman).isCancelled()) {
+ ((EntityPlayer) entityhuman).playerConnection.sendPacket(new PacketPlayOutAttachEntity(entityinsentient, entityinsentient.getLeashHolder()));
+ continue;
+ }
+ // CraftBukkit end
entityinsentient.setLeashHolder(this, true);
flag = true;
}
@@ -81,8 +89,11 @@
}
if (!flag) {
- this.die();
- if (entityhuman.abilities.canInstantlyBuild) {
+ // CraftBukkit start - Move below
+ // this.die();
+ boolean die = true;
+ // CraftBukkit end
+ if (true || entityhuman.abilities.canInstantlyBuild) { // CraftBukkit - Process for non-creative as well
d0 = 7.0D;
list = this.world.a(EntityInsentient.class, new AxisAlignedBB(this.locX - d0, this.locY - d0, this.locZ - d0, this.locX + d0, this.locY + d0, this.locZ + d0));
iterator = list.iterator();
@@ -90,9 +101,20 @@
while (iterator.hasNext()) {
entityinsentient = (EntityInsentient) iterator.next();
if (entityinsentient.isLeashed() && entityinsentient.getLeashHolder() == this) {
- entityinsentient.unleash(true, false);
+ // CraftBukkit start
+ if (CraftEventFactory.callPlayerUnleashEntityEvent(entityinsentient, entityhuman).isCancelled()) {
+ die = false;
+ continue;
+ }
+ entityinsentient.unleash(true, !entityhuman.abilities.canInstantlyBuild); // false -> survival mode boolean
+ // CraftBukkit end
}
}
+ // CraftBukkit start
+ if (die) {
+ this.die();
+ }
+ // CraftBukkit end
}
}