summaryrefslogtreecommitdiffstats
path: root/nms-patches/EntityEnderman.patch
blob: dc6ad7787653ef3d60d481dd1de6669da74de6ed (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
60
61
62
63
64
65
66
--- a/net/minecraft/server/EntityEnderman.java
+++ b/net/minecraft/server/EntityEnderman.java
@@ -4,6 +4,8 @@
 import com.google.common.base.Optional;
 import com.google.common.base.Predicate;
 import com.google.common.collect.Sets;
+import org.bukkit.event.entity.EntityTargetEvent;
+
 import java.util.Random;
 import java.util.Set;
 import java.util.UUID;
@@ -56,7 +58,17 @@
     }
 
     public void setGoalTarget(@Nullable EntityLiving entityliving) {
-        super.setGoalTarget(entityliving);
+        // CraftBukkit start - fire event
+        setGoalTarget(entityliving, EntityTargetEvent.TargetReason.UNKNOWN, true);
+    }
+
+    @Override
+    public boolean setGoalTarget(EntityLiving entityliving, org.bukkit.event.entity.EntityTargetEvent.TargetReason reason, boolean fireEvent) {
+        if (!super.setGoalTarget(entityliving, reason, fireEvent)) {
+            return false;
+        }
+        entityliving = getGoalTarget();
+        // CraftBukkit end
         AttributeInstance attributeinstance = this.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED);
 
         if (entityliving == null) {
@@ -70,6 +82,7 @@
                 attributeinstance.b(EntityEnderman.b);
             }
         }
+        return true;
 
     }
 
@@ -317,8 +330,12 @@
             boolean flag = movingobjectposition != null && movingobjectposition.a().equals(blockposition);
 
             if (EntityEnderman.c.contains(block) && flag) {
-                this.enderman.setCarried(iblockdata);
-                world.setAir(blockposition);
+                // CraftBukkit start - Pickup event
+                if (!org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(this.enderman, this.enderman.world.getWorld().getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ()), org.bukkit.Material.AIR).isCancelled()) {
+                    this.enderman.setCarried(iblockdata);
+                    world.setAir(blockposition);
+                }
+                // CraftBukkit end
             }
 
         }
@@ -348,8 +365,12 @@
             IBlockData iblockdata2 = this.a.getCarried();
 
             if (iblockdata2 != null && this.a(world, blockposition, iblockdata2.getBlock(), iblockdata, iblockdata1)) {
+                // CraftBukkit start - Place event
+                if (!org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(this.a, blockposition, this.a.getCarried().getBlock(), this.a.getCarried().getBlock().toLegacyData(this.a.getCarried())).isCancelled()) {
                 world.setTypeAndData(blockposition, iblockdata2, 3);
                 this.a.setCarried((IBlockData) null);
+                }
+                // CraftBukkit end
             }
 
         }