Search in sources :

Example 46 with EntityDamageEvent

use of org.bukkit.event.entity.EntityDamageEvent in project AllMiniGames by MiniGameWorlds.

the class Dropper method onEvent.

@Override
protected void onEvent(Event event) {
    if (event instanceof EntityDamageEvent) {
        EntityDamageEvent e = (EntityDamageEvent) event;
        Player p = (Player) e.getEntity();
        boolean isDead = p.getHealth() <= e.getDamage();
        if (isDead) {
            e.setDamage(0);
            PlayerTool.makePureState(p);
            if (!checkBelowBlock(p)) {
                // respawn
                p.teleport(getLocation());
            }
        }
    }
}
Also used : Player(org.bukkit.entity.Player) EntityDamageEvent(org.bukkit.event.entity.EntityDamageEvent)

Example 47 with EntityDamageEvent

use of org.bukkit.event.entity.EntityDamageEvent in project AllMiniGames by MiniGameWorlds.

the class LavaUp method onEvent.

@Override
protected void onEvent(Event event) {
    if (event instanceof EntityDamageEvent) {
        EntityDamageEvent damageEvent = (EntityDamageEvent) event;
        checkPlayerIsDead(damageEvent);
        if (damageEvent instanceof EntityDamageByEntityEvent) {
            cancelPlayerHitDamage((EntityDamageByEntityEvent) damageEvent);
        }
    }
}
Also used : EntityDamageByEntityEvent(org.bukkit.event.entity.EntityDamageByEntityEvent) EntityDamageEvent(org.bukkit.event.entity.EntityDamageEvent)

Example 48 with EntityDamageEvent

use of org.bukkit.event.entity.EntityDamageEvent in project Bukkit by Bukkit.

the class KillCommand method execute.

@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
    if (!testPermission(sender))
        return true;
    if (sender instanceof Player) {
        Player player = (Player) sender;
        EntityDamageEvent ede = new EntityDamageEvent(player, EntityDamageEvent.DamageCause.SUICIDE, 1000);
        Bukkit.getPluginManager().callEvent(ede);
        if (ede.isCancelled())
            return true;
        ede.getEntity().setLastDamageCause(ede);
        player.setHealth(0);
        sender.sendMessage("Ouch. That look like it hurt.");
    } else {
        sender.sendMessage("You can only perform this command as a player");
    }
    return true;
}
Also used : Player(org.bukkit.entity.Player) EntityDamageEvent(org.bukkit.event.entity.EntityDamageEvent)

Example 49 with EntityDamageEvent

use of org.bukkit.event.entity.EntityDamageEvent in project Glowstone by GlowstoneMC.

the class GlowLivingEntity method damage.

@Override
public void damage(double amount, Entity source, @NotNull DamageCause cause) {
    // invincibility timer
    if (noDamageTicks > 0 || health <= 0 || !canTakeDamage(cause) || isInvulnerable()) {
        return;
    } else {
        noDamageTicks = maximumNoDamageTicks;
    }
    // fire resistance
    if (hasPotionEffect(PotionEffectType.FIRE_RESISTANCE)) {
        if (source instanceof Fireball) {
            return;
        } else {
            switch(cause) {
                case FIRE:
                case FIRE_TICK:
                case HOT_FLOOR:
                case LAVA:
                    return;
                default:
            }
        }
    }
    // armor damage protection
    // formula source: http://minecraft.gamepedia.com/Armor#Damage_Protection
    double defensePoints = getAttributeManager().getPropertyValue(Key.KEY_ARMOR);
    double toughness = getAttributeManager().getPropertyValue(Key.KEY_ARMOR_TOUGHNESS);
    amount = amount * (1 - Math.min(20.0, Math.max(defensePoints / 5.0, defensePoints - amount / (2.0 + toughness / 4.0))) / 25);
    // fire event
    EntityDamageEvent event = EventFactory.getInstance().onEntityDamage(source == null ? new EntityDamageEvent(this, cause, amount) : new EntityDamageByEntityEvent(source, this, cause, amount));
    if (event.isCancelled()) {
        return;
    }
    // apply damage
    amount = event.getFinalDamage();
    lastDamage = amount;
    if (isPlayerHit(source)) {
        playerDamageTick = ticksLived;
        if (health - amount <= 0) {
            killer = determinePlayer(source);
            if (killer != null) {
                killer.incrementStatistic(Statistic.KILL_ENTITY, getType());
            }
        }
    }
    setHealth(health - amount);
    playEffectKnownAndSelf(EntityEffect.HURT);
    if (cause == DamageCause.ENTITY_ATTACK && source != null) {
        Vector distance = RayUtil.getRayBetween(getLocation(), ((LivingEntity) source).getEyeLocation());
        Vector rayLength = RayUtil.getVelocityRay(distance).normalize();
        Vector currentVelocity = getVelocity();
        currentVelocity.add(rayLength.multiply(((amount + 1) / 2d)));
        setVelocity(currentVelocity);
    }
    // play sounds, handle death
    if (health > 0) {
        Sound hurtSound = getHurtSound();
        if (hurtSound != null && !isSilent()) {
            world.playSound(location, hurtSound, getSoundVolume(), getSoundPitch());
        }
    }
    setLastDamager(source);
}
Also used : Fireball(org.bukkit.entity.Fireball) EntityDamageByEntityEvent(org.bukkit.event.entity.EntityDamageByEntityEvent) Sound(org.bukkit.Sound) Vector(org.bukkit.util.Vector) EntityDamageEvent(org.bukkit.event.entity.EntityDamageEvent)

