summaryrefslogtreecommitdiffstats
path: root/nms-patches/EntityLeash.patch
blob: 190a91786da87564b23b60f9b20914a288282703 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
--- 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;
 
@@ -73,6 +75,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;
                     }
@@ -80,8 +88,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();
@@ -89,9 +100,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
                 }
             }