summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornathat890 <nathat890@outlook.com>2018-11-14 14:10:22 +1100
committermd_5 <git@md-5.net>2018-11-14 14:10:22 +1100
commitd2c422f13e5226a81b7fe3f8355922beed2a9cfc (patch)
tree30818363607320b8a215b541292364dcc03932b8
parent17ff1e04679d5826f7d574fecc1a97820d5579d1 (diff)
downloadcraftbukkit-d2c422f13e5226a81b7fe3f8355922beed2a9cfc.tar
craftbukkit-d2c422f13e5226a81b7fe3f8355922beed2a9cfc.tar.gz
craftbukkit-d2c422f13e5226a81b7fe3f8355922beed2a9cfc.tar.lz
craftbukkit-d2c422f13e5226a81b7fe3f8355922beed2a9cfc.tar.xz
craftbukkit-d2c422f13e5226a81b7fe3f8355922beed2a9cfc.zip
SPIGOT-4339: Add EntityTransformEvent
Thanks klugemonkey for some contributions in https://hub.spigotmc.org/stash/projects/SPIGOT/repos/bukkit/pull-requests/351/overview
-rw-r--r--nms-patches/EntityMushroomCow.patch25
-rw-r--r--nms-patches/EntityPig.patch18
-rw-r--r--nms-patches/EntitySlime.patch16
-rw-r--r--nms-patches/EntityVillager.patch24
-rw-r--r--nms-patches/EntityZombie.patch34
-rw-r--r--nms-patches/EntityZombieVillager.patch26
-rw-r--r--src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java10
7 files changed, 119 insertions, 34 deletions
diff --git a/nms-patches/EntityMushroomCow.patch b/nms-patches/EntityMushroomCow.patch
index 0be5ad07..e39e2781 100644
--- a/nms-patches/EntityMushroomCow.patch
+++ b/nms-patches/EntityMushroomCow.patch
@@ -1,14 +1,19 @@
--- a/net/minecraft/server/EntityMushroomCow.java
+++ b/net/minecraft/server/EntityMushroomCow.java
-@@ -1,6 +1,7 @@
- package net.minecraft.server;
+@@ -2,6 +2,12 @@
import javax.annotation.Nullable;
-+import org.bukkit.event.player.PlayerShearEntityEvent; // CraftBukkit
++// 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 {
-@@ -23,6 +24,14 @@
+ public EntityMushroomCow(World world) {
+@@ -23,6 +29,14 @@
return true;
} else if (itemstack.getItem() == Items.SHEARS && this.getAge() >= 0) {
@@ -23,3 +28,15 @@
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,6 +49,11 @@
+ entitycow.setCustomName(this.getCustomName());
+ }
+
++ // CraftBukkit start
++ if (CraftEventFactory.callEntityTransformEvent(this, entitycow, EntityTransformEvent.TransformReason.SHEARED).isCancelled()) {
++ return false;
++ }
++ // CraftBukkit end
+ this.world.addEntity(entitycow);
+
+ for (int i = 0; i < 5; ++i) {
diff --git a/nms-patches/EntityPig.patch b/nms-patches/EntityPig.patch
index 02669176..83c89247 100644
--- a/nms-patches/EntityPig.patch
+++ b/nms-patches/EntityPig.patch
@@ -1,15 +1,18 @@
--- a/net/minecraft/server/EntityPig.java
+++ b/net/minecraft/server/EntityPig.java
-@@ -2,6 +2,8 @@
+@@ -2,6 +2,11 @@
import javax.annotation.Nullable;
-+import org.bukkit.craftbukkit.event.CraftEventFactory; // CraftBukkit
++// CraftBukkit start
++import org.bukkit.craftbukkit.event.CraftEventFactory;
++import org.bukkit.event.entity.EntityTransformEvent;
++// CraftBukkit end
+
public class EntityPig extends EntityAnimal {
private static final DataWatcherObject<Boolean> bC = DataWatcher.a(EntityPig.class, DataWatcherRegistry.i);
-@@ -118,13 +120,14 @@
+@@ -118,13 +123,14 @@
}
public void die(DamageSource damagesource) {
@@ -25,7 +28,7 @@
}
@Nullable
-@@ -149,6 +152,12 @@
+@@ -149,6 +155,12 @@
if (!this.world.isClientSide && !this.dead) {
EntityPigZombie entitypigzombie = new EntityPigZombie(this.world);
@@ -38,11 +41,16 @@
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 +166,8 @@
+@@ -157,7 +169,13 @@
entitypigzombie.setCustomNameVisible(this.getCustomNameVisible());
}
- this.world.addEntity(entitypigzombie);
++ // CraftBukkit start
++ if (CraftEventFactory.callEntityTransformEvent(this, entitypigzombie, EntityTransformEvent.TransformReason.LIGHTNING).isCancelled()) {
++ return;
++ }
++ // CraftBukkit end
+ // CraftBukkit - added a reason for spawning this creature
+ this.world.addEntity(entitypigzombie, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.LIGHTNING);
this.die();
diff --git a/nms-patches/EntitySlime.patch b/nms-patches/EntitySlime.patch
index 0e817f25..c3edb9da 100644
--- a/nms-patches/EntitySlime.patch
+++ b/nms-patches/EntitySlime.patch
@@ -1,16 +1,18 @@
--- a/net/minecraft/server/EntitySlime.java
+++ b/net/minecraft/server/EntitySlime.java
-@@ -1,6 +1,9 @@
+@@ -1,6 +1,11 @@
package net.minecraft.server;
import javax.annotation.Nullable;
+// CraftBukkit start
++import org.bukkit.craftbukkit.event.CraftEventFactory;
++import org.bukkit.event.entity.EntityTransformEvent;
+import org.bukkit.event.entity.SlimeSplitEvent;
+// CraftBukkit end
public class EntitySlime extends EntityInsentient implements IMonster {
-@@ -134,7 +137,7 @@
+@@ -134,7 +139,7 @@
}
public EntityTypes<? extends EntitySlime> P() {
@@ -19,7 +21,7 @@
}
public void die() {
-@@ -143,6 +146,18 @@
+@@ -143,6 +148,18 @@
if (!this.world.isClientSide && i > 1 && this.getHealth() <= 0.0F) {
int j = 2 + this.random.nextInt(3);
@@ -38,11 +40,17 @@
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 +173,7 @@
+@@ -158,7 +175,13 @@
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
}
}
diff --git a/nms-patches/EntityVillager.patch b/nms-patches/EntityVillager.patch
index 6cfcdfc5..7d9705c9 100644
--- a/nms-patches/EntityVillager.patch
+++ b/nms-patches/EntityVillager.patch
@@ -1,21 +1,23 @@
--- a/net/minecraft/server/EntityVillager.java
+++ b/net/minecraft/server/EntityVillager.java
-@@ -7,6 +7,14 @@
+@@ -7,6 +7,16 @@
import javax.annotation.Nullable;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
+// CraftBukkit start
+import org.bukkit.Bukkit;
+import org.bukkit.craftbukkit.entity.CraftVillager;
++import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.craftbukkit.inventory.CraftMerchantRecipe;
+import org.bukkit.entity.Villager;
++import org.bukkit.event.entity.EntityTransformEvent;
+import org.bukkit.event.entity.VillagerAcquireTradeEvent;
+import org.bukkit.event.entity.VillagerReplenishTradeEvent;
+// CraftBukkit end
public class EntityVillager extends EntityAgeable implements NPC, IMerchant {
-@@ -38,7 +46,7 @@
+@@ -38,7 +48,7 @@
public EntityVillager(World world, int i) {
super(EntityTypes.VILLAGER, world);
@@ -24,7 +26,7 @@
this.setProfession(i);
this.setSize(0.6F, 1.95F);
((Navigation) this.getNavigation()).a(true);
-@@ -120,7 +128,14 @@
+@@ -120,7 +130,14 @@
MerchantRecipe merchantrecipe = (MerchantRecipe) iterator.next();
if (merchantrecipe.h()) {
@@ -40,7 +42,7 @@
}
}
-@@ -132,7 +147,7 @@
+@@ -132,7 +149,7 @@
}
}
@@ -49,7 +51,7 @@
}
}
-@@ -434,7 +449,20 @@
+@@ -434,7 +451,20 @@
for (int l = 0; l < k; ++l) {
EntityVillager.IMerchantRecipeOption entityvillager_imerchantrecipeoption = aentityvillager_imerchantrecipeoption3[l];
@@ -71,3 +73,15 @@
}
}
+@@ -574,6 +604,11 @@
+ entitywitch.setCustomNameVisible(this.getCustomNameVisible());
+ }
+
++ // CraftBukkit start
++ if (CraftEventFactory.callEntityTransformEvent(this, entitywitch, EntityTransformEvent.TransformReason.LIGHTNING).isCancelled()) {
++ return;
++ }
++ // CraftBukkit end
+ this.world.addEntity(entitywitch);
+ this.die();
+ }
diff --git a/nms-patches/EntityZombie.patch b/nms-patches/EntityZombie.patch
index 4a6dc06c..e0c799e0 100644
--- a/nms-patches/EntityZombie.patch
+++ b/nms-patches/EntityZombie.patch
@@ -1,20 +1,22 @@
--- a/net/minecraft/server/EntityZombie.java
+++ b/net/minecraft/server/EntityZombie.java
-@@ -6,6 +6,13 @@
+@@ -6,6 +6,15 @@
import java.util.UUID;
import javax.annotation.Nullable;
+// CraftBukkit start
++import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.event.entity.CreatureSpawnEvent;
+import org.bukkit.event.entity.EntityCombustByEntityEvent;
+import org.bukkit.event.entity.EntityCombustEvent;
+import org.bukkit.event.entity.EntityTargetEvent;
++import org.bukkit.event.entity.EntityTransformEvent;
+// CraftBukkit end
+
public class EntityZombie extends EntityMonster {
protected static final IAttribute c = (new AttributeRanged((IAttribute) null, "zombie.spawnReinforcements", 0.0D, 0.0D, 1.0D)).a("Spawn Reinforcements Chance");
-@@ -21,6 +28,7 @@
+@@ -21,6 +30,7 @@
private int bJ;
private float bK;
private float bL;
@@ -22,7 +24,7 @@
public EntityZombie(EntityTypes<?> entitytypes, World world) {
super(entitytypes, world);
-@@ -143,8 +151,12 @@
+@@ -143,8 +153,12 @@
public void tick() {
if (!this.world.isClientSide) {
@@ -37,7 +39,7 @@
if (this.bJ < 0) {
this.dE();
}
-@@ -182,7 +194,14 @@
+@@ -182,7 +196,14 @@
}
if (flag) {
@@ -53,16 +55,21 @@
}
}
-@@ -221,7 +240,7 @@
+@@ -221,7 +242,12 @@
entityzombie.setCustomNameVisible(this.getCustomNameVisible());
}
- this.world.addEntity(entityzombie);
++ // CraftBukkit start
++ if (CraftEventFactory.callEntityTransformEvent(this, entityzombie, EntityTransformEvent.TransformReason.DROWNED).isCancelled()) {
++ return;
++ }
++ // CraftBukkit end
+ this.world.addEntity(entityzombie, CreatureSpawnEvent.SpawnReason.DROWNED); // CraftBukkit - added spawn reason
this.die();
}
}
-@@ -252,8 +271,8 @@
+@@ -252,8 +278,8 @@
if (this.world.getType(new BlockPosition(i1, j1 - 1, k1)).q() && this.world.getLightLevel(new BlockPosition(i1, j1, k1)) < 10) {
entityzombie.setPosition((double) i1, (double) j1, (double) k1);
if (!this.world.isPlayerNearby((double) i1, (double) j1, (double) k1, 7.0D) && this.world.a_(entityzombie, entityzombie.getBoundingBox()) && this.world.getCubes(entityzombie, entityzombie.getBoundingBox()) && !this.world.containsLiquid(entityzombie.getBoundingBox())) {
@@ -73,7 +80,7 @@
entityzombie.prepare(this.world.getDamageScaler(new BlockPosition(entityzombie)), (GroupDataEntity) null, (NBTTagCompound) null);
this.getAttributeInstance(EntityZombie.c).b(new AttributeModifier("Zombie reinforcement caller charge", -0.05000000074505806D, 0));
entityzombie.getAttributeInstance(EntityZombie.c).b(new AttributeModifier("Zombie reinforcement callee charge", -0.05000000074505806D, 0));
-@@ -276,7 +295,14 @@
+@@ -276,7 +302,14 @@
float f = this.world.getDamageScaler(new BlockPosition(this)).b();
if (this.getItemInMainHand().isEmpty() && this.isBurning() && this.random.nextFloat() < f * 0.3F) {
@@ -89,16 +96,21 @@
}
}
-@@ -372,7 +398,7 @@
+@@ -372,7 +405,12 @@
entityzombievillager.setCustomNameVisible(entityvillager.getCustomNameVisible());
}
- this.world.addEntity(entityzombievillager);
++ // CraftBukkit start
++ if (CraftEventFactory.callEntityTransformEvent(this, entityzombievillager, EntityTransformEvent.TransformReason.INFECTION).isCancelled()) {
++ return;
++ }
++ // CraftBukkit end
+ this.world.addEntity(entityzombievillager, CreatureSpawnEvent.SpawnReason.INFECTION); // CraftBukkit - add SpawnReason
this.world.a((EntityHuman) null, 1026, new BlockPosition(this), 0);
}
-@@ -422,7 +448,7 @@
+@@ -422,7 +460,7 @@
entitychicken1.setPositionRotation(this.locX, this.locY, this.locZ, this.yaw, 0.0F);
entitychicken1.prepare(difficultydamagescaler, (GroupDataEntity) null, (NBTTagCompound) null);
entitychicken1.s(true);
@@ -107,7 +119,7 @@
this.startRiding(entitychicken1);
}
}
-@@ -495,7 +521,7 @@
+@@ -495,7 +533,7 @@
}
public void die(DamageSource damagesource) {
@@ -116,7 +128,7 @@
if (damagesource.getEntity() instanceof EntityCreeper) {
EntityCreeper entitycreeper = (EntityCreeper) damagesource.getEntity();
-@@ -508,6 +534,7 @@
+@@ -508,6 +546,7 @@
}
}
}
diff --git a/nms-patches/EntityZombieVillager.patch b/nms-patches/EntityZombieVillager.patch
index adbd9da4..895bf789 100644
--- a/nms-patches/EntityZombieVillager.patch
+++ b/nms-patches/EntityZombieVillager.patch
@@ -1,6 +1,17 @@
--- a/net/minecraft/server/EntityZombieVillager.java
+++ b/net/minecraft/server/EntityZombieVillager.java
-@@ -9,6 +9,7 @@
+@@ -2,6 +2,10 @@
+
+ import java.util.UUID;
+ import javax.annotation.Nullable;
++// CraftBukkit start
++import org.bukkit.craftbukkit.event.CraftEventFactory;
++import org.bukkit.event.entity.EntityTransformEvent;
++// CraftBukkit end
+
+ public class EntityZombieVillager extends EntityZombie {
+
+@@ -9,6 +13,7 @@
private static final DataWatcherObject<Integer> b = DataWatcher.a(EntityZombieVillager.class, DataWatcherRegistry.b);
private int conversionTime;
private UUID bD;
@@ -8,7 +19,7 @@
public EntityZombieVillager(World world) {
super(EntityTypes.ZOMBIE_VILLAGER, world);
-@@ -54,8 +55,13 @@
+@@ -54,8 +59,13 @@
}
public void tick() {
@@ -23,7 +34,7 @@
this.conversionTime -= i;
if (this.conversionTime <= 0) {
-@@ -100,8 +106,10 @@
+@@ -100,8 +110,10 @@
this.bD = uuid;
this.conversionTime = i;
this.getDataWatcher().set(EntityZombieVillager.a, Boolean.valueOf(true));
@@ -36,16 +47,21 @@
this.world.broadcastEntityEffect(this, (byte) 16);
}
-@@ -123,7 +131,7 @@
+@@ -123,7 +135,12 @@
entityvillager.setCustomNameVisible(this.getCustomNameVisible());
}
- this.world.addEntity(entityvillager);
++ // CraftBukkit start
++ if (CraftEventFactory.callEntityTransformEvent(this, entityvillager, EntityTransformEvent.TransformReason.CURED).isCancelled()) {
++ return;
++ }
++ // CraftBukkit end
+ this.world.addEntity(entityvillager, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.CURED); // CraftBukkit - add SpawnReason
if (this.bD != null) {
EntityHuman entityhuman = this.world.b(this.bD);
-@@ -132,7 +140,7 @@
+@@ -132,7 +149,7 @@
}
}
diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
index 328322c1..aca32147 100644
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
@@ -301,6 +301,16 @@ public class CraftEventFactory {
}
/**
+ * EntityTransformEvent
+ */
+ public static EntityTransformEvent callEntityTransformEvent(EntityLiving original, EntityLiving converted, EntityTransformEvent.TransformReason convertType) {
+ EntityTransformEvent event = new EntityTransformEvent(original.getBukkitEntity(), converted.getBukkitEntity(), convertType);
+ Bukkit.getPluginManager().callEvent(event);
+
+ return event;
+ }
+
+ /**
* EntityShootBowEvent
*/
public static EntityShootBowEvent callEntityShootBowEvent(EntityLiving who, ItemStack itemstack, EntityArrow entityArrow, float force) {