use of org.bukkit.event.entity.EntityDamageEvent in project Essentials by drtshock.
the class Commandsuicide method run.
@Override
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
final EntityDamageEvent ede = new EntityDamageEvent(user.getBase(), EntityDamageEvent.DamageCause.SUICIDE, Float.MAX_VALUE);
server.getPluginManager().callEvent(ede);
ede.getEntity().setLastDamageCause(ede);
user.getBase().setHealth(0);
user.sendMessage(tl("suicideMessage"));
user.setDisplayNick();
ess.broadcastMessage(user, tl("suicideSuccess", user.getDisplayName()));
}
use of org.bukkit.event.entity.EntityDamageEvent in project Plan by plan-player-analytics.
the class DeathEventListener method findWeapon.
public String findWeapon(Entity dead) {
EntityDamageEvent entityDamageEvent = dead.getLastDamageCause();
if (entityDamageEvent == null)
return "Unknown (No damage cause defined)";
Entity killer = ((EntityDamageByEntityEvent) entityDamageEvent).getDamager();
if (killer instanceof Player)
return getItemInHand((Player) killer);
if (killer instanceof Tameable)
return getPetType((Tameable) killer);
// Projectile, EnderCrystal and all other causes that are not known yet
return new EntityNameFormatter().apply(killer.getType().name());
}
use of org.bukkit.event.entity.EntityDamageEvent in project Plan by plan-player-analytics.
the class DeathEventListener method findKiller.
public Optional<Player> findKiller(Entity dead) {
EntityDamageEvent entityDamageEvent = dead.getLastDamageCause();
if (!(entityDamageEvent instanceof EntityDamageByEntityEvent)) {
// Not damaged by entity, can't be a player
return Optional.empty();
}
Entity killer = ((EntityDamageByEntityEvent) entityDamageEvent).getDamager();
if (killer instanceof Player)
return Optional.of((Player) killer);
if (killer instanceof Tameable)
return getOwner((Tameable) killer);
if (killer instanceof Projectile)
return getShooter((Projectile) killer);
// Recursive call
if (killer instanceof EnderCrystal)
return findKiller(killer);
return Optional.empty();
}
use of org.bukkit.event.entity.EntityDamageEvent in project RoseStacker by Rosewood-Development.
the class EntityListener method handleEntityDeath.
private void handleEntityDeath(EntityEvent event, LivingEntity entity, boolean useLastDamageCause) {
if (this.stackManager.isWorldDisabled(entity.getWorld()))
return;
if (!this.stackManager.isEntityStackingEnabled())
return;
StackedEntity stackedEntity = this.stackManager.getStackedEntity(entity);
if (stackedEntity == null)
return;
if (stackedEntity.getStackSize() == 1) {
this.stackManager.removeEntityStack(stackedEntity);
return;
}
// Should we kill the entire stack at once?
EntityDamageEvent lastDamageCause = entity.getLastDamageCause();
if (useLastDamageCause && (stackedEntity.getStackSettings().shouldKillEntireStackOnDeath() || (Setting.SPAWNER_DISABLE_MOB_AI_OPTIONS_KILL_ENTIRE_STACK_ON_DEATH.getBoolean() && PersistentDataUtils.isAiDisabled(entity)) || (lastDamageCause != null && Setting.ENTITY_KILL_ENTIRE_STACK_CONDITIONS.getStringList().stream().anyMatch(x -> x.equalsIgnoreCase(lastDamageCause.getCause().name()))) || (entity.getKiller() != null && entity.getKiller().hasPermission("rosestacker.killentirestack")))) {
if (Setting.ENTITY_DROP_ACCURATE_ITEMS.getBoolean()) {
if (entity instanceof Slime)
((Slime) entity).setSize(1);
if (event instanceof EntityDeathEvent) {
EntityDeathEvent deathEvent = (EntityDeathEvent) event;
stackedEntity.dropStackLoot(new ArrayList<>(deathEvent.getDrops()), deathEvent.getDroppedExp());
deathEvent.getDrops().clear();
} else {
stackedEntity.dropStackLoot(null, 0);
}
} else if (Setting.ENTITY_DROP_ACCURATE_EXP.getBoolean() && event instanceof EntityDeathEvent) {
EntityDeathEvent deathEvent = (EntityDeathEvent) event;
deathEvent.setDroppedExp(deathEvent.getDroppedExp() * stackedEntity.getStackSize());
}
Player killer = entity.getKiller();
if (killer != null && stackedEntity.getStackSize() - 1 > 0)
killer.incrementStatistic(Statistic.KILL_ENTITY, entity.getType(), stackedEntity.getStackSize() - 1);
this.stackManager.removeEntityStack(stackedEntity);
return;
}
// Decrease stack size by 1
stackedEntity.updateDisplay();
stackedEntity.decreaseStackSize();
stackedEntity.getEntity().setVelocity(new Vector());
if (Setting.ENTITY_KILL_TRANSFER_VELOCITY.getBoolean()) {
stackedEntity.getEntity().setVelocity(entity.getVelocity());
entity.setVelocity(new Vector());
}
if (!Setting.ENTITY_DISPLAY_CORPSE.getBoolean())
event.getEntity().remove();
}
use of org.bukkit.event.entity.EntityDamageEvent in project MagicPlugin by elBukkit.
the class EntityData method modifyDrops.
public void modifyDrops(EntityDeathEvent event) {
if (dropXp != null) {
event.setDroppedExp(dropXp);
}
List<ItemStack> dropList = event.getDrops();
if (!defaultDrops) {
dropList.clear();
}
if (dropsRequirePlayerKiller) {
EntityDamageEvent lastDamage = event.getEntity().getLastDamageCause();
if (!(lastDamage instanceof EntityDamageByEntityEvent))
return;
Entity damager = ((EntityDamageByEntityEvent) lastDamage).getDamager();
damager = controller.getDamageSource(damager);
if (!(damager instanceof Player) || damager == event.getEntity())
return;
}
if (drops != null) {
for (Deque<WeightedPair<String>> dropTable : drops) {
String key = RandomUtils.weightedRandom(dropTable);
if (key != null && !key.equalsIgnoreCase("none")) {
ItemStack item = controller.createItem(key);
if (item != null) {
dropList.add(item);
}
}
}
}
if (loot != null) {
ConfigurationSection processLoot = loot;
EntityDamageEvent lastDamage = event.getEntity().getLastDamageCause();
if (lastDamage instanceof EntityDamageByEntityEvent) {
Entity damager = ((EntityDamageByEntityEvent) lastDamage).getDamager();
damager = controller.getDamageSource(damager);
Mage mage = controller.getMage(damager);
processLoot = new MageParameters(mage, key + ".loot");
ConfigurationUtils.addConfigurations(processLoot, loot);
}
Set<String> keys = processLoot.getKeys(false);
for (String key : keys) {
int count = 1;
double probability;
ConfigurationSection config = processLoot.getConfigurationSection(key);
if (config != null) {
probability = config.getDouble("probability", 1);
count = config.getInt("count", 1);
} else {
probability = processLoot.getDouble(key);
}
if (!RandomUtils.checkProbability(probability))
continue;
ItemStack item = controller.createItem(key);
item.setAmount(count);
dropList.add(item);
}
}
}
Aggregations