mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-30 21:07:36 +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.
This commit is contained in:
parent
155874eec9
commit
b292a9dfbc
@ -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,9 +465,26 @@ 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())) {
|
||||||
|
// 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.setSitting(false);
|
||||||
entitywolf1.c(entityliving);
|
entitywolf1.c(entityliving);
|
||||||
}
|
}
|
||||||
|
// CraftBukkit end
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user