diff --git a/nms-patches/EntityMushroomCow.patch b/nms-patches/EntityMushroomCow.patch index 3c07a016dd..9997688a37 100644 --- a/nms-patches/EntityMushroomCow.patch +++ b/nms-patches/EntityMushroomCow.patch @@ -13,7 +13,7 @@ public class EntityMushroomCow extends EntityCow { public EntityMushroomCow(World world) { -@@ -23,6 +29,14 @@ +@@ -23,9 +29,17 @@ return true; } else if (itemstack.getItem() == Items.SHEARS && this.getAge() >= 0) { @@ -27,8 +27,12 @@ + // 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(); -@@ -35,7 +49,12 @@ +- 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()); } @@ -38,6 +42,8 @@ + 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) { diff --git a/nms-patches/EntityPig.patch b/nms-patches/EntityPig.patch index 83c892472f..7a01790cf3 100644 --- a/nms-patches/EntityPig.patch +++ b/nms-patches/EntityPig.patch @@ -28,31 +28,18 @@ } @Nullable -@@ -149,6 +155,12 @@ - if (!this.world.isClientSide && !this.dead) { - EntityPigZombie entitypigzombie = new EntityPigZombie(this.world); - -+ // CraftBukkit start -+ if (CraftEventFactory.callPigZapEvent(this, entitylightning, entitypigzombie).isCancelled()) { -+ return; -+ } -+ // CraftBukkit end -+ - entitypigzombie.setSlot(EnumItemSlot.MAINHAND, new ItemStack(Items.GOLDEN_SWORD)); - entitypigzombie.setPositionRotation(this.locX, this.locY, this.locZ, this.yaw, this.pitch); - entitypigzombie.setNoAI(this.isNoAI()); -@@ -157,7 +169,13 @@ +@@ -157,7 +163,13 @@ entitypigzombie.setCustomNameVisible(this.getCustomNameVisible()); } - this.world.addEntity(entitypigzombie); + // CraftBukkit start -+ if (CraftEventFactory.callEntityTransformEvent(this, entitypigzombie, EntityTransformEvent.TransformReason.LIGHTNING).isCancelled()) { ++ if (CraftEventFactory.callPigZapEvent(this, entitylightning, entitypigzombie).isCancelled()) { + return; + } -+ // CraftBukkit end + // CraftBukkit - added a reason for spawning this creature + this.world.addEntity(entitypigzombie, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.LIGHTNING); ++ // CraftBukkit end this.die(); } } diff --git a/nms-patches/EntitySlime.patch b/nms-patches/EntitySlime.patch index c3edb9da7c..50032f3b03 100644 --- a/nms-patches/EntitySlime.patch +++ b/nms-patches/EntitySlime.patch @@ -1,10 +1,12 @@ --- a/net/minecraft/server/EntitySlime.java +++ b/net/minecraft/server/EntitySlime.java -@@ -1,6 +1,11 @@ +@@ -1,6 +1,13 @@ package net.minecraft.server; import javax.annotation.Nullable; +// CraftBukkit start ++import java.util.ArrayList; ++import java.util.List; +import org.bukkit.craftbukkit.event.CraftEventFactory; +import org.bukkit.event.entity.EntityTransformEvent; +import org.bukkit.event.entity.SlimeSplitEvent; @@ -12,7 +14,7 @@ public class EntitySlime extends EntityInsentient implements IMonster { -@@ -134,7 +139,7 @@ +@@ -134,7 +141,7 @@ } public EntityTypes P() { @@ -21,7 +23,7 @@ } public void die() { -@@ -143,6 +148,18 @@ +@@ -143,6 +150,19 @@ if (!this.world.isClientSide && i > 1 && this.getHealth() <= 0.0F) { int j = 2 + this.random.nextInt(3); @@ -35,23 +37,29 @@ + super.die(); + return; + } ++ List slimes = new ArrayList<>(j); + // CraftBukkit end + for (int k = 0; k < j; ++k) { float f = ((float) (k % 2) - 0.5F) * (float) i / 4.0F; float f1 = ((float) (k / 2) - 0.5F) * (float) i / 4.0F; -@@ -158,7 +175,13 @@ +@@ -158,8 +178,18 @@ entityslime.setSize(i / 2, true); entityslime.setPositionRotation(this.locX + (double) f, this.locY + 0.5D, this.locZ + (double) f1, this.random.nextFloat() * 360.0F, 0.0F); - this.world.addEntity(entityslime); + -+ // CraftBukkit start -+ if (CraftEventFactory.callEntityTransformEvent(this, entityslime, EntityTransformEvent.TransformReason.SPLIT).isCancelled()) { -+ continue; -+ } -+ // CraftBukkit end -+ this.world.addEntity(entityslime, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.SLIME_SPLIT); // CraftBukkit - SpawnReason ++ slimes.add(entityslime); // CraftBukkit ++ } ++ ++ // CraftBukkit start ++ if (CraftEventFactory.callEntityTransformEvent(this, slimes, EntityTransformEvent.TransformReason.SPLIT).isCancelled()) { ++ return; ++ } ++ for (EntityLiving living : slimes) { ++ this.world.addEntity(living, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.SLIME_SPLIT); // CraftBukkit - SpawnReason } ++ // CraftBukkit end } + super.die(); diff --git a/nms-patches/EntityZombie.patch b/nms-patches/EntityZombie.patch index e0c799e0fe..b85809fecd 100644 --- a/nms-patches/EntityZombie.patch +++ b/nms-patches/EntityZombie.patch @@ -96,7 +96,16 @@ } } -@@ -372,7 +405,12 @@ +@@ -362,7 +395,7 @@ + EntityZombieVillager entityzombievillager = new EntityZombieVillager(this.world); + + entityzombievillager.u(entityvillager); +- this.world.kill(entityvillager); ++ // this.world.kill(entityvillager); // CraftBukkit - moved down + entityzombievillager.prepare(this.world.getDamageScaler(new BlockPosition(entityzombievillager)), new EntityZombie.GroupDataZombie(false, null), (NBTTagCompound) null); + entityzombievillager.setProfession(entityvillager.getProfession()); + entityzombievillager.setBaby(entityvillager.isBaby()); +@@ -372,7 +405,13 @@ entityzombievillager.setCustomNameVisible(entityvillager.getCustomNameVisible()); } @@ -105,12 +114,13 @@ + if (CraftEventFactory.callEntityTransformEvent(this, entityzombievillager, EntityTransformEvent.TransformReason.INFECTION).isCancelled()) { + return; + } -+ // CraftBukkit end ++ this.world.kill(entityvillager); // CraftBukkit - from above + this.world.addEntity(entityzombievillager, CreatureSpawnEvent.SpawnReason.INFECTION); // CraftBukkit - add SpawnReason ++ // CraftBukkit end this.world.a((EntityHuman) null, 1026, new BlockPosition(this), 0); } -@@ -422,7 +460,7 @@ +@@ -422,7 +461,7 @@ entitychicken1.setPositionRotation(this.locX, this.locY, this.locZ, this.yaw, 0.0F); entitychicken1.prepare(difficultydamagescaler, (GroupDataEntity) null, (NBTTagCompound) null); entitychicken1.s(true); @@ -119,7 +129,7 @@ this.startRiding(entitychicken1); } } -@@ -495,7 +533,7 @@ +@@ -495,7 +534,7 @@ } public void die(DamageSource damagesource) { @@ -128,7 +138,7 @@ if (damagesource.getEntity() instanceof EntityCreeper) { EntityCreeper entitycreeper = (EntityCreeper) damagesource.getEntity(); -@@ -508,6 +546,7 @@ +@@ -508,6 +547,7 @@ } } } diff --git a/nms-patches/EntityZombieVillager.patch b/nms-patches/EntityZombieVillager.patch index 895bf78958..be60d420d7 100644 --- a/nms-patches/EntityZombieVillager.patch +++ b/nms-patches/EntityZombieVillager.patch @@ -47,7 +47,15 @@ this.world.broadcastEntityEffect(this, (byte) 16); } -@@ -123,7 +135,12 @@ +@@ -116,14 +128,20 @@ + entityvillager.setAgeRaw(-24000); + } + +- this.world.kill(this); ++ // this.world.kill(this); // CraftBukkit - moved down + entityvillager.setNoAI(this.isNoAI()); + if (this.hasCustomName()) { + entityvillager.setCustomName(this.getCustomName()); entityvillager.setCustomNameVisible(this.getCustomNameVisible()); } @@ -56,12 +64,13 @@ + if (CraftEventFactory.callEntityTransformEvent(this, entityvillager, EntityTransformEvent.TransformReason.CURED).isCancelled()) { + return; + } -+ // CraftBukkit end ++ this.world.kill(this); // CraftBukkit - from above + this.world.addEntity(entityvillager, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.CURED); // CraftBukkit - add SpawnReason ++ // CraftBukkit end if (this.bD != null) { EntityHuman entityhuman = this.world.b(this.bD); -@@ -132,7 +149,7 @@ +@@ -132,7 +150,7 @@ } } diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java index aca3214785..26e14f0dc2 100644 --- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java +++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java @@ -2,6 +2,7 @@ package org.bukkit.craftbukkit.event; import java.net.InetAddress; import java.util.ArrayList; +import java.util.Collections; import java.util.EnumMap; import java.util.List; import java.util.Map; @@ -303,8 +304,20 @@ public class CraftEventFactory { /** * EntityTransformEvent */ - public static EntityTransformEvent callEntityTransformEvent(EntityLiving original, EntityLiving converted, EntityTransformEvent.TransformReason convertType) { - EntityTransformEvent event = new EntityTransformEvent(original.getBukkitEntity(), converted.getBukkitEntity(), convertType); + public static EntityTransformEvent callEntityTransformEvent(EntityLiving original, EntityLiving coverted, EntityTransformEvent.TransformReason transformReason) { + return callEntityTransformEvent(original, Collections.singletonList(coverted), transformReason); + } + + /** + * EntityTransformEvent + */ + public static EntityTransformEvent callEntityTransformEvent(EntityLiving original, List convertedList, EntityTransformEvent.TransformReason convertType) { + List list = new ArrayList<>(); + for (EntityLiving entityLiving : convertedList) { + list.add(entityLiving.getBukkitEntity()); + } + + EntityTransformEvent event = new EntityTransformEvent(original.getBukkitEntity(), list, convertType); Bukkit.getPluginManager().callEvent(event); return event;