Example 50 with EntityDamageEvent

use of org.bukkit.event.entity.EntityDamageEvent in project MyMaid2 by jaoafa.

the class Event_CommandBlockVariable method onCommandBlockCall.

@EventHandler
public void onCommandBlockCall(ServerCommandEvent event) {
    if (!(event.getSender() instanceof BlockCommandSender))
        return;
    BlockCommandSender sender = (BlockCommandSender) event.getSender();
    if (sender.getBlock() == null || !(sender.getBlock().getState() instanceof CommandBlock))
        return;
    CommandBlock cmdb = (CommandBlock) sender.getBlock().getState();
    String command = cmdb.getCommand();
    // 最初に$が入ってたら変数入りコマンド
    if (!command.startsWith("$"))
        return;
    // $を消す
    command = StringUtils.stripStart(command, "$");
    // /を消す
    command = StringUtils.stripStart(command, "/");
    // 「@p」のみ置き換える動作をする
    if (sender instanceof Player) {
        Player player = (Player) sender;
        NearestPlayer npr = new NearestPlayer(player.getLocation());
        if (npr.getStatus()) {
            command = command.replaceAll("@" + "p" + "", npr.getPlayer().getName());
        }
    } else if (sender instanceof BlockCommandSender) {
        NearestPlayer npr = new NearestPlayer(cmdb.getBlock().getLocation());
        if (npr.getStatus()) {
            command = command.replaceAll("@" + "p" + "", npr.getPlayer().getName());
        }
    }
    // ----- 事前定義(予約済み変数) ----- //
    SimpleDateFormat sdf_Year = new SimpleDateFormat("yyyy");
    command = command.replaceAll("\\$" + "DateTime_Year" + "\\$", sdf_Year.format(new Date()));
    SimpleDateFormat sdf_Month = new SimpleDateFormat("MM");
    command = command.replaceAll("\\$" + "DateTime_Month" + "\\$", sdf_Month.format(new Date()));
    SimpleDateFormat sdf_Day = new SimpleDateFormat("dd");
    command = command.replaceAll("\\$" + "DateTime_Day" + "\\$", sdf_Day.format(new Date()));
    SimpleDateFormat sdf_Hour = new SimpleDateFormat("HH");
    command = command.replaceAll("\\$" + "DateTime_Hour" + "\\$", sdf_Hour.format(new Date()));
    SimpleDateFormat sdf_Minute = new SimpleDateFormat("mm");
    command = command.replaceAll("\\$" + "DateTime_Minute" + "\\$", sdf_Minute.format(new Date()));
    SimpleDateFormat sdf_Second = new SimpleDateFormat("ss");
    command = command.replaceAll("\\$" + "DateTime_Second" + "\\$", sdf_Second.format(new Date()));
    command = command.replaceAll("\\$" + "PlayerCount" + "\\$", String.valueOf(Bukkit.getServer().getOnlinePlayers().size()));
    for (Player p : Bukkit.getOnlinePlayers()) {
        if (!command.contains("$" + "Damager_" + p.getName() + "$")) {
            continue;
        }
        EntityDamageEvent ede = p.getLastDamageCause();
        if (ede == null) {
            continue;
        }
        Entity e = ede.getEntity();
        if (e == null) {
            continue;
        }
        String name = e.getName();
        command = command.replaceAll("\\$" + "Damager_" + p.getName() + "\\$", name);
    }
    ScoreboardManager sbm = Bukkit.getScoreboardManager();
    Scoreboard sb = sbm.getMainScoreboard();
    for (Objective obj : sb.getObjectives()) {
        String regex = "\\$Score_" + obj.getName() + "_(.+?)\\$";
        Pattern p = Pattern.compile(regex);
        Matcher m = p.matcher(command);
        while (m.find()) {
            Score i = obj.getScore(m.group(1));
            if (i == null) {
                continue;
            }
            command = command.replaceAll("\\$" + "Score_" + obj.getName() + "_" + m.group(1) + "\\$", "" + i.getScore());
        }
    }
    // ----- 事前定義(予約済み変数) ----- //
    Map<String, String> map = MyMaidVariable.listALL();
    for (Map.Entry<String, String> e : map.entrySet()) {
        command = command.replaceAll("\\$" + e.getKey() + "\\$", e.getValue());
    }
    Bukkit.dispatchCommand(sender, command);
}
Also used : Entity(org.bukkit.entity.Entity) Pattern(java.util.regex.Pattern) Player(org.bukkit.entity.Player) NearestPlayer(com.jaoafa.MyMaid2.Lib.NearestPlayer) NearestPlayer(com.jaoafa.MyMaid2.Lib.NearestPlayer) Matcher(java.util.regex.Matcher) CommandBlock(org.bukkit.block.CommandBlock) Date(java.util.Date) Objective(org.bukkit.scoreboard.Objective) Score(org.bukkit.scoreboard.Score) Scoreboard(org.bukkit.scoreboard.Scoreboard) ScoreboardManager(org.bukkit.scoreboard.ScoreboardManager) SimpleDateFormat(java.text.SimpleDateFormat) Map(java.util.Map) BlockCommandSender(org.bukkit.command.BlockCommandSender) EntityDamageEvent(org.bukkit.event.entity.EntityDamageEvent) EventHandler(org.bukkit.event.EventHandler)

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