Search in sources :

Example 6 with DamageSource

use of net.minecraft.server.v1_11_R1.DamageSource in project PaperDev by Kamillaova.

the class CraftLivingEntity method damage.

public void damage(double amount, org.bukkit.entity.Entity source) {
    DamageSource reason = DamageSource.GENERIC;
    if (source instanceof HumanEntity) {
        reason = DamageSource.playerAttack(((CraftHumanEntity) source).getHandle());
    } else if (source instanceof LivingEntity) {
        reason = DamageSource.mobAttack(((CraftLivingEntity) source).getHandle());
    }
    entity.damageEntity(reason, (float) amount);
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) DamageSource(net.minecraft.server.v1_12_R1.DamageSource) HumanEntity(org.bukkit.entity.HumanEntity)

Example 7 with DamageSource

use of net.minecraft.server.v1_11_R1.DamageSource 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;
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) EntityDeathEvent(org.bukkit.event.entity.EntityDeathEvent) IronGolem(org.bukkit.entity.IronGolem) EntityIronGolem(net.minecraft.server.v1_11_R1.EntityIronGolem)

Example 8 with DamageSource

use of net.minecraft.server.v1_11_R1.DamageSource 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;
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) PathfinderGoalLookAtPlayer(net.minecraft.server.v1_11_R1.PathfinderGoalLookAtPlayer) EntityDeathEvent(org.bukkit.event.entity.EntityDeathEvent) ItemStack(org.bukkit.inventory.ItemStack)

Example 9 with DamageSource

use of net.minecraft.server.v1_11_R1.DamageSource in project solinia3-core by mixxit.

the class EntityUtils method PSetHPChange.

public static void PSetHPChange(LivingEntity targetToDamage, Double hpchange, LivingEntity sourceEntityOfChange, boolean playHurtSound) {
    if (targetToDamage instanceof ArmorStand || sourceEntityOfChange instanceof ArmorStand)
        return;
    if (hpchange == 0)
        return;
    // This will check both their invulnerability from minecraft and godmode from essentials
    if (hpchange < 0 && EntityUtils.IsInvulnerable(targetToDamage))
        return;
    float cur_hp = ((EntityLiving) ((CraftLivingEntity) targetToDamage).getHandle()).getHealth();
    float max_hp = ((EntityLiving) ((CraftLivingEntity) targetToDamage).getHandle()).getMaxHealth();
    float hp = cur_hp + hpchange.floatValue();
    if (hp >= max_hp)
        cur_hp = max_hp;
    else
        cur_hp = hp;
    ((EntityLiving) ((CraftLivingEntity) targetToDamage).getHandle()).setHealth(cur_hp);
    float soundVolume = 1.0F;
    if (hpchange < 0) {
        DamageSource damagesource = net.minecraft.server.v1_15_R1.DamageSource.mobAttack(((EntityLiving) ((CraftLivingEntity) sourceEntityOfChange).getHandle()));
        DamageCause damagecause = DamageCause.ENTITY_ATTACK;
        EntityDamageByEntityEvent event = new EntityDamageByEntityEvent(sourceEntityOfChange, targetToDamage, damagecause, hpchange);
        ((CraftLivingEntity) targetToDamage).setLastDamage(hpchange.doubleValue());
        ((CraftLivingEntity) targetToDamage).setLastDamageCause(event);
        ((CraftLivingEntity) targetToDamage).setNoDamageTicks(20);
        ((EntityLiving) ((CraftLivingEntity) targetToDamage).getHandle()).hurtDuration = 10;
        ((EntityLiving) ((CraftLivingEntity) targetToDamage).getHandle()).hurtTicks = ((EntityLiving) ((CraftLivingEntity) targetToDamage).getHandle()).hurtDuration;
        ((EntityLiving) ((CraftLivingEntity) targetToDamage).getHandle()).getCombatTracker().trackDamage(damagesource, cur_hp, hpchange.floatValue());
        if (((EntityLiving) ((CraftLivingEntity) targetToDamage).getHandle()).getHealth() <= 0.0F) {
            targetToDamage.getWorld().playSound(targetToDamage.getLocation(), Sound.ENTITY_GENERIC_DEATH, soundVolume, GetSoundPitch(((EntityLiving) ((CraftLivingEntity) targetToDamage).getHandle())));
            ((EntityLiving) ((CraftLivingEntity) targetToDamage).getHandle()).die(damagesource);
        } else {
            if (targetToDamage instanceof Player) {
                PacketPlayOutAnimation packet = new PacketPlayOutAnimation(((CraftPlayer) targetToDamage).getHandle(), 1);
                ((CraftPlayer) targetToDamage).getHandle().playerConnection.sendPacket(packet);
            }
            if (playHurtSound)
                targetToDamage.getWorld().playSound(targetToDamage.getLocation(), Sound.ENTITY_GENERIC_HURT, soundVolume, GetSoundPitch(((EntityLiving) ((CraftLivingEntity) targetToDamage).getHandle())));
        }
    }
}
Also used : Player(org.bukkit.entity.Player) CraftPlayer(org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer) EntityPlayer(net.minecraft.server.v1_15_R1.EntityPlayer) ArmorStand(org.bukkit.entity.ArmorStand) EntityLiving(net.minecraft.server.v1_15_R1.EntityLiving) DamageSource(net.minecraft.server.v1_15_R1.DamageSource) EntityDamageByEntityEvent(org.bukkit.event.entity.EntityDamageByEntityEvent) CraftLivingEntity(org.bukkit.craftbukkit.v1_15_R1.entity.CraftLivingEntity) CraftPlayer(org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer) DamageCause(org.bukkit.event.entity.EntityDamageEvent.DamageCause) PacketPlayOutAnimation(net.minecraft.server.v1_15_R1.PacketPlayOutAnimation)

Example 10 with DamageSource

use of net.minecraft.server.v1_11_R1.DamageSource in project MechanicsMain by WeaponMechanics.

the class v1_16_R3 method logDamage.

@Override
public void logDamage(LivingEntity victim, LivingEntity source, double health, double damage, boolean isMelee) {
    DamageSource damageSource;
    if (isMelee) {
        if (source instanceof Player) {
            damageSource = DamageSource.playerAttack(((org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer) source).getHandle());
        } else {
            damageSource = DamageSource.mobAttack(((CraftLivingEntity) source).getHandle());
        }
    } else {
        damageSource = DamageSource.projectile(null, ((CraftLivingEntity) source).getHandle());
    }
    EntityLiving nms = ((CraftLivingEntity) victim).getHandle();
    nms.combatTracker.trackDamage(damageSource, (float) damage, (float) health);
}
Also used : Player(org.bukkit.entity.Player) CraftPlayer(org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer) DamageSource(net.minecraft.server.v1_16_R3.DamageSource) EntityLiving(net.minecraft.server.v1_16_R3.EntityLiving) CraftPlayer(org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer) CraftLivingEntity(org.bukkit.craftbukkit.v1_16_R3.entity.CraftLivingEntity)

Aggregations

Player (org.bukkit.entity.Player)10 LivingEntity (org.bukkit.entity.LivingEntity)3 DamageSource (net.minecraft.server.v1_12_R1.DamageSource)2 DamageSource (net.minecraft.server.v1_15_R1.DamageSource)2 EntityLiving (net.minecraft.server.v1_15_R1.EntityLiving)2 CraftLivingEntity (org.bukkit.craftbukkit.v1_15_R1.entity.CraftLivingEntity)2 CraftPlayer (org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer)2 EntityDeathEvent (org.bukkit.event.entity.EntityDeathEvent)2 DamageSource (net.minecraft.server.v1_10_R1.DamageSource)1 EntityLiving (net.minecraft.server.v1_10_R1.EntityLiving)1 DamageSource (net.minecraft.server.v1_11_R1.DamageSource)1 EntityIronGolem (net.minecraft.server.v1_11_R1.EntityIronGolem)1 EntityLiving (net.minecraft.server.v1_11_R1.EntityLiving)1 PathfinderGoalLookAtPlayer (net.minecraft.server.v1_11_R1.PathfinderGoalLookAtPlayer)1 EntityLiving (net.minecraft.server.v1_12_R1.EntityLiving)1 DamageSource (net.minecraft.server.v1_13_R2.DamageSource)1 EntityLiving (net.minecraft.server.v1_13_R2.EntityLiving)1 DamageSource (net.minecraft.server.v1_14_R1.DamageSource)1 EntityLiving (net.minecraft.server.v1_14_R1.EntityLiving)1 EntityPlayer (net.minecraft.server.v1_15_R1.EntityPlayer)1