From b292a9dfbc9725de05d81c0702ad5817394c5f36 Mon Sep 17 00:00:00 2001 From: EvilSeph Date: Sat, 18 Jun 2011 22:37:52 -0400 Subject: [PATCH] Added more events for Wolves. Thanks Deaygo! Added events for when wolf owner attacks an entity, or is attacked. Also added event for when a non-tame wolf targets a sheep. --- .../net/minecraft/server/EntityHuman.java | 23 +++++++++++++++++-- .../java/net/minecraft/server/EntityWolf.java | 17 +++++++++++++- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/minecraft/server/EntityHuman.java b/src/main/java/net/minecraft/server/EntityHuman.java index 5b01faaedd..5feff7a7f1 100644 --- a/src/main/java/net/minecraft/server/EntityHuman.java +++ b/src/main/java/net/minecraft/server/EntityHuman.java @@ -10,7 +10,9 @@ import org.bukkit.craftbukkit.TrigMath; import org.bukkit.entity.Player; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.entity.EntityTargetEvent; import org.bukkit.event.entity.EntityDamageEvent.DamageCause; +import org.bukkit.event.entity.EntityTargetEvent.TargetReason; import org.bukkit.event.player.PlayerBedEnterEvent; import org.bukkit.event.player.PlayerBedLeaveEvent; import org.bukkit.event.player.PlayerDropItemEvent; @@ -463,8 +465,25 @@ public abstract class EntityHuman extends EntityLiving { EntityWolf entitywolf1 = (EntityWolf) entity; if (entitywolf1.A() && entitywolf1.E() == null && this.name.equals(entitywolf1.x()) && (!flag || !entitywolf1.isSitting())) { - entitywolf1.setSitting(false); - entitywolf1.c(entityliving); + // CraftBukkit start + CraftServer server = this.world.getServer(); + org.bukkit.entity.Entity bukkitTarget = null; + if (entity != null) { + bukkitTarget = entityliving.getBukkitEntity(); + } + EntityTargetEvent event; + if (flag) { + event = new EntityTargetEvent(entitywolf1.getBukkitEntity(), bukkitTarget, TargetReason.OWNER_ATTACKED_TARGET); + } else { + event = new EntityTargetEvent(entitywolf1.getBukkitEntity(), bukkitTarget, TargetReason.TARGET_ATTACKED_OWNER); + } + server.getPluginManager().callEvent(event); + + if (!event.isCancelled()) { + entitywolf1.setSitting(false); + entitywolf1.c(entityliving); + } + // CraftBukkit end } } } diff --git a/src/main/java/net/minecraft/server/EntityWolf.java b/src/main/java/net/minecraft/server/EntityWolf.java index cfc1228d09..8ef074f0b1 100644 --- a/src/main/java/net/minecraft/server/EntityWolf.java +++ b/src/main/java/net/minecraft/server/EntityWolf.java @@ -109,7 +109,22 @@ public class EntityWolf extends EntityAnimal { List list = this.world.a(EntitySheep.class, AxisAlignedBB.b(this.locX, this.locY, this.locZ, this.locX + 1.0D, this.locY + 1.0D, this.locZ + 1.0D).b(16.0D, 4.0D, 16.0D)); if (!list.isEmpty()) { - this.c((Entity) list.get(this.world.random.nextInt(list.size()))); + // CraftBukkit start + Entity entity = (Entity) list.get(this.world.random.nextInt(list.size())); + + CraftServer server = this.world.getServer(); + org.bukkit.entity.Entity bukkitTarget = null; + if (entity != null) { + bukkitTarget = entity.getBukkitEntity(); + } + + EntityTargetEvent event = new EntityTargetEvent(this.getBukkitEntity(), bukkitTarget, TargetReason.RANDOM_TARGET); + server.getPluginManager().callEvent(event); + + if (!event.isCancelled() || event.getTarget() != null ) { + this.c(entity); + } + // CraftBukkit end } }