Search in sources :

Example 66 with EntityDamageEvent

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);
    }
}
Also used : Metrics(com.wbm.plugin.util.Metrics) BlockData(org.bukkit.block.data.BlockData) Entity(org.bukkit.entity.Entity) Event(org.bukkit.event.Event) Sound(org.bukkit.Sound) Player(org.bukkit.entity.Player) SoloBattleMiniGame(com.worldbiomusic.minigameworld.minigameframes.SoloBattleMiniGame) LocationTool(com.wbm.plugin.util.LocationTool) AllMiniGamesMain(com.worldbiomusic.allgames.AllMiniGamesMain) ArrayList(java.util.ArrayList) EventHandler(org.bukkit.event.EventHandler) List(java.util.List) EntityChangeBlockEvent(org.bukkit.event.entity.EntityChangeBlockEvent) Location(org.bukkit.Location) Map(java.util.Map) SoundTool(com.wbm.plugin.util.SoundTool) ChatColor(org.bukkit.ChatColor) Material(org.bukkit.Material) EntityDamageByEntityEvent(org.bukkit.event.entity.EntityDamageByEntityEvent) EntityDamageEvent(org.bukkit.event.entity.EntityDamageEvent) Option(com.worldbiomusic.minigameworld.minigameframes.helpers.MiniGameCustomOption.Option) Bukkit(org.bukkit.Bukkit) Listener(org.bukkit.event.Listener) DamageCause(org.bukkit.event.entity.EntityDamageEvent.DamageCause) Entity(org.bukkit.entity.Entity) Player(org.bukkit.entity.Player) EntityDamageByEntityEvent(org.bukkit.event.entity.EntityDamageByEntityEvent)

Example 67 with EntityDamageEvent

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();
        }
    }
}
Also used : ProjectileHitEvent(org.bukkit.event.entity.ProjectileHitEvent) Entity(org.bukkit.entity.Entity) Player(org.bukkit.entity.Player) EntityDeathEvent(org.bukkit.event.entity.EntityDeathEvent) ProjectileLaunchEvent(org.bukkit.event.entity.ProjectileLaunchEvent) ProjectileSource(org.bukkit.projectiles.ProjectileSource) ItemStack(org.bukkit.inventory.ItemStack) Projectile(org.bukkit.entity.Projectile) EntityDamageEvent(org.bukkit.event.entity.EntityDamageEvent)

Example 68 with EntityDamageEvent

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();
        }
    }
}
Also used : Entity(org.bukkit.entity.Entity) Player(org.bukkit.entity.Player) EntityDamageByEntityEvent(org.bukkit.event.entity.EntityDamageByEntityEvent) EntityDeathEvent(org.bukkit.event.entity.EntityDeathEvent) EntityDamageEvent(org.bukkit.event.entity.EntityDamageEvent)

Example 69 with EntityDamageEvent

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);
        }
    }
}
Also used : Timespan(ch.njol.skript.util.Timespan) Entity(org.bukkit.entity.Entity) EntityCombustEvent(org.bukkit.event.entity.EntityCombustEvent) EntityDamageEvent(org.bukkit.event.entity.EntityDamageEvent)

Example 70 with EntityDamageEvent

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);
}
Also used : EntityDamageByEntityEvent(org.bukkit.event.entity.EntityDamageByEntityEvent) EntityDamageEvent(org.bukkit.event.entity.EntityDamageEvent)

Aggregations

EntityDamageEvent (org.bukkit.event.entity.EntityDamageEvent)109 Player (org.bukkit.entity.Player)43 EntityDamageByEntityEvent (org.bukkit.event.entity.EntityDamageByEntityEvent)40 Entity (org.bukkit.entity.Entity)30 LivingEntity (org.bukkit.entity.LivingEntity)25 EventHandler (org.bukkit.event.EventHandler)24 Projectile (org.bukkit.entity.Projectile)15 ItemStack (org.bukkit.inventory.ItemStack)13 Test (org.junit.Test)11 Function (com.google.common.base.Function)8 ProjectileSource (org.bukkit.projectiles.ProjectileSource)8 Location (org.bukkit.Location)7 EntityDamageByBlockEvent (org.bukkit.event.entity.EntityDamageByBlockEvent)7 DamageCause (org.bukkit.event.entity.EntityDamageEvent.DamageCause)7 EntityDeathEvent (org.bukkit.event.entity.EntityDeathEvent)7 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)7 ArrayList (java.util.ArrayList)6 List (java.util.List)6 World (org.bukkit.World)6 Block (org.bukkit.block.Block)6