use of org.bukkit.event.entity.EntityDamageEvent in project AllMiniGames by MiniGameWorlds.
the class DodgeBlock method killPlayer.
private void killPlayer(EntityDamageEvent e) {
if (e.getCause() == DamageCause.FALLING_BLOCK) {
if (!(e instanceof EntityDamageByEntityEvent)) {
return;
}
EntityDamageByEntityEvent event = (EntityDamageByEntityEvent) e;
Entity fallingBlock = event.getDamager();
if (this.fallingBlocks.contains(fallingBlock)) {
Player p = (Player) e.getEntity();
// give score to others
getLivePlayers().stream().filter(all -> !all.equals(p)).forEach(all -> plusScore(all, 1));
// message, sound
sendMessages(p.getName() + ChatColor.RED + " died");
sendTitle(p, ChatColor.RED + "DIE", "");
SoundTool.play(getPlayers(), Sound.BLOCK_NOTE_BLOCK_CHIME);
// live false
setLive(p, false);
}
} else {
e.setDamage(0);
}
}
use of org.bukkit.event.entity.EntityDamageEvent in project AllMiniGames by MiniGameWorlds.
the class TeamTiny method onEvent.
@Override
protected void onEvent(Event event) {
if (event instanceof ProjectileHitEvent) {
ProjectileHitEvent e = (ProjectileHitEvent) event;
Entity hitEntity = e.getHitEntity();
if (hitEntity != null && hitEntity.equals(this.entity)) {
// event detector can detect shooter from ProjectileHitEvent
plusTeamScore(1);
// sound
SoundTool.play(getPlayers(), Sound.BLOCK_NOTE_BLOCK_CHIME);
// particle
spawnHitParticles(hitEntity);
}
} else if (event instanceof ProjectileLaunchEvent) {
ProjectileLaunchEvent e = (ProjectileLaunchEvent) event;
Projectile proj = e.getEntity();
ProjectileSource shooterEntity = proj.getShooter();
// event detector can detect player from ProjectileLaunchEvent
Player shooter = (Player) shooterEntity;
// don't change amount of snowball
shooter.getInventory().addItem(new ItemStack(Material.SNOWBALL));
// give cooldown
shooter.setCooldown(Material.SNOWBALL, (int) (20 * this.shootDelay));
} else if (event instanceof EntityDamageEvent) {
EntityDamageEvent e = (EntityDamageEvent) event;
if (e.getEntity().equals(this.entity)) {
e.setDamage(0);
}
} else if (event instanceof EntityDeathEvent) {
EntityDeathEvent e = (EntityDeathEvent) event;
if (e.getEntity().equals(this.entity)) {
summonEntity();
}
}
}
use of org.bukkit.event.entity.EntityDamageEvent in project AllMiniGames by MiniGameWorlds.
the class HitMob method onEvent.
@Override
protected void onEvent(Event event) {
if (event instanceof EntityDamageEvent) {
EntityDamageEvent damageEvent = (EntityDamageEvent) event;
Entity entity = damageEvent.getEntity();
// if player dead
if (entity instanceof Player) {
Player p = (Player) entity;
if (p.getHealth() <= damageEvent.getDamage()) {
finishGame();
}
}
if (entity.equals(this.mob)) {
if (event instanceof EntityDamageByEntityEvent) {
EntityDamageByEntityEvent e = (EntityDamageByEntityEvent) event;
int damage = (int) e.getDamage();
// event detector can detect EntityDamageByEntityEvent if damager is a player or
// a shooter of projectile
plusScore(damage);
// title
sendTitles("" + ChatColor.GREEN + damage, "damage");
}
// cancel damage dealt to the mob
damageEvent.setDamage(0);
}
} else if (event instanceof EntityDeathEvent) {
EntityDeathEvent e = (EntityDeathEvent) event;
if (this.mob.equals(e.getEntity())) {
spawnMob();
}
}
}
use of org.bukkit.event.entity.EntityDamageEvent in project Skript by SkriptLang.
the class EffIgnite method execute.
@Override
protected void execute(final Event e) {
final int d;
if (duration != null) {
final Timespan t = duration.getSingle(e);
if (t == null)
return;
d = (int) (t.getTicks_i() >= Integer.MAX_VALUE ? Integer.MAX_VALUE : t.getTicks_i());
} else {
d = ignite ? DEFAULT_DURATION : 0;
}
for (final Entity en : entities.getArray(e)) {
if (e instanceof EntityDamageEvent && ((EntityDamageEvent) e).getEntity() == en && !Delay.isDelayed(e)) {
Bukkit.getScheduler().scheduleSyncDelayedTask(Skript.getInstance(), new Runnable() {
@Override
public void run() {
en.setFireTicks(d);
}
});
} else {
if (e instanceof EntityCombustEvent && ((EntityCombustEvent) e).getEntity() == en && !Delay.isDelayed(e))
// can't change the duration, thus simply cancel the event (and create a new one)
((EntityCombustEvent) e).setCancelled(true);
en.setFireTicks(d);
}
}
}
use of org.bukkit.event.entity.EntityDamageEvent in project McRPG by Eunoians.
the class MobHealthbarUtils method fixDeathMessage.
/**
* Fix issues with death messages caused by the mob healthbars.
*
* @param deathMessage The original death message
* @param player The player who died
* @return the fixed death message
*/
public static String fixDeathMessage(String deathMessage, Player player) {
EntityDamageEvent lastDamageCause = player.getLastDamageCause();
String replaceString = lastDamageCause instanceof EntityDamageByEntityEvent ? StringUtils.getPrettyEntityTypeString(((EntityDamageByEntityEvent) lastDamageCause).getDamager().getType()) : "a mob";
return deathMessage.replaceAll("(?:(\u00A7(?:[0-9A-FK-ORa-fk-or]))*(?:[\u2764\u25A0]{1,10})){1,2}", replaceString);
}
Aggregations