use of org.bukkit.event.entity.EntityDeathEvent in project Village_Defense by Plajer.
the class PlayerBuster method damageEntity.
@Override
public boolean damageEntity(DamageSource damagesource, float f) {
if (damagesource != null && damagesource.getEntity() != null && damagesource.getEntity().getBukkitEntity().getType() == EntityType.PLAYER) {
ItemStack[] itemStack = new ItemStack[] { new ItemStack(Material.ROTTEN_FLESH) };
Bukkit.getServer().getPluginManager().callEvent(new EntityDeathEvent((LivingEntity) this.getBukkitEntity(), Arrays.asList(itemStack), expToDrop));
Player player = (Player) damagesource.getEntity().getBukkitEntity();
org.bukkit.entity.Entity primed = getBukkitEntity().getWorld().spawnEntity(getBukkitEntity().getLocation(), EntityType.PRIMED_TNT);
this.die();
return true;
} else {
super.damageEntity(damagesource, f);
return false;
}
}
use of org.bukkit.event.entity.EntityDeathEvent in project Village_Defense by Plajer.
the class GolemBuster method damageEntity.
@Override
public boolean damageEntity(DamageSource damagesource, float f) {
if (damagesource != null && damagesource.getEntity() != null && damagesource.getEntity().getBukkitEntity().getType() == EntityType.IRON_GOLEM) {
this.die();
this.die();
ItemStack[] itemStack = new ItemStack[] { new ItemStack(Material.ROTTEN_FLESH) };
Bukkit.getServer().getPluginManager().callEvent(new EntityDeathEvent((LivingEntity) this.getBukkitEntity(), Arrays.asList(itemStack), expToDrop));
IronGolem golem = (IronGolem) damagesource.getEntity().getBukkitEntity();
golem.getWorld().spawnEntity(golem.getLocation(), EntityType.PRIMED_TNT);
return true;
} else {
super.damageEntity(damagesource, f);
return false;
}
}
use of org.bukkit.event.entity.EntityDeathEvent in project Village_Defense by Plajer.
the class GolemBuster method damageEntity.
@Override
public boolean damageEntity(DamageSource damagesource, float f) {
if (damagesource != null && damagesource.getEntity() != null && damagesource.getEntity().getBukkitEntity().getType() == EntityType.IRON_GOLEM) {
this.die();
this.die();
org.bukkit.inventory.ItemStack[] itemStack = new org.bukkit.inventory.ItemStack[] { new org.bukkit.inventory.ItemStack(org.bukkit.Material.ROTTEN_FLESH) };
Bukkit.getServer().getPluginManager().callEvent(new EntityDeathEvent((LivingEntity) this.getBukkitEntity(), Arrays.asList(itemStack), expToDrop));
IronGolem golem = (IronGolem) damagesource.getEntity().getBukkitEntity();
// golem.getWorld().createExplosion(golem.getLocation(), 4);
org.bukkit.entity.Entity primed = golem.getWorld().spawnEntity(golem.getLocation(), EntityType.PRIMED_TNT);
return true;
} else {
super.damageEntity(damagesource, f);
return false;
}
}
use of org.bukkit.event.entity.EntityDeathEvent in project Village_Defense by Plajer.
the class PlayerBuster method damageEntity.
@Override
public boolean damageEntity(DamageSource damagesource, float f) {
if (damagesource != null && damagesource.getEntity() != null && damagesource.getEntity().getBukkitEntity().getType() == EntityType.PLAYER) {
ItemStack[] itemStack = new ItemStack[] { new ItemStack(Material.ROTTEN_FLESH) };
Bukkit.getServer().getPluginManager().callEvent(new EntityDeathEvent((LivingEntity) this.getBukkitEntity(), Arrays.asList(itemStack), expToDrop));
Player player = (Player) damagesource.getEntity().getBukkitEntity();
org.bukkit.entity.Entity primed = getBukkitEntity().getWorld().spawnEntity(getBukkitEntity().getLocation(), EntityType.PRIMED_TNT);
this.die();
return true;
} else {
super.damageEntity(damagesource, f);
return false;
}
}
use of org.bukkit.event.entity.EntityDeathEvent in project Glowstone by GlowstoneMC.
the class GlowLivingEntity method setHealth.
// //////////////////////////////////////////////////////////////////////////
// Health
@Override
public void setHealth(double health) {
if (health < 0) {
health = 0;
}
if (health > getMaxHealth()) {
health = getMaxHealth();
}
this.health = health;
metadata.set(MetadataIndex.HEALTH, (float) health);
for (Objective objective : getServer().getScoreboardManager().getMainScoreboard().getObjectivesByCriteria(Criterias.HEALTH)) {
objective.getScore(getName()).setScore((int) health);
}
if (health > 0) {
return;
}
if (this.tryUseTotem()) {
return;
}
// Killed
active = false;
Sound deathSound = getDeathSound();
if (deathSound != null && !isSilent()) {
world.playSound(location, deathSound, getSoundVolume(), getSoundPitch());
}
playEffectKnownAndSelf(EntityEffect.DEATH);
if (this instanceof GlowPlayer) {
GlowPlayer player = (GlowPlayer) this;
List<ItemStack> items = null;
boolean dropInventory = !world.getGameRuleMap().getBoolean(GameRules.KEEP_INVENTORY);
if (dropInventory) {
items = Arrays.stream(player.getInventory().getContents()).filter(stack -> !InventoryUtil.isEmpty(stack)).collect(Collectors.toList());
player.getInventory().clear();
}
PlayerDeathEvent event = new PlayerDeathEvent(player, items, 0, player.getDisplayName() + " died.");
EventFactory.getInstance().callEvent(event);
server.broadcastMessage(event.getDeathMessage());
if (dropInventory) {
for (ItemStack item : items) {
world.dropItemNaturally(getLocation(), item);
}
}
player.setShoulderEntityRight(null);
player.setShoulderEntityLeft(null);
player.incrementStatistic(Statistic.DEATHS);
} else {
EntityDeathEvent deathEvent = new EntityDeathEvent(this, new ArrayList<>());
if (world.getGameRuleMap().getBoolean(GameRules.DO_MOB_LOOT)) {
LootData data = LootingManager.generate(this);
deathEvent.getDrops().addAll(data.getItems());
// Only drop experience when hit by a player within 5 seconds (100 game ticks)
if (ticksLived - playerDamageTick <= 100 && data.getExperience() > 0) {
ThreadLocalRandom random = ThreadLocalRandom.current();
ExperienceSplitter.forEachCut(data.getExperience(), exp -> {
double modX = random.nextDouble() - 0.5;
double modZ = random.nextDouble() - 0.5;
Location xpLocation = new Location(world, location.getBlockX() + 0.5 + modX, location.getY(), location.getBlockZ() + 0.5 + modZ);
GlowExperienceOrb orb = (GlowExperienceOrb) world.spawnEntity(xpLocation, EntityType.EXPERIENCE_ORB);
orb.setExperience(exp);
orb.setSourceEntityId(this.getUniqueId());
if (getLastDamager() != null) {
orb.setTriggerEntityId(getLastDamager().getUniqueId());
}
});
}
}
deathEvent = EventFactory.getInstance().callEvent(deathEvent);
for (ItemStack item : deathEvent.getDrops()) {
world.dropItemNaturally(getLocation(), item);
}
}
// to help keep code maintainable
if (this instanceof GlowSlime) {
GlowSlime slime = (GlowSlime) this;
int size = slime.getSize();
if (size > 1) {
int count = 2 + ThreadLocalRandom.current().nextInt(3);
SlimeSplitEvent event = EventFactory.getInstance().callEvent(new SlimeSplitEvent(slime, count));
if (event.isCancelled() || event.getCount() <= 0) {
return;
}
count = event.getCount();
for (int i = 0; i < count; ++i) {
Location spawnLoc = getLocation().clone();
spawnLoc.add(ThreadLocalRandom.current().nextDouble(0.5, 3), 0, ThreadLocalRandom.current().nextDouble(0.5, 3));
GlowSlime splitSlime = (GlowSlime) world.spawnEntity(spawnLoc, EntityType.SLIME);
// Make the split slime the same name as the killed slime.
if (getCustomName() != null && !getCustomName().isEmpty()) {
splitSlime.setCustomName(getCustomName());
}
splitSlime.setSize(size / 2);
}
}
}
}
Aggregations