diff --git a/src/main/java/net/minecraft/server/EntityIronGolem.java b/src/main/java/net/minecraft/server/EntityIronGolem.java index afc7e0ee26..dec42cdd41 100644 --- a/src/main/java/net/minecraft/server/EntityIronGolem.java +++ b/src/main/java/net/minecraft/server/EntityIronGolem.java @@ -63,7 +63,12 @@ public class EntityIronGolem extends EntityGolem { protected void o(Entity entity) { if (entity instanceof IMonster && this.aH().nextInt(20) == 0) { - this.setGoalTarget((EntityLiving) entity); + // CraftBukkit start + org.bukkit.event.entity.EntityTargetLivingEntityEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callEntityTargetLivingEvent(this, (EntityLiving) entity, org.bukkit.event.entity.EntityTargetEvent.TargetReason.COLLISION); + if (!event.isCancelled()) { + this.setGoalTarget(((org.bukkit.craftbukkit.entity.CraftLivingEntity) event.getTarget()).getHandle()); + } + // CraftBukkit end } super.o(entity); diff --git a/src/main/java/net/minecraft/server/EntityPigZombie.java b/src/main/java/net/minecraft/server/EntityPigZombie.java index 38d1442224..ec26850670 100644 --- a/src/main/java/net/minecraft/server/EntityPigZombie.java +++ b/src/main/java/net/minecraft/server/EntityPigZombie.java @@ -83,22 +83,20 @@ public class EntityPigZombie extends EntityZombie { if (entity1 instanceof EntityPigZombie) { EntityPigZombie entitypigzombie = (EntityPigZombie) entity1; - entitypigzombie.c(entity); + entitypigzombie.c(entity, EntityTargetEvent.TargetReason.PIG_ZOMBIE_TARGET); } } - this.c(entity); + this.c(entity, EntityTargetEvent.TargetReason.TARGET_ATTACKED_ENTITY); } return super.damageEntity(damagesource, f); } } - private void c(Entity entity) { - // CraftBukkit start - org.bukkit.entity.Entity bukkitTarget = entity == null ? null : entity.getBukkitEntity(); - - EntityTargetEvent event = new EntityTargetEvent(this.getBukkitEntity(), bukkitTarget, EntityTargetEvent.TargetReason.PIG_ZOMBIE_TARGET); + // CraftBukkit start + private void c(Entity entity, EntityTargetEvent.TargetReason reason) { // add TargetReason + EntityTargetEvent event = new EntityTargetEvent(this.getBukkitEntity(), entity.getBukkitEntity(), reason); this.world.getServer().getPluginManager().callEvent(event); if (event.isCancelled()) { diff --git a/src/main/java/net/minecraft/server/EntityWolf.java b/src/main/java/net/minecraft/server/EntityWolf.java index 9a4e0c4cc6..b992d08492 100644 --- a/src/main/java/net/minecraft/server/EntityWolf.java +++ b/src/main/java/net/minecraft/server/EntityWolf.java @@ -1,5 +1,10 @@ package net.minecraft.server; +// CraftBukkit start +import org.bukkit.craftbukkit.event.CraftEventFactory; +import org.bukkit.event.entity.EntityTargetEvent.TargetReason; +// CraftBukkit end + public class EntityWolf extends EntityTameableAnimal { private float bq; @@ -236,6 +241,11 @@ public class EntityWolf extends EntityTameableAnimal { this.bc = false; this.setPathEntity((PathEntity) null); this.setTarget((Entity) null); + // CraftBukkit start + if (this.getGoalTarget() != null) { + CraftEventFactory.callEntityTargetEvent(this, null, TargetReason.FORGOT_TARGET); + } + // CraftBukkit end this.setGoalTarget((EntityLiving) null); } } else if (itemstack != null && itemstack.getItem() == Items.BONE && !this.isAngry()) { @@ -249,9 +259,14 @@ public class EntityWolf extends EntityTameableAnimal { if (!this.world.isStatic) { // CraftBukkit - added event call and isCancelled check. - if (this.random.nextInt(3) == 0 && !org.bukkit.craftbukkit.event.CraftEventFactory.callEntityTameEvent(this, entityhuman).isCancelled()) { + if (this.random.nextInt(3) == 0 && !CraftEventFactory.callEntityTameEvent(this, entityhuman).isCancelled()) { this.setTamed(true); this.setPathEntity((PathEntity) null); + // CraftBukkit start + if (this.getGoalTarget() != null) { + CraftEventFactory.callEntityTargetEvent(this, null, TargetReason.FORGOT_TARGET); + } + // CraftBukkit end this.setGoalTarget((EntityLiving) null); this.bp.setSitting(true); this.setHealth(this.getMaxHealth()); // CraftBukkit - 20.0 -> getMaxHealth() diff --git a/src/main/java/net/minecraft/server/EntityZombie.java b/src/main/java/net/minecraft/server/EntityZombie.java index 66c4c9c449..ecb4abe18a 100644 --- a/src/main/java/net/minecraft/server/EntityZombie.java +++ b/src/main/java/net/minecraft/server/EntityZombie.java @@ -10,6 +10,7 @@ import org.bukkit.craftbukkit.entity.CraftLivingEntity; import org.bukkit.event.entity.CreatureSpawnEvent; import org.bukkit.event.entity.EntityCombustByEntityEvent; import org.bukkit.event.entity.EntityCombustEvent; +import org.bukkit.event.entity.EntityTargetEvent; //CraftBukkit end public class EntityZombie extends EntityMonster { @@ -188,7 +189,13 @@ public class EntityZombie extends EntityMonster { entityzombie.setPosition((double) i1, (double) j1, (double) k1); if (this.world.b(entityzombie.boundingBox) && this.world.getCubes(entityzombie, entityzombie.boundingBox).isEmpty() && !this.world.containsLiquid(entityzombie.boundingBox)) { this.world.addEntity(entityzombie, CreatureSpawnEvent.SpawnReason.REINFORCEMENTS); // CraftBukkit - entityzombie.setGoalTarget(entityliving); + // CraftBukkit start - call EntityTargetEvent + org.bukkit.event.entity.EntityTargetLivingEntityEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callEntityTargetLivingEvent(entityzombie, entityliving, EntityTargetEvent.TargetReason.REINFORCEMENT_TARGET); + entityliving = ((org.bukkit.craftbukkit.entity.CraftLivingEntity) event.getTarget()).getHandle(); + if (!event.isCancelled()) { + entityzombie.setGoalTarget(entityliving); + } + // CraftBukkit end entityzombie.a((GroupDataEntity) null); this.getAttributeInstance(bp).a(new AttributeModifier("Zombie reinforcement caller charge", -0.05000000074505806D, 0)); entityzombie.getAttributeInstance(bp).a(new AttributeModifier("Zombie reinforcement callee charge", -0.05000000074505806D, 0)); diff --git a/src/main/java/net/minecraft/server/PathfinderGoalHurtByTarget.java b/src/main/java/net/minecraft/server/PathfinderGoalHurtByTarget.java index 6686f0590e..2a0404eefd 100644 --- a/src/main/java/net/minecraft/server/PathfinderGoalHurtByTarget.java +++ b/src/main/java/net/minecraft/server/PathfinderGoalHurtByTarget.java @@ -32,7 +32,13 @@ public class PathfinderGoalHurtByTarget extends PathfinderGoalTarget { EntityCreature entitycreature = (EntityCreature) iterator.next(); if (this.c != entitycreature && entitycreature.getGoalTarget() == null && !entitycreature.c(this.c.getLastDamager())) { - entitycreature.setGoalTarget(this.c.getLastDamager()); + // CraftBukkit start - call EntityTargetEvent + org.bukkit.event.entity.EntityTargetLivingEntityEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callEntityTargetLivingEvent(entitycreature, this.c.getLastDamager(), org.bukkit.event.entity.EntityTargetEvent.TargetReason.TARGET_ATTACKED_NEARBY_ENTITY); + if (event.isCancelled()) { + continue; + } + entitycreature.setGoalTarget(event.getTarget() == null ? null : ((org.bukkit.craftbukkit.entity.CraftLivingEntity) event.getTarget()).getHandle()); + // CraftBukkit end } } } diff --git a/src/main/java/net/minecraft/server/PathfinderGoalOcelotAttack.java b/src/main/java/net/minecraft/server/PathfinderGoalOcelotAttack.java index 8baf68d3f5..0c08df387e 100644 --- a/src/main/java/net/minecraft/server/PathfinderGoalOcelotAttack.java +++ b/src/main/java/net/minecraft/server/PathfinderGoalOcelotAttack.java @@ -1,5 +1,7 @@ package net.minecraft.server; +import org.bukkit.event.entity.EntityTargetEvent; // CraftBukkit + public class PathfinderGoalOcelotAttack extends PathfinderGoal { World a; @@ -29,6 +31,10 @@ public class PathfinderGoalOcelotAttack extends PathfinderGoal { } public void d() { + // CraftBukkit start + EntityTargetEvent.TargetReason reason = this.c.isAlive() ? EntityTargetEvent.TargetReason.FORGOT_TARGET : EntityTargetEvent.TargetReason.TARGET_DIED; + org.bukkit.craftbukkit.event.CraftEventFactory.callEntityTargetEvent(this.c, null, reason); + // CraftBukkit end this.c = null; this.b.getNavigation().h(); }