summaryrefslogtreecommitdiffstats
path: root/nms-patches/EntityCreeper.patch
blob: 091520348c4bf90303cbc08186941dc66c1d5272 (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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
--- a/net/minecraft/server/EntityCreeper.java
+++ b/net/minecraft/server/EntityCreeper.java
@@ -3,6 +3,10 @@
 import java.util.Collection;
 import java.util.Iterator;
 import javax.annotation.Nullable;
+// CraftBukkit start
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.event.entity.ExplosionPrimeEvent;
+// CraftBukkit end
 
 public class EntityCreeper extends EntityMonster {
 
@@ -121,7 +125,7 @@
     }
 
     public void die(DamageSource damagesource) {
-        super.die(damagesource);
+        // super.die(damagesource); // CraftBukkit - Moved to end
         if (this.world.getGameRules().getBoolean("doMobLoot")) {
             if (damagesource.getEntity() instanceof EntitySkeleton) {
                 this.a((IMaterial) ItemRecord.a(this.random));
@@ -130,6 +134,7 @@
                 this.a((IMaterial) Items.CREEPER_HEAD);
             }
         }
+        super.die(damagesource); // CraftBukkit - Moved from above
 
     }
 
@@ -156,9 +161,19 @@
 
     public void onLightningStrike(EntityLightning entitylightning) {
         super.onLightningStrike(entitylightning);
-        this.datawatcher.set(EntityCreeper.b, Boolean.valueOf(true));
+        // CraftBukkit start
+        if (CraftEventFactory.callCreeperPowerEvent(this, entitylightning, org.bukkit.event.entity.CreeperPowerEvent.PowerCause.LIGHTNING).isCancelled()) {
+            return;
+        }
+
+        this.setPowered(true);
     }
 
+    public void setPowered(boolean powered) {
+        this.datawatcher.set(EntityCreeper.b, powered);
+    }
+    // CraftBukkit end
+
     protected boolean a(EntityHuman entityhuman, EnumHand enumhand) {
         ItemStack itemstack = entityhuman.b(enumhand);
 
@@ -180,10 +195,18 @@
             boolean flag = this.world.getGameRules().getBoolean("mobGriefing");
             float f = this.isPowered() ? 2.0F : 1.0F;
 
-            this.aX = true;
-            this.world.explode(this, this.locX, this.locY, this.locZ, (float) this.explosionRadius * f, flag);
-            this.die();
-            this.dG();
+            // CraftBukkit start
+            ExplosionPrimeEvent event = new ExplosionPrimeEvent(this.getBukkitEntity(), this.explosionRadius * f, false);
+            this.world.getServer().getPluginManager().callEvent(event);
+            if (!event.isCancelled()) {
+                this.aX = true;
+                this.world.createExplosion(this, this.locX, this.locY, this.locZ, event.getRadius(), event.getFire(), flag);
+                this.die();
+                this.dG();
+            } else {
+                fuseTicks = 0;
+            }
+            // CraftBukkit end
         }
 
     }
@@ -194,6 +217,7 @@
         if (!collection.isEmpty()) {
             EntityAreaEffectCloud entityareaeffectcloud = new EntityAreaEffectCloud(this.world, this.locX, this.locY, this.locZ);
 
+            entityareaeffectcloud.setSource(this); // CraftBukkit
             entityareaeffectcloud.setRadius(2.5F);
             entityareaeffectcloud.setRadiusOnUse(-0.5F);
             entityareaeffectcloud.setWaitTime(10);