3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-20 21:40:06 +01:00

Added wolf damage and target events. Thanks Deaygo!

Dieser Commit ist enthalten in:
EvilSeph 2011-06-17 23:47:33 -04:00
Ursprung b0fcbe7fca
Commit 87b421767c

Datei anzeigen

@ -4,7 +4,14 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
// CraftBukkit start // CraftBukkit start
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.entity.CraftEntity;
import org.bukkit.craftbukkit.event.CraftEventFactory; import org.bukkit.craftbukkit.event.CraftEventFactory;
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.entity.EntityTameEvent; import org.bukkit.event.entity.EntityTameEvent;
// CraftBukkit end // CraftBukkit end
@ -233,8 +240,25 @@ public class EntityWolf extends EntityAnimal {
} else { } else {
if (!this.A() && !this.isAngry()) { if (!this.A() && !this.isAngry()) {
if (entity instanceof EntityHuman) { if (entity instanceof EntityHuman) {
// CraftBukkit start
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.TARGET_ATTACKED_ENTITY);
server.getPluginManager().callEvent(event);
if (!event.isCancelled()) {
if (event.getTarget() == null) {
this.target = null;
} else {
this.setAngry(true); this.setAngry(true);
this.target = (Entity) entity; this.target = ((CraftEntity) event.getTarget()).getHandle();
}
}
// CraftBukkit end
} }
if (entity instanceof EntityArrow && ((EntityArrow) entity).shooter != null) { if (entity instanceof EntityArrow && ((EntityArrow) entity).shooter != null) {
@ -250,12 +274,29 @@ public class EntityWolf extends EntityAnimal {
EntityWolf entitywolf = (EntityWolf) entity1; EntityWolf entitywolf = (EntityWolf) entity1;
if (!entitywolf.A() && entitywolf.target == null) { if (!entitywolf.A() && entitywolf.target == null) {
// CraftBukkit start
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.TARGET_ATTACKED_ENTITY);
server.getPluginManager().callEvent(event);
if (!event.isCancelled()) {
if (event.getTarget() == null) {
this.target = null;
} else {
entitywolf.target = (Entity) entity; entitywolf.target = (Entity) entity;
if (entity instanceof EntityHuman) { if (entity instanceof EntityHuman) {
entitywolf.setAngry(true); entitywolf.setAngry(true);
} }
} }
} }
// CraftBukkit end
}
}
} }
} else if (entity != this && entity != null) { } else if (entity != this && entity != null) {
if (this.A() && entity instanceof EntityHuman && ((EntityHuman) entity).name.equalsIgnoreCase(this.x())) { if (this.A() && entity instanceof EntityHuman && ((EntityHuman) entity).name.equalsIgnoreCase(this.x())) {
@ -291,9 +332,20 @@ public class EntityWolf extends EntityAnimal {
if (this.A()) { if (this.A()) {
b0 = 4; b0 = 4;
} }
// CraftBukkit start
CraftServer server = this.world.getServer();
org.bukkit.entity.Entity damager = this.getBukkitEntity();
org.bukkit.entity.Entity damagee = (entity == null) ? null : entity.getBukkitEntity();
DamageCause damageCause = EntityDamageEvent.DamageCause.ENTITY_ATTACK;
EntityDamageByEntityEvent event = new EntityDamageByEntityEvent(damager, damagee, damageCause, b0);
server.getPluginManager().callEvent(event);
if (!event.isCancelled()) {
entity.damageEntity(this, b0); entity.damageEntity(this, b0);
} }
// CraftBukkit end
}
} }
public boolean a(EntityHuman entityhuman) { public boolean a(EntityHuman entityhuman) {