use of org.bukkit.event.entity.EntityDamageByEntityEvent in project Glowstone by GlowstoneMC.
the class GlowArmorStand method damage.
@Override
public void damage(double amount, Entity source, @NotNull DamageCause cause) {
if (getNoDamageTicks() > 0 || health <= 0 || !canTakeDamage(cause)) {
return;
}
if (source instanceof Projectile && !(source instanceof Arrow)) {
return;
}
EntityDamageEvent event = EventFactory.getInstance().onEntityDamage(source == null ? new EntityDamageEvent(this, cause, amount) : new EntityDamageByEntityEvent(source, this, cause, amount));
if (event.isCancelled()) {
return;
}
boolean drop = false;
if (source instanceof GlowPlayer || source instanceof Arrow && ((Projectile) source).getShooter() instanceof GlowPlayer) {
GlowPlayer damager = (GlowPlayer) (source instanceof GlowPlayer ? source : ((Arrow) source).getShooter());
if (damager.getGameMode() == GameMode.ADVENTURE) {
return;
} else if (damager.getGameMode() == GameMode.CREATIVE) {
// Instantly kill the entity
amount = 2;
} else {
// Needs two hits
amount = 1;
drop = true;
}
}
setLastDamage(amount);
setHealth(health - amount, drop);
}
use of org.bukkit.event.entity.EntityDamageByEntityEvent in project HawkEye by oliverwoodings.
the class MonitorEntityListener method onEntityDeath.
/**
* Uses the lastAttacker field in the players {@link PlayerSession} to log the death and cause
*/
@HawkEvent(dataType = { DataType.PVP_DEATH, DataType.MOB_DEATH, DataType.OTHER_DEATH, DataType.ENTITY_KILL })
public void onEntityDeath(EntityDeathEvent event) {
Entity entity = event.getEntity();
if (entity instanceof Player) {
// Player death
Player victim = (Player) entity;
// Mob or PVP death
if (victim.getLastDamageCause() instanceof EntityDamageByEntityEvent) {
Entity damager = ((EntityDamageByEntityEvent) (victim.getLastDamageCause())).getDamager();
if (damager instanceof Player) {
if (!Config.isLogged(DataType.PVP_DEATH) && !Config.LogDeathDrops)
return;
DataManager.addEntry(new DataEntry(victim, DataType.PVP_DEATH, victim.getLocation(), Util.getEntityName(damager)));
} else {
if (!Config.isLogged(DataType.MOB_DEATH) && !Config.LogDeathDrops)
return;
DataManager.addEntry(new DataEntry(victim, DataType.MOB_DEATH, victim.getLocation(), Util.getEntityName(damager)));
}
// Other death
} else {
if (!Config.isLogged(DataType.OTHER_DEATH) && !Config.LogDeathDrops)
return;
EntityDamageEvent dEvent = victim.getLastDamageCause();
String cause = dEvent == null ? "Unknown" : victim.getLastDamageCause().getCause().name();
String[] words = cause.split("_");
for (int i = 0; i < words.length; i++) words[i] = words[i].substring(0, 1).toUpperCase() + words[i].substring(1).toLowerCase();
cause = Util.join(Arrays.asList(words), " ");
DataManager.addEntry(new DataEntry(victim, DataType.OTHER_DEATH, victim.getLocation(), cause));
}
// Log item drops
if (Config.LogDeathDrops) {
String data = null;
for (ItemStack stack : event.getDrops()) {
if (stack.getData() != null)
data = stack.getAmount() + "x " + stack.getTypeId() + ":" + stack.getData().getData();
else
data = stack.getAmount() + "x " + stack.getTypeId();
DataManager.addEntry(new DataEntry(victim, DataType.ITEM_DROP, victim.getLocation(), data));
}
}
} else {
// Mob Death
if (!Config.isLogged(DataType.ENTITY_KILL))
return;
if (entity.getLastDamageCause() instanceof EntityDamageByEntityEvent) {
Entity damager = ((EntityDamageByEntityEvent) entity.getLastDamageCause()).getDamager();
// Only interested in player kills
if (!(damager instanceof Player))
return;
Player player = (Player) damager;
DataManager.addEntry(new DataEntry(player, DataType.ENTITY_KILL, entity.getLocation(), Util.getEntityName(entity)));
}
}
}
use of org.bukkit.event.entity.EntityDamageByEntityEvent in project Denizen-For-Bukkit by DenizenScript.
the class EntityDamagedScriptEvent method onEntityDamaged.
@EventHandler
public void onEntityDamaged(EntityDamageEvent event) {
entity = new EntityTag(event.getEntity());
cause = new ElementTag(CoreUtilities.toLowerCase(event.getCause().name()));
damager = null;
projectile = null;
held = null;
if (event instanceof EntityDamageByEntityEvent) {
damager = new EntityTag(((EntityDamageByEntityEvent) event).getDamager());
if (damager.isProjectile()) {
projectile = damager;
if (damager.hasShooter()) {
damager = damager.getShooter();
}
}
if (damager != null) {
held = damager.getItemInHand();
if (held != null) {
held.setAmount(1);
}
}
}
this.event = event;
fire(event);
}
use of org.bukkit.event.entity.EntityDamageByEntityEvent in project Prism-Bukkit by prism.
the class DeathUtils method getCauseNiceName.
/**
* Returns the name of what caused an entity to die.
*
* @return String
*/
public static String getCauseNiceName(Entity entity) {
EntityDamageEvent e = entity.getLastDamageCause();
if (e == null) {
return "unknown";
}
// Determine the root cause
DamageCause damageCause = e.getCause();
Entity killer = null;
// If was damaged by an entity
if (entity.getLastDamageCause() instanceof EntityDamageByEntityEvent) {
EntityDamageByEntityEvent entityDamageByEntityEvent = (EntityDamageByEntityEvent) entity.getLastDamageCause();
// Arrow?
if (entityDamageByEntityEvent.getDamager() instanceof Arrow) {
Projectile arrow = (Arrow) entityDamageByEntityEvent.getDamager();
ProjectileSource source = arrow.getShooter();
if (source instanceof Player) {
killer = ((Player) source);
}
} else {
killer = entityDamageByEntityEvent.getDamager();
}
}
if (entity instanceof Player) {
Player player = (Player) entity;
// yourself with instant damage it doesn't show as suicide.
if (killer instanceof Player) {
// Themself
if (killer.getName().equals(player.getName())) {
return "suicide";
}
// translate bukkit events to nicer names
if ((damageCause.equals(DamageCause.ENTITY_ATTACK) || damageCause.equals(DamageCause.PROJECTILE))) {
return "pvp";
}
}
}
// Causes of death for either entities or players
if (damageCause.equals(DamageCause.ENTITY_ATTACK)) {
return "mob";
} else if (damageCause.equals(DamageCause.PROJECTILE)) {
return "skeleton";
} else if (damageCause.equals(DamageCause.ENTITY_EXPLOSION)) {
return "creeper";
} else if (damageCause.equals(DamageCause.CONTACT)) {
return "cactus";
} else if (damageCause.equals(DamageCause.BLOCK_EXPLOSION)) {
return "tnt";
} else if (damageCause.equals(DamageCause.FIRE) || damageCause.equals(DamageCause.FIRE_TICK)) {
return "fire";
} else if (damageCause.equals(DamageCause.MAGIC)) {
return "potion";
}
return damageCause.name().toLowerCase();
}
use of org.bukkit.event.entity.EntityDamageByEntityEvent in project xAuth by CypherX.
the class xAuthEntityListener method onEntityDamage.
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onEntityDamage(EntityDamageEvent event) {
Entity entity = event.getEntity();
if (entity instanceof Player && ((Player) entity).isOnline()) {
// player taking damage
xAuthPlayer xp = plyrMngr.getPlayer(((Player) entity).getName());
if (plyrMngr.isRestricted(xp, event) || plyrMngr.hasGodmode(xp, event.getCause()))
event.setCancelled(true);
}
if (event instanceof EntityDamageByEntityEvent) {
// player dealing damage to other entity
EntityDamageByEntityEvent edbeEvent = (EntityDamageByEntityEvent) event;
Entity damager = edbeEvent.getDamager();
if (damager instanceof Player) {
xAuthPlayer player = plyrMngr.getPlayer(((Player) damager).getName());
if (plyrMngr.isRestricted(player, edbeEvent)) {
plyrMngr.sendNotice(player);
event.setCancelled(true);
}
}
}
}
Aggregations