[Bleeding] Added new target events. Fixes BUKKIT-935

This commit is contained in:
feildmaster 2012-03-09 15:40:59 -06:00 committed by EvilSeph
parent a967d6e371
commit 77ef051095
7 changed files with 59 additions and 35 deletions

View File

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

View File

@ -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,21 +45,20 @@ 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);
// 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;
this.lastDamager = null;
} else {
this.target = ((CraftEntity) event.getTarget()).getHandle();
this.lastDamager = this.target instanceof EntityLiving ? (EntityLiving) this.target : null;
this.target = ((org.bukkit.craftbukkit.entity.CraftEntity) event.getTarget()).getHandle();
}
}
} else {
this.target = entity;
}
// CraftBukkit end
}

View File

@ -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) {

View File

@ -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;
}

View File

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

View File

@ -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;
}
}

View File

@ -430,7 +430,13 @@ public class CraftEventFactory {
}
public static EntityTargetEvent callEntityTargetEvent(Entity entity, Entity target, EntityTargetEvent.TargetReason reason) {
EntityTargetEvent event = new EntityTargetEvent(entity.getBukkitEntity(), target.getBukkitEntity(), reason);
EntityTargetEvent event = new EntityTargetEvent(entity.getBukkitEntity(), target == null ? null : target.getBukkitEntity(), reason);
entity.getBukkitEntity().getServer().getPluginManager().callEvent(event);
return event;
}
public static EntityTargetLivingEntityEvent callEntityTargetLivingEvent(Entity entity, EntityLiving target, EntityTargetEvent.TargetReason reason) {
EntityTargetLivingEntityEvent event = new EntityTargetLivingEntityEvent(entity.getBukkitEntity(), (LivingEntity) target.getBukkitEntity(), reason);
entity.getBukkitEntity().getServer().getPluginManager().callEvent(event);
return event;
}
@ -458,7 +464,6 @@ public class CraftEventFactory {
public static ItemStack callPreCraftEvent(InventoryCrafting matrix, ItemStack result, InventoryView lastCraftView, boolean isRepair) {
CraftInventoryCrafting inventory = new CraftInventoryCrafting(matrix, matrix.resultInventory);
inventory.setResult(new CraftItemStack(result));
PrepareItemCraftEvent event = new PrepareItemCraftEvent(inventory, lastCraftView, isRepair);
Bukkit.getPluginManager().callEvent(event);