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

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.
Dieser Commit ist enthalten in:
EvilSeph 2011-06-18 22:37:52 -04:00
Ursprung 155874eec9
Commit b292a9dfbc
2 geänderte Dateien mit 37 neuen und 3 gelöschten Zeilen

Datei anzeigen

@ -10,7 +10,9 @@ import org.bukkit.craftbukkit.TrigMath;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityTargetEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause; 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.PlayerBedEnterEvent;
import org.bukkit.event.player.PlayerBedLeaveEvent; import org.bukkit.event.player.PlayerBedLeaveEvent;
import org.bukkit.event.player.PlayerDropItemEvent; import org.bukkit.event.player.PlayerDropItemEvent;
@ -463,8 +465,25 @@ public abstract class EntityHuman extends EntityLiving {
EntityWolf entitywolf1 = (EntityWolf) entity; EntityWolf entitywolf1 = (EntityWolf) entity;
if (entitywolf1.A() && entitywolf1.E() == null && this.name.equals(entitywolf1.x()) && (!flag || !entitywolf1.isSitting())) { if (entitywolf1.A() && entitywolf1.E() == null && this.name.equals(entitywolf1.x()) && (!flag || !entitywolf1.isSitting())) {
entitywolf1.setSitting(false); // CraftBukkit start
entitywolf1.c(entityliving); 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
} }
} }
} }

Datei anzeigen

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