Search in sources :

Example 1 with EntityDamageEvent

use of org.bukkit.event.entity.EntityDamageEvent in project Denizen-For-Bukkit by DenizenScript.

the class HurtCommand method execute.

@SuppressWarnings("unchecked")
@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
    List<dEntity> entities = (List<dEntity>) scriptEntry.getObject("entities");
    dEntity source = (dEntity) scriptEntry.getObject("source");
    Element amountElement = scriptEntry.getElement("amount");
    Element cause = scriptEntry.getElement("cause");
    dB.report(scriptEntry, getName(), amountElement.debug() + aH.debugList("entities", entities) + (cause == null ? "" : cause.debug()) + (source == null ? "" : source.debug()));
    double amount = amountElement.asDouble();
    for (dEntity entity : entities) {
        if (entity.getLivingEntity() == null) {
            dB.echoDebug(scriptEntry, entity + " is not a living entity!");
            continue;
        }
        if (cause == null) {
            if (source == null) {
                entity.getLivingEntity().damage(amount);
            } else {
                entity.getLivingEntity().damage(amount, source.getBukkitEntity());
            }
        } else {
            EntityDamageEvent ede = source == null ? new EntityDamageEvent(entity.getBukkitEntity(), EntityDamageEvent.DamageCause.valueOf(cause.asString().toUpperCase()), amount) : new EntityDamageByEntityEvent(source.getBukkitEntity(), entity.getBukkitEntity(), EntityDamageEvent.DamageCause.valueOf(cause.asString().toUpperCase()), amount);
            Bukkit.getPluginManager().callEvent(ede);
            if (!ede.isCancelled()) {
                if (source == null) {
                    entity.getLivingEntity().damage(ede.getFinalDamage());
                } else {
                    entity.getLivingEntity().damage(ede.getFinalDamage(), source.getBukkitEntity());
                }
            }
        }
    }
}
Also used : EntityDamageByEntityEvent(org.bukkit.event.entity.EntityDamageByEntityEvent) net.aufdemrand.denizen.objects.dEntity(net.aufdemrand.denizen.objects.dEntity) Element(net.aufdemrand.denizencore.objects.Element) ArrayList(java.util.ArrayList) List(java.util.List) net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList) EntityDamageEvent(org.bukkit.event.entity.EntityDamageEvent)

Example 2 with EntityDamageEvent

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 {
    EntityDamageEvent ede = new EntityDamageEvent(user.getBase(), EntityDamageEvent.DamageCause.SUICIDE, Short.MAX_VALUE);
    server.getPluginManager().callEvent(ede);
    ede.getEntity().setLastDamageCause(ede);
    user.getBase().damage(Short.MAX_VALUE);
    if (user.getBase().getHealth() > 0) {
        user.getBase().setHealth(0);
    }
    user.sendMessage(tl("suicideMessage"));
    user.setDisplayNick();
    ess.broadcastMessage(user, tl("suicideSuccess", user.getDisplayName()));
}
Also used : EntityDamageEvent(org.bukkit.event.entity.EntityDamageEvent)

Example 3 with EntityDamageEvent

use of org.bukkit.event.entity.EntityDamageEvent in project Essentials by drtshock.

the class Commandkill method updatePlayer.

@Override
protected void updatePlayer(final Server server, final CommandSource sender, final User user, final String[] args) throws PlayerExemptException {
    final Player matchPlayer = user.getBase();
    if (sender.isPlayer() && user.isAuthorized("essentials.kill.exempt") && !ess.getUser(sender.getPlayer()).isAuthorized("essentials.kill.force")) {
        throw new PlayerExemptException(tl("killExempt", matchPlayer.getDisplayName()));
    }
    final EntityDamageEvent ede = new EntityDamageEvent(matchPlayer, sender.isPlayer() && sender.getPlayer().getName().equals(matchPlayer.getName()) ? EntityDamageEvent.DamageCause.SUICIDE : EntityDamageEvent.DamageCause.CUSTOM, Short.MAX_VALUE);
    server.getPluginManager().callEvent(ede);
    if (ede.isCancelled() && sender.isPlayer() && !ess.getUser(sender.getPlayer()).isAuthorized("essentials.kill.force")) {
        return;
    }
    ede.getEntity().setLastDamageCause(ede);
    matchPlayer.damage(Short.MAX_VALUE);
    if (matchPlayer.getHealth() > 0) {
        matchPlayer.setHealth(0);
    }
    sender.sendMessage(tl("kill", matchPlayer.getDisplayName()));
}
Also used : Player(org.bukkit.entity.Player) EntityDamageEvent(org.bukkit.event.entity.EntityDamageEvent)

Example 4 with EntityDamageEvent

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

the class NoFall method dealFallDamage.

private void dealFallDamage(final Player player, final double damage) {
    if (mcAccess.getHandle().dealFallDamageFiresAnEvent().decide()) {
        // TODO: Better decideOptimistically?
        mcAccess.getHandle().dealFallDamage(player, damage);
    } else {
        final EntityDamageEvent event = BridgeHealth.getEntityDamageEvent(player, DamageCause.FALL, damage);
        Bukkit.getPluginManager().callEvent(event);
        if (!event.isCancelled()) {
            // TODO: account for no damage ticks etc.
            player.setLastDamageCause(event);
            mcAccess.getHandle().dealFallDamage(player, BridgeHealth.getRawDamage(event));
        }
    }
    // Currently resetting is done from within the damage event handler.
    // TODO: MUST detect if event fired at all (...) and override, if necessary. Best probe once per class (with YES).
    // data.clearNoFallData();
    player.setFallDistance(0);
}
Also used : EntityDamageEvent(org.bukkit.event.entity.EntityDamageEvent)

Example 5 with EntityDamageEvent

use of org.bukkit.event.entity.EntityDamageEvent in project Essentials by EssentialsX.

the class Commandkill method updatePlayer.

@Override
protected void updatePlayer(final Server server, final CommandSource sender, final User user, final String[] args) throws PlayerExemptException {
    final Player matchPlayer = user.getBase();
    if (sender.isPlayer() && user.isAuthorized("essentials.kill.exempt") && !ess.getUser(sender.getPlayer()).isAuthorized("essentials.kill.force")) {
        throw new PlayerExemptException(tl("killExempt", matchPlayer.getDisplayName()));
    }
    final EntityDamageEvent ede = new EntityDamageEvent(matchPlayer, sender.isPlayer() && sender.getPlayer().getName().equals(matchPlayer.getName()) ? EntityDamageEvent.DamageCause.SUICIDE : EntityDamageEvent.DamageCause.CUSTOM, Short.MAX_VALUE);
    server.getPluginManager().callEvent(ede);
    if (ede.isCancelled() && sender.isPlayer() && !ess.getUser(sender.getPlayer()).isAuthorized("essentials.kill.force")) {
        return;
    }
    ede.getEntity().setLastDamageCause(ede);
    matchPlayer.damage(Short.MAX_VALUE);
    if (matchPlayer.getHealth() > 0) {
        matchPlayer.setHealth(0);
    }
    sender.sendMessage(tl("kill", matchPlayer.getDisplayName()));
}
Also used : Player(org.bukkit.entity.Player) EntityDamageEvent(org.bukkit.event.entity.EntityDamageEvent)

Aggregations

EntityDamageEvent (org.bukkit.event.entity.EntityDamageEvent)28 EntityDamageByEntityEvent (org.bukkit.event.entity.EntityDamageByEntityEvent)12 Player (org.bukkit.entity.Player)9 Entity (org.bukkit.entity.Entity)8 LivingEntity (org.bukkit.entity.LivingEntity)8 Projectile (org.bukkit.entity.Projectile)6 EventHandler (org.bukkit.event.EventHandler)6 ItemStack (org.bukkit.inventory.ItemStack)3 ProjectileSource (org.bukkit.projectiles.ProjectileSource)3 EntityTag (com.denizenscript.denizen.objects.EntityTag)2 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)2 ArrayList (java.util.ArrayList)2 net.aufdemrand.denizen.objects.dEntity (net.aufdemrand.denizen.objects.dEntity)2 Element (net.aufdemrand.denizencore.objects.Element)2 net.aufdemrand.denizencore.objects.dList (net.aufdemrand.denizencore.objects.dList)2 DamageSource (net.minecraft.world.damagesource.DamageSource)2 net.minecraft.world.entity (net.minecraft.world.entity)2 org.bukkit.entity (org.bukkit.entity)2 Arrow (org.bukkit.entity.Arrow)2 Tameable (org.bukkit.entity.Tameable)2