summaryrefslogtreecommitdiffstats
path: root/nms-patches/EntityMushroomCow.patch
blob: 9997688a37e891f9ed067727b5ff79bb2e37c2fa (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
--- a/net/minecraft/server/EntityMushroomCow.java
+++ b/net/minecraft/server/EntityMushroomCow.java
@@ -2,6 +2,12 @@
 
 import javax.annotation.Nullable;
 
+// CraftBukkit start
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.event.entity.EntityTransformEvent;
+import org.bukkit.event.player.PlayerShearEntityEvent;
+// CraftBukkit end
+
 public class EntityMushroomCow extends EntityCow {
 
     public EntityMushroomCow(World world) {
@@ -23,9 +29,17 @@
 
             return true;
         } else if (itemstack.getItem() == Items.SHEARS && this.getAge() >= 0) {
+            // CraftBukkit start
+            PlayerShearEntityEvent event = new PlayerShearEntityEvent((org.bukkit.entity.Player) entityhuman.getBukkitEntity(), this.getBukkitEntity());
+            this.world.getServer().getPluginManager().callEvent(event);
+
+            if (event.isCancelled()) {
+                return false;
+            }
+            // CraftBukkit end
             this.world.addParticle(Particles.u, this.locX, this.locY + (double) (this.length / 2.0F), this.locZ, 0.0D, 0.0D, 0.0D);
             if (!this.world.isClientSide) {
-                this.die();
+                // this.die(); // CraftBukkit - moved down
                 EntityCow entitycow = new EntityCow(this.world);
 
                 entitycow.setPositionRotation(this.locX, this.locY, this.locZ, this.yaw, this.pitch);
@@ -35,7 +49,14 @@
                     entitycow.setCustomName(this.getCustomName());
                 }
 
-                this.world.addEntity(entitycow);
+                // CraftBukkit start
+                if (CraftEventFactory.callEntityTransformEvent(this, entitycow, EntityTransformEvent.TransformReason.SHEARED).isCancelled()) {
+                    return false;
+                }
+                this.world.addEntity(entitycow, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.SHEARED);
+
+                this.die(); // CraftBukkit - from above
+                // CraftBukkit end
 
                 for (int i = 0; i < 5; ++i) {
                     this.world.addEntity(new EntityItem(this.world, this.locX, this.locY + (double) this.length, this.locZ, new ItemStack(Blocks.RED_MUSHROOM)));