use of org.bukkit.event.entity.EntityDamageByEntityEvent in project Citizens2 by CitizensDev.
the class EventListen method onEntityDamage.
@EventHandler
public void onEntityDamage(EntityDamageEvent event) {
NPC npc = npcRegistry.getNPC(event.getEntity());
if (npc == null) {
if (event instanceof EntityDamageByEntityEvent) {
npc = npcRegistry.getNPC(((EntityDamageByEntityEvent) event).getDamager());
if (npc == null)
return;
event.setCancelled(!npc.data().get(NPC.DAMAGE_OTHERS_METADATA, true));
NPCDamageEntityEvent damageEvent = new NPCDamageEntityEvent(npc, (EntityDamageByEntityEvent) event);
Bukkit.getPluginManager().callEvent(damageEvent);
}
return;
}
event.setCancelled(npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true));
if (event instanceof EntityDamageByEntityEvent) {
NPCDamageByEntityEvent damageEvent = new NPCDamageByEntityEvent(npc, (EntityDamageByEntityEvent) event);
Bukkit.getPluginManager().callEvent(damageEvent);
if (!damageEvent.isCancelled() || !(damageEvent.getDamager() instanceof Player))
return;
Player damager = (Player) damageEvent.getDamager();
NPCLeftClickEvent leftClickEvent = new NPCLeftClickEvent(npc, damager);
Bukkit.getPluginManager().callEvent(leftClickEvent);
} else if (event instanceof EntityDamageByBlockEvent) {
Bukkit.getPluginManager().callEvent(new NPCDamageByBlockEvent(npc, (EntityDamageByBlockEvent) event));
} else {
Bukkit.getPluginManager().callEvent(new NPCDamageEvent(npc, event));
}
}
use of org.bukkit.event.entity.EntityDamageByEntityEvent in project Statz by Staartvin.
the class KillsMobsListener method onDie.
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onDie(final EntityDeathEvent event) {
final PlayerStat stat = PlayerStat.KILLS_MOBS;
Entity e = event.getEntity();
if (!(e.getLastDamageCause() instanceof EntityDamageByEntityEvent)) {
return;
}
EntityDamageByEntityEvent nEvent = (EntityDamageByEntityEvent) e.getLastDamageCause();
if (nEvent.getDamager() instanceof Player) {
// Entity died because of Player
// Killer
final Player player = (Player) nEvent.getDamager();
// Do general check
if (!plugin.doGeneralCheck(player, stat))
return;
if (e instanceof Player) {
// Player killed player
// Handled by other listener
} else {
// Player killed mob
String mobType = StatzUtil.getMobType(e);
String weapon = "";
ItemStack item = player.getInventory().getItemInMainHand();
if (item.getType() == Material.AIR) {
weapon = "HAND";
} else {
weapon = item.getType().toString();
}
// Update value to new stat.
plugin.getDataManager().setPlayerInfo(player.getUniqueId(), stat, StatzUtil.makeQuery("uuid", player.getUniqueId().toString(), "value", 1, "world", player.getWorld().getName(), "mob", mobType, "weapon", weapon));
}
} else if (nEvent.getDamager() instanceof Arrow) {
// Entity was killed by an arrow, now check if it was shot by a player
Arrow killerArrow = (Arrow) nEvent.getDamager();
if (killerArrow.getShooter() instanceof Player) {
Player shooter = (Player) killerArrow.getShooter();
// Now update database.
plugin.getDataManager().setPlayerInfo(shooter.getUniqueId(), stat, StatzUtil.makeQuery("uuid", shooter.getUniqueId().toString(), "value", 1, "world", shooter.getWorld().getName(), "mob", StatzUtil.getMobType(e), "weapon", "BOW"));
}
}
//
}
use of org.bukkit.event.entity.EntityDamageByEntityEvent in project Towny by ElgarL.
the class TownyEntityMonitorListener method onEntityDeath.
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onEntityDeath(EntityDeathEvent event) {
Entity defenderEntity = event.getEntity();
TownyWorld World = null;
try {
World = TownyUniverse.getDataSource().getWorld(defenderEntity.getLocation().getWorld().getName());
if (!World.isUsingTowny())
return;
} catch (NotRegisteredException e) {
// World not registered with Towny.
return;
}
// Was this a player death?
if (defenderEntity instanceof Player) {
// Killed by another entity?
if (defenderEntity.getLastDamageCause() instanceof EntityDamageByEntityEvent) {
EntityDamageByEntityEvent damageEvent = (EntityDamageByEntityEvent) defenderEntity.getLastDamageCause();
Entity attackerEntity = damageEvent.getDamager();
Player defenderPlayer = (Player) defenderEntity;
Player attackerPlayer = null;
Resident attackerResident = null;
Resident defenderResident = null;
try {
defenderResident = TownyUniverse.getDataSource().getResident(defenderPlayer.getName());
} catch (NotRegisteredException e) {
return;
}
// Was this a missile?
if (attackerEntity instanceof Projectile) {
Projectile projectile = (Projectile) attackerEntity;
if (projectile.getShooter() instanceof Player) {
attackerPlayer = (Player) projectile.getShooter();
try {
attackerResident = TownyUniverse.getDataSource().getResident(attackerPlayer.getName());
} catch (NotRegisteredException e) {
}
}
} else if (attackerEntity instanceof Player) {
// This was a player kill
attackerPlayer = (Player) attackerEntity;
try {
attackerResident = TownyUniverse.getDataSource().getResident(attackerPlayer.getName());
} catch (NotRegisteredException e) {
}
}
/*
* If attackerPlayer or attackerResident are null at this point
* it was a natural death, not PvP.
*/
deathPayment(attackerPlayer, defenderPlayer, attackerResident, defenderResident);
wartimeDeathPoints(attackerPlayer, defenderPlayer, attackerResident, defenderResident);
if (TownySettings.isRemovingOnMonarchDeath())
monarchDeath(attackerPlayer, defenderPlayer, attackerResident, defenderResident);
}
}
}
use of org.bukkit.event.entity.EntityDamageByEntityEvent in project Prism-Bukkit by prism.
the class EntitySerializer method serialize.
/**
* Serialize entity.
* @param entity Entity.
*/
public final void serialize(Entity entity) {
entityName = entity.getType().name().toLowerCase();
// Get custom name
customName = entity.getCustomName();
// Get animal age
if (entity instanceof Ageable) {
isAdult = ((Ageable) entity).isAdult();
}
// Owner
if (entity instanceof Tameable) {
final Tameable mob = (Tameable) entity;
if (mob.getOwner() != null) {
tamingOwner = mob.getOwner().getUniqueId().toString();
} else if (mob.isTamed()) {
tamingOwner = "-none-";
}
}
// Sitting
if (entity instanceof Sittable) {
sitting = ((Sittable) entity).isSitting();
}
EntityDamageEvent damageEvent = entity.getLastDamageCause();
// Saves us the null check
if (damageEvent instanceof EntityDamageByEntityEvent && !damageEvent.isCancelled() && damageEvent.getDamage() > ((LivingEntity) entity).getHealth()) {
EntityDamageByEntityEvent e = (EntityDamageByEntityEvent) damageEvent;
if (e.getDamager() instanceof Projectile) {
customDesc = EntityUtils.getCustomProjectileDescription((Projectile) e.getDamager());
}
}
serializer(entity);
}
use of org.bukkit.event.entity.EntityDamageByEntityEvent in project Prism-Bukkit by prism.
the class DeathUtils method getTameWolfOwner.
/**
* Determines the owner of a tamed wolf.
*
* @param event EntityDeathEvent
* @return String
*/
public static String getTameWolfOwner(EntityDeathEvent event) {
String owner = "";
EntityDamageByEntityEvent e = ((EntityDamageByEntityEvent) event.getEntity().getLastDamageCause());
if (e != null) {
Entity killer = e.getDamager();
if (killer instanceof Wolf) {
Wolf wolf = (Wolf) killer;
if (wolf.isTamed()) {
if (wolf.getOwner() instanceof Player) {
owner = ((Player) wolf.getOwner()).getName();
}
if (wolf.getOwner() instanceof OfflinePlayer) {
owner = wolf.getOwner().getName();
}
}
}
}
return owner;
}
Aggregations