SPIGOT-4339: Add EntityTransformEvent

Thanks klugemonkey for some contributions in https://hub.spigotmc.org/stash/projects/SPIGOT/repos/bukkit/pull-requests/351/overview

By: nathat890 <nathat890@outlook.com>
This commit is contained in:
CraftBukkit/Spigot
2018-11-14 14:10:22 +11:00
parent 04cffd8092
commit 6fd5f1379b
7 changed files with 119 additions and 34 deletions

View File

@@ -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();