diff options
Diffstat (limited to 'src/main/java/net/minecraft')
6 files changed, 53 insertions, 34 deletions
diff --git a/src/main/java/net/minecraft/server/EntityHuman.java b/src/main/java/net/minecraft/server/EntityHuman.java index 24fc1292..a5da800d 100644 --- a/src/main/java/net/minecraft/server/EntityHuman.java +++ b/src/main/java/net/minecraft/server/EntityHuman.java @@ -671,22 +671,6 @@ public abstract class EntityHuman extends EntityLiving { EntityWolf entitywolf1 = (EntityWolf) entity; if (entitywolf1.isTamed() && entitywolf1.H() == null && this.name.equals(entitywolf1.getOwnerName()) && (!flag || !entitywolf1.isSitting())) { - // CraftBukkit start - org.bukkit.entity.Entity bukkitTarget = entity == null ? null : entityliving.getBukkitEntity(); - - EntityTargetEvent event; - if (flag) { - event = new EntityTargetEvent(entitywolf1.getBukkitEntity(), bukkitTarget, EntityTargetEvent.TargetReason.OWNER_ATTACKED_TARGET); - } else { - event = new EntityTargetEvent(entitywolf1.getBukkitEntity(), bukkitTarget, EntityTargetEvent.TargetReason.TARGET_ATTACKED_OWNER); - } - this.world.getServer().getPluginManager().callEvent(event); - - if (event.isCancelled()) { - continue; - } - // CraftBukkit end - entitywolf1.setSitting(false); entitywolf1.setTarget(entityliving); } diff --git a/src/main/java/net/minecraft/server/EntityMonster.java b/src/main/java/net/minecraft/server/EntityMonster.java index a5881412..5f6dcf65 100644 --- a/src/main/java/net/minecraft/server/EntityMonster.java +++ b/src/main/java/net/minecraft/server/EntityMonster.java @@ -2,7 +2,6 @@ package net.minecraft.server; // CraftBukkit start import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.entity.CraftEntity; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityTargetEvent; @@ -46,20 +45,19 @@ public abstract class EntityMonster extends EntityCreature implements IMonster { if (this.passenger != entity && this.vehicle != entity) { if (entity != this) { - // CraftBukkit start - org.bukkit.entity.Entity bukkitTarget = entity == null ? null : entity.getBukkitEntity(); - - EntityTargetEvent event = new EntityTargetEvent(this.getBukkitEntity(), bukkitTarget, EntityTargetEvent.TargetReason.TARGET_ATTACKED_ENTITY); - Bukkit.getPluginManager().callEvent(event); - - if (!event.isCancelled()) { - if (event.getTarget() == null) { - this.target = null; - this.lastDamager = null; - } else { - this.target = ((CraftEntity) event.getTarget()).getHandle(); - this.lastDamager = this.target instanceof EntityLiving ? (EntityLiving) this.target : null; + // CraftBukkit start - We still need to call events for entities without goals + if (entity != this.target && (this instanceof EntityBlaze || this instanceof EntityEnderman || this instanceof EntitySpider || this instanceof EntityGiantZombie || this instanceof EntitySilverfish)) { + EntityTargetEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callEntityTargetEvent(this, entity, EntityTargetEvent.TargetReason.TARGET_ATTACKED_ENTITY); + + if (!event.isCancelled()) { + if (event.getTarget() == null) { + this.target = null; + } else { + this.target = ((org.bukkit.craftbukkit.entity.CraftEntity) event.getTarget()).getHandle(); + } } + } else { + this.target = entity; } // CraftBukkit end } diff --git a/src/main/java/net/minecraft/server/EntitySlime.java b/src/main/java/net/minecraft/server/EntitySlime.java index 4ed80557..939edc4b 100644 --- a/src/main/java/net/minecraft/server/EntitySlime.java +++ b/src/main/java/net/minecraft/server/EntitySlime.java @@ -1,7 +1,5 @@ package net.minecraft.server; -import org.bukkit.entity.Slime; - public class EntitySlime extends EntityLiving implements IMonster { public float a; @@ -94,7 +92,7 @@ public class EntitySlime extends EntityLiving implements IMonster { protected void d_() { this.aF(); - EntityHuman entityhuman = this.world.findNearbyVulnerablePlayer(this, 16.0D); + EntityHuman entityhuman = this.world.findNearbyVulnerablePlayer(this, 16.0D); // CraftBukkit TODO: EntityTargetEvent if (entityhuman != null) { this.a(entityhuman, 10.0F, 20.0F); @@ -141,7 +139,7 @@ public class EntitySlime extends EntityLiving implements IMonster { int j = 2 + this.random.nextInt(3); // CraftBukkit start - org.bukkit.event.entity.SlimeSplitEvent event = new org.bukkit.event.entity.SlimeSplitEvent((Slime) this.getBukkitEntity(), j); + org.bukkit.event.entity.SlimeSplitEvent event = new org.bukkit.event.entity.SlimeSplitEvent((org.bukkit.entity.Slime) this.getBukkitEntity(), j); this.world.getServer().getPluginManager().callEvent(event); if (!event.isCancelled() && event.getCount() > 0) { diff --git a/src/main/java/net/minecraft/server/PathfinderGoalArrowAttack.java b/src/main/java/net/minecraft/server/PathfinderGoalArrowAttack.java index 479cb1eb..dce0513a 100644 --- a/src/main/java/net/minecraft/server/PathfinderGoalArrowAttack.java +++ b/src/main/java/net/minecraft/server/PathfinderGoalArrowAttack.java @@ -1,5 +1,7 @@ package net.minecraft.server; +import org.bukkit.event.entity.EntityTargetEvent; // CraftBukkit + public class PathfinderGoalArrowAttack extends PathfinderGoal { World a; @@ -36,6 +38,10 @@ public class PathfinderGoalArrowAttack 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(b, null, reason); + // CraftBukkit end this.c = null; } diff --git a/src/main/java/net/minecraft/server/PathfinderGoalMeleeAttack.java b/src/main/java/net/minecraft/server/PathfinderGoalMeleeAttack.java index bed2ba50..283e5f30 100644 --- a/src/main/java/net/minecraft/server/PathfinderGoalMeleeAttack.java +++ b/src/main/java/net/minecraft/server/PathfinderGoalMeleeAttack.java @@ -1,5 +1,7 @@ package net.minecraft.server; +import org.bukkit.event.entity.EntityTargetEvent; // CraftBukkit + public class PathfinderGoalMeleeAttack extends PathfinderGoal { World a; @@ -52,6 +54,10 @@ public class PathfinderGoalMeleeAttack 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(b, null, reason); + // CraftBukkit end this.c = null; this.b.ak().f(); } diff --git a/src/main/java/net/minecraft/server/PathfinderGoalTarget.java b/src/main/java/net/minecraft/server/PathfinderGoalTarget.java index be5371a0..327f235c 100644 --- a/src/main/java/net/minecraft/server/PathfinderGoalTarget.java +++ b/src/main/java/net/minecraft/server/PathfinderGoalTarget.java @@ -1,5 +1,7 @@ package net.minecraft.server; +import org.bukkit.event.entity.EntityTargetEvent; // CraftBukkit + public abstract class PathfinderGoalTarget extends PathfinderGoal { protected EntityLiving c; @@ -100,6 +102,31 @@ public abstract class PathfinderGoalTarget extends PathfinderGoal { } } + // CraftBukkit start - Check all the different target goals for the reason, default to RANDOM_TARGET + EntityTargetEvent.TargetReason reason = EntityTargetEvent.TargetReason.RANDOM_TARGET; + + if (this instanceof PathfinderGoalDefendVillage) { + reason = EntityTargetEvent.TargetReason.DEFEND_VILLAGE; + } else if (this instanceof PathfinderGoalHurtByTarget) { + reason = EntityTargetEvent.TargetReason.TARGET_ATTACKED_ENTITY; + } else if (this instanceof PathfinderGoalNearestAttackableTarget) { + if (entityliving instanceof EntityHuman) { + reason = EntityTargetEvent.TargetReason.CLOSEST_PLAYER; + } + } else if (this instanceof PathfinderGoalOwnerHurtByTarget) { + reason = EntityTargetEvent.TargetReason.TARGET_ATTACKED_OWNER; + } else if (this instanceof PathfinderGoalOwnerHurtTarget) { + reason = EntityTargetEvent.TargetReason.OWNER_ATTACKED_TARGET; + } + + org.bukkit.event.entity.EntityTargetLivingEntityEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callEntityTargetLivingEvent(c, entityliving, reason); + if (event.isCancelled() || event.getTarget() == null) { + return false; + } else if (entityliving.getBukkitEntity() != event.getTarget()) { + this.c.b((EntityLiving) ((org.bukkit.craftbukkit.entity.CraftEntity) event.getTarget()).getHandle()); + } + // CraftBukkit end + return true; } } |