13
0
geforkt von Mirrors/Paper

SPIGOT-4339: Add EntityTransformEvent

Thanks klugemonkey for some contributions in https://hub.spigotmc.org/stash/projects/SPIGOT/repos/bukkit/pull-requests/351/overview
Dieser Commit ist enthalten in:
nathat890 2018-11-14 14:10:22 +11:00 committet von md_5
Ursprung 17ff1e0467
Commit d2c422f13e
7 geänderte Dateien mit 119 neuen und 34 gelöschten Zeilen

Datei anzeigen

@ -1,14 +1,19 @@
--- a/net/minecraft/server/EntityMushroomCow.java --- a/net/minecraft/server/EntityMushroomCow.java
+++ b/net/minecraft/server/EntityMushroomCow.java +++ b/net/minecraft/server/EntityMushroomCow.java
@@ -1,6 +1,7 @@ @@ -2,6 +2,12 @@
package net.minecraft.server;
import javax.annotation.Nullable; 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 { public class EntityMushroomCow extends EntityCow {
@@ -23,6 +24,14 @@ public EntityMushroomCow(World world) {
@@ -23,6 +29,14 @@
return true; return true;
} else if (itemstack.getItem() == Items.SHEARS && this.getAge() >= 0) { } 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); 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) { if (!this.world.isClientSide) {
this.die(); 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) {

Datei anzeigen

@ -1,15 +1,18 @@
--- a/net/minecraft/server/EntityPig.java --- a/net/minecraft/server/EntityPig.java
+++ b/net/minecraft/server/EntityPig.java +++ b/net/minecraft/server/EntityPig.java
@@ -2,6 +2,8 @@ @@ -2,6 +2,11 @@
import javax.annotation.Nullable; 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 { public class EntityPig extends EntityAnimal {
private static final DataWatcherObject<Boolean> bC = DataWatcher.a(EntityPig.class, DataWatcherRegistry.i); 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) { public void die(DamageSource damagesource) {
@ -25,7 +28,7 @@
} }
@Nullable @Nullable
@@ -149,6 +152,12 @@ @@ -149,6 +155,12 @@
if (!this.world.isClientSide && !this.dead) { if (!this.world.isClientSide && !this.dead) {
EntityPigZombie entitypigzombie = new EntityPigZombie(this.world); EntityPigZombie entitypigzombie = new EntityPigZombie(this.world);
@ -38,11 +41,16 @@
entitypigzombie.setSlot(EnumItemSlot.MAINHAND, new ItemStack(Items.GOLDEN_SWORD)); entitypigzombie.setSlot(EnumItemSlot.MAINHAND, new ItemStack(Items.GOLDEN_SWORD));
entitypigzombie.setPositionRotation(this.locX, this.locY, this.locZ, this.yaw, this.pitch); entitypigzombie.setPositionRotation(this.locX, this.locY, this.locZ, this.yaw, this.pitch);
entitypigzombie.setNoAI(this.isNoAI()); entitypigzombie.setNoAI(this.isNoAI());
@@ -157,7 +166,8 @@ @@ -157,7 +169,13 @@
entitypigzombie.setCustomNameVisible(this.getCustomNameVisible()); entitypigzombie.setCustomNameVisible(this.getCustomNameVisible());
} }
- this.world.addEntity(entitypigzombie); - 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 + // CraftBukkit - added a reason for spawning this creature
+ this.world.addEntity(entitypigzombie, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.LIGHTNING); + this.world.addEntity(entitypigzombie, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.LIGHTNING);
this.die(); this.die();

Datei anzeigen

@ -1,16 +1,18 @@
--- a/net/minecraft/server/EntitySlime.java --- a/net/minecraft/server/EntitySlime.java
+++ b/net/minecraft/server/EntitySlime.java +++ b/net/minecraft/server/EntitySlime.java
@@ -1,6 +1,9 @@ @@ -1,6 +1,11 @@
package net.minecraft.server; package net.minecraft.server;
import javax.annotation.Nullable; import javax.annotation.Nullable;
+// CraftBukkit start +// CraftBukkit start
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.event.entity.EntityTransformEvent;
+import org.bukkit.event.entity.SlimeSplitEvent; +import org.bukkit.event.entity.SlimeSplitEvent;
+// CraftBukkit end +// CraftBukkit end
public class EntitySlime extends EntityInsentient implements IMonster { public class EntitySlime extends EntityInsentient implements IMonster {
@@ -134,7 +137,7 @@ @@ -134,7 +139,7 @@
} }
public EntityTypes<? extends EntitySlime> P() { public EntityTypes<? extends EntitySlime> P() {
@ -19,7 +21,7 @@
} }
public void die() { public void die() {
@@ -143,6 +146,18 @@ @@ -143,6 +148,18 @@
if (!this.world.isClientSide && i > 1 && this.getHealth() <= 0.0F) { if (!this.world.isClientSide && i > 1 && this.getHealth() <= 0.0F) {
int j = 2 + this.random.nextInt(3); int j = 2 + this.random.nextInt(3);
@ -38,11 +40,17 @@
for (int k = 0; k < j; ++k) { for (int k = 0; k < j; ++k) {
float f = ((float) (k % 2) - 0.5F) * (float) i / 4.0F; float f = ((float) (k % 2) - 0.5F) * (float) i / 4.0F;
float f1 = ((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.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); 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); - 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 + this.world.addEntity(entityslime, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.SLIME_SPLIT); // CraftBukkit - SpawnReason
} }
} }

Datei anzeigen

@ -1,21 +1,23 @@
--- a/net/minecraft/server/EntityVillager.java --- a/net/minecraft/server/EntityVillager.java
+++ b/net/minecraft/server/EntityVillager.java +++ b/net/minecraft/server/EntityVillager.java
@@ -7,6 +7,14 @@ @@ -7,6 +7,16 @@
import javax.annotation.Nullable; import javax.annotation.Nullable;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
+// CraftBukkit start +// CraftBukkit start
+import org.bukkit.Bukkit; +import org.bukkit.Bukkit;
+import org.bukkit.craftbukkit.entity.CraftVillager; +import org.bukkit.craftbukkit.entity.CraftVillager;
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.craftbukkit.inventory.CraftMerchantRecipe; +import org.bukkit.craftbukkit.inventory.CraftMerchantRecipe;
+import org.bukkit.entity.Villager; +import org.bukkit.entity.Villager;
+import org.bukkit.event.entity.EntityTransformEvent;
+import org.bukkit.event.entity.VillagerAcquireTradeEvent; +import org.bukkit.event.entity.VillagerAcquireTradeEvent;
+import org.bukkit.event.entity.VillagerReplenishTradeEvent; +import org.bukkit.event.entity.VillagerReplenishTradeEvent;
+// CraftBukkit end +// CraftBukkit end
public class EntityVillager extends EntityAgeable implements NPC, IMerchant { public class EntityVillager extends EntityAgeable implements NPC, IMerchant {
@@ -38,7 +46,7 @@ @@ -38,7 +48,7 @@
public EntityVillager(World world, int i) { public EntityVillager(World world, int i) {
super(EntityTypes.VILLAGER, world); super(EntityTypes.VILLAGER, world);
@ -24,7 +26,7 @@
this.setProfession(i); this.setProfession(i);
this.setSize(0.6F, 1.95F); this.setSize(0.6F, 1.95F);
((Navigation) this.getNavigation()).a(true); ((Navigation) this.getNavigation()).a(true);
@@ -120,7 +128,14 @@ @@ -120,7 +130,14 @@
MerchantRecipe merchantrecipe = (MerchantRecipe) iterator.next(); MerchantRecipe merchantrecipe = (MerchantRecipe) iterator.next();
if (merchantrecipe.h()) { 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) { for (int l = 0; l < k; ++l) {
EntityVillager.IMerchantRecipeOption entityvillager_imerchantrecipeoption = aentityvillager_imerchantrecipeoption3[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();
}

Datei anzeigen

@ -1,20 +1,22 @@
--- a/net/minecraft/server/EntityZombie.java --- a/net/minecraft/server/EntityZombie.java
+++ b/net/minecraft/server/EntityZombie.java +++ b/net/minecraft/server/EntityZombie.java
@@ -6,6 +6,13 @@ @@ -6,6 +6,15 @@
import java.util.UUID; import java.util.UUID;
import javax.annotation.Nullable; import javax.annotation.Nullable;
+// CraftBukkit start +// CraftBukkit start
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.event.entity.CreatureSpawnEvent; +import org.bukkit.event.entity.CreatureSpawnEvent;
+import org.bukkit.event.entity.EntityCombustByEntityEvent; +import org.bukkit.event.entity.EntityCombustByEntityEvent;
+import org.bukkit.event.entity.EntityCombustEvent; +import org.bukkit.event.entity.EntityCombustEvent;
+import org.bukkit.event.entity.EntityTargetEvent; +import org.bukkit.event.entity.EntityTargetEvent;
+import org.bukkit.event.entity.EntityTransformEvent;
+// CraftBukkit end +// CraftBukkit end
+ +
public class EntityZombie extends EntityMonster { 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"); 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 int bJ;
private float bK; private float bK;
private float bL; private float bL;
@ -22,7 +24,7 @@
public EntityZombie(EntityTypes<?> entitytypes, World world) { public EntityZombie(EntityTypes<?> entitytypes, World world) {
super(entitytypes, world); super(entitytypes, world);
@@ -143,8 +151,12 @@ @@ -143,8 +153,12 @@
public void tick() { public void tick() {
if (!this.world.isClientSide) { if (!this.world.isClientSide) {
@ -37,7 +39,7 @@
if (this.bJ < 0) { if (this.bJ < 0) {
this.dE(); this.dE();
} }
@@ -182,7 +194,14 @@ @@ -182,7 +196,14 @@
} }
if (flag) { if (flag) {
@ -53,16 +55,21 @@
} }
} }
@@ -221,7 +240,7 @@ @@ -221,7 +242,12 @@
entityzombie.setCustomNameVisible(this.getCustomNameVisible()); entityzombie.setCustomNameVisible(this.getCustomNameVisible());
} }
- this.world.addEntity(entityzombie); - 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.world.addEntity(entityzombie, CreatureSpawnEvent.SpawnReason.DROWNED); // CraftBukkit - added spawn reason
this.die(); 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) { 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); 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())) { 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); 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)); 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)); 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(); float f = this.world.getDamageScaler(new BlockPosition(this)).b();
if (this.getItemInMainHand().isEmpty() && this.isBurning() && this.random.nextFloat() < f * 0.3F) { 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()); entityzombievillager.setCustomNameVisible(entityvillager.getCustomNameVisible());
} }
- this.world.addEntity(entityzombievillager); - 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.addEntity(entityzombievillager, CreatureSpawnEvent.SpawnReason.INFECTION); // CraftBukkit - add SpawnReason
this.world.a((EntityHuman) null, 1026, new BlockPosition(this), 0); 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.setPositionRotation(this.locX, this.locY, this.locZ, this.yaw, 0.0F);
entitychicken1.prepare(difficultydamagescaler, (GroupDataEntity) null, (NBTTagCompound) null); entitychicken1.prepare(difficultydamagescaler, (GroupDataEntity) null, (NBTTagCompound) null);
entitychicken1.s(true); entitychicken1.s(true);
@ -107,7 +119,7 @@
this.startRiding(entitychicken1); this.startRiding(entitychicken1);
} }
} }
@@ -495,7 +521,7 @@ @@ -495,7 +533,7 @@
} }
public void die(DamageSource damagesource) { public void die(DamageSource damagesource) {
@ -116,7 +128,7 @@
if (damagesource.getEntity() instanceof EntityCreeper) { if (damagesource.getEntity() instanceof EntityCreeper) {
EntityCreeper entitycreeper = (EntityCreeper) damagesource.getEntity(); EntityCreeper entitycreeper = (EntityCreeper) damagesource.getEntity();
@@ -508,6 +534,7 @@ @@ -508,6 +546,7 @@
} }
} }
} }

Datei anzeigen

@ -1,6 +1,17 @@
--- a/net/minecraft/server/EntityZombieVillager.java --- a/net/minecraft/server/EntityZombieVillager.java
+++ b/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 static final DataWatcherObject<Integer> b = DataWatcher.a(EntityZombieVillager.class, DataWatcherRegistry.b);
private int conversionTime; private int conversionTime;
private UUID bD; private UUID bD;
@ -8,7 +19,7 @@
public EntityZombieVillager(World world) { public EntityZombieVillager(World world) {
super(EntityTypes.ZOMBIE_VILLAGER, world); super(EntityTypes.ZOMBIE_VILLAGER, world);
@@ -54,8 +55,13 @@ @@ -54,8 +59,13 @@
} }
public void tick() { public void tick() {
@ -23,7 +34,7 @@
this.conversionTime -= i; this.conversionTime -= i;
if (this.conversionTime <= 0) { if (this.conversionTime <= 0) {
@@ -100,8 +106,10 @@ @@ -100,8 +110,10 @@
this.bD = uuid; this.bD = uuid;
this.conversionTime = i; this.conversionTime = i;
this.getDataWatcher().set(EntityZombieVillager.a, Boolean.valueOf(true)); this.getDataWatcher().set(EntityZombieVillager.a, Boolean.valueOf(true));
@ -36,16 +47,21 @@
this.world.broadcastEntityEffect(this, (byte) 16); this.world.broadcastEntityEffect(this, (byte) 16);
} }
@@ -123,7 +131,7 @@ @@ -123,7 +135,12 @@
entityvillager.setCustomNameVisible(this.getCustomNameVisible()); entityvillager.setCustomNameVisible(this.getCustomNameVisible());
} }
- this.world.addEntity(entityvillager); - 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 + this.world.addEntity(entityvillager, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.CURED); // CraftBukkit - add SpawnReason
if (this.bD != null) { if (this.bD != null) {
EntityHuman entityhuman = this.world.b(this.bD); EntityHuman entityhuman = this.world.b(this.bD);
@@ -132,7 +140,7 @@ @@ -132,7 +149,7 @@
} }
} }

Datei anzeigen

@ -300,6 +300,16 @@ public class CraftEventFactory {
return event; return event;
} }
/**
* 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 * EntityShootBowEvent
*/ */