use of org.bukkit.event.entity.EntityDamageEvent in project Denizen by DenizenScript.
the class NPCTagBase method onDeath.
// <--[action]
// @Actions
// death
// death by entity
// death by <entity>
// death by block
// death by <cause>
//
// @Triggers when the NPC dies.
//
// @Context
// <context.killer> returns the entity that killed the NPC (if any)
// <context.shooter> returns the shooter of the killing projectile (if any)
// <context.damage> returns the last amount of damage applied (if any)
// <context.death_cause> returns the last damage cause (if any)
//
// -->
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onDeath(EntityDeathEvent deathEvent) {
NPC citizen = CitizensAPI.getNPCRegistry().getNPC(deathEvent.getEntity());
if (citizen == null || !citizen.hasTrait(AssignmentTrait.class)) {
return;
}
NPCTag npc = new NPCTag(citizen);
EntityDamageEvent event = deathEvent.getEntity().getLastDamageCause();
String deathCause = event == null ? "unknown" : CoreUtilities.toLowerCase(event.getCause().toString()).replace('_', ' ');
Map<String, ObjectTag> context = new HashMap<>();
context.put("damage", new ElementTag(event == null ? 0 : event.getDamage()));
context.put("death_cause", new ElementTag(deathCause));
PlayerTag player = null;
if (event instanceof EntityDamageByEntityEvent) {
Entity killerEntity = ((EntityDamageByEntityEvent) event).getDamager();
context.put("killer", new EntityTag(killerEntity).getDenizenObject());
if (killerEntity instanceof Player) {
player = PlayerTag.mirrorBukkitPlayer((Player) killerEntity);
} else if (killerEntity instanceof Projectile) {
ProjectileSource shooter = ((Projectile) killerEntity).getShooter();
if (shooter instanceof LivingEntity) {
context.put("shooter", new EntityTag((LivingEntity) shooter).getDenizenObject());
if (shooter instanceof Player) {
player = PlayerTag.mirrorBukkitPlayer((Player) shooter);
}
npc.action("death by " + ((LivingEntity) shooter).getType(), player, context);
}
}
npc.action("death by entity", player, context);
npc.action("death by " + killerEntity.getType(), player, context);
} else if (event instanceof EntityDamageByBlockEvent) {
npc.action("death by block", null, context);
}
npc.action("death", player, context);
npc.action("death by " + deathCause, player, context);
}
use of org.bukkit.event.entity.EntityDamageEvent in project AllMiniGames by MiniGameWorlds.
the class BreedMob method onEvent.
@Override
protected void onEvent(Event event) {
if (event instanceof EntityDeathEvent) {
EntityDeathEvent e = (EntityDeathEvent) event;
if (!(e.getEntity() instanceof Mob)) {
return;
}
Mob entity = (Mob) e.getEntity();
// check mob
if (this.mobs.contains(entity)) {
layTwoMobs(entity.getLocation());
// clear drops
e.getDrops().clear();
}
} else if (event instanceof EntityDamageEvent) {
EntityDamageEvent e = (EntityDamageEvent) event;
if (e.getEntity() instanceof Player) {
Player p = (Player) e.getEntity();
// if death
if (p.getHealth() <= e.getDamage()) {
e.setCancelled(true);
// title
sendTitle(p, ChatColor.RED + "DIE", "");
// set live: false
this.setLive(p, false);
}
}
} else if (event instanceof EntityExplodeEvent) {
// prevent block breaking by explosion of creeper
EntityExplodeEvent e = (EntityExplodeEvent) event;
if (!this.mobs.contains(e.getEntity())) {
return;
}
// prevent breaking
e.blockList().clear();
// lay
layTwoMobs(e.getEntity().getLocation());
// sound
SoundTool.play(getPlayers(), Sound.BLOCK_NOTE_BLOCK_CHIME);
}
}
use of org.bukkit.event.entity.EntityDamageEvent in project AllMiniGames by MiniGameWorlds.
the class HiddenArcher method onEvent.
@Override
protected void onEvent(Event event) {
super.onEvent(event);
if (event instanceof EntityDamageEvent) {
EntityDamageEvent damageEvent = (EntityDamageEvent) event;
damageEvent.setCancelled(true);
if (damageEvent instanceof EntityDamageByEntityEvent) {
EntityDamageByEntityEvent e = (EntityDamageByEntityEvent) damageEvent;
// check
Entity damager = e.getDamager();
Entity victimEntity = e.getEntity();
if (!(damager instanceof Snowball && victimEntity instanceof Player)) {
return;
}
Player victim = (Player) victimEntity;
Snowball snowball = (Snowball) damager;
if (snowball.getShooter() instanceof Player) {
Player shooter = ((Player) snowball.getShooter());
if (!this.isSameTeam(victim, shooter)) {
damageEvent.setCancelled(false);
// remove damage
e.setDamage(0);
this.shootPlayer(shooter, victim);
}
}
}
} else if (event instanceof ProjectileLaunchEvent) {
ProjectileLaunchEvent e = (ProjectileLaunchEvent) event;
Projectile proj = e.getEntity();
ProjectileSource shooter = proj.getShooter();
if (proj.getType() == EntityType.SNOWBALL) {
Player p = (Player) shooter;
p.getInventory().addItem(new ItemStack(Material.SNOWBALL));
p.setCooldown(Material.SNOWBALL, 20 * this.reloadCoolDown);
}
}
}
use of org.bukkit.event.entity.EntityDamageEvent in project AllMiniGames by MiniGameWorlds.
the class PassMob method onEvent.
@Override
protected void onEvent(Event event) {
super.onEvent(event);
if (event instanceof EntityDeathEvent) {
EntityDeathEvent e = (EntityDeathEvent) event;
Entity entity = e.getEntity();
if (this.isPassMobEntity(entity)) {
Area area = this.getMobArea(entity);
area.passMobToOtherArea(entity, this.otherArea(area));
// remove drops
e.getDrops().clear();
}
} else if (event instanceof EntityDamageEvent) {
EntityDamageEvent e = (EntityDamageEvent) event;
if (e.getEntity() instanceof Player) {
Player p = (Player) e.getEntity();
// if death
if (p.getHealth() <= e.getDamage()) {
// cancel damage
e.setDamage(0);
// msg
sendTitle(p, ChatColor.RED + "DIE", "");
// heal player
PlayerTool.heal(p);
Team team = this.getTeam(p);
Area area = this.getTeamArea(team);
p.teleport(area.loc);
}
}
}
}
use of org.bukkit.event.entity.EntityDamageEvent in project AllMiniGames by MiniGameWorlds.
the class Bridge method onEvent.
@Override
protected void onEvent(Event event) {
if (event instanceof EntityDamageEvent) {
EntityDamageEvent e = (EntityDamageEvent) event;
e.setDamage(0);
} else if (event instanceof PlayerInteractEvent) {
useSkill((PlayerInteractEvent) event);
}
}
Aggregations