Search in sources :

Example 6 with EntityDeathEvent

use of org.bukkit.event.entity.EntityDeathEvent 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 7 with EntityDeathEvent

use of org.bukkit.event.entity.EntityDeathEvent 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();
        ItemStack[] itemStack = new ItemStack[] { new ItemStack(Material.ROTTEN_FLESH) };
        Bukkit.getServer().getPluginManager().callEvent(new EntityDeathEvent((LivingEntity) this.getBukkitEntity(), Arrays.asList(itemStack), expToDrop));
        IronGolem golem = (IronGolem) damagesource.getEntity().getBukkitEntity();
        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_8_R3.EntityIronGolem) ItemStack(org.bukkit.inventory.ItemStack)

Example 8 with EntityDeathEvent

use of org.bukkit.event.entity.EntityDeathEvent 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_9_R1.EntityIronGolem)

Example 9 with EntityDeathEvent

use of org.bukkit.event.entity.EntityDeathEvent 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_9_R1.PathfinderGoalLookAtPlayer) EntityDeathEvent(org.bukkit.event.entity.EntityDeathEvent) ItemStack(org.bukkit.inventory.ItemStack)

Example 10 with EntityDeathEvent

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

the class GlowLivingEntity method setHealth.

// //////////////////////////////////////////////////////////////////////////
// Health
@Override
public void setHealth(double health) {
    if (health < 0) {
        health = 0;
    }
    if (health > getMaxHealth()) {
        health = getMaxHealth();
    }
    this.health = health;
    metadata.set(MetadataIndex.HEALTH, (float) health);
    for (Objective objective : getServer().getScoreboardManager().getMainScoreboard().getObjectivesByCriteria(Criterias.HEALTH)) {
        objective.getScore(getName()).setScore((int) health);
    }
    if (health > 0) {
        return;
    }
    if (this.tryUseTotem()) {
        return;
    }
    // Killed
    active = false;
    Sound deathSound = getDeathSound();
    if (deathSound != null && !isSilent()) {
        world.playSound(location, deathSound, getSoundVolume(), getSoundPitch());
    }
    playEffectKnownAndSelf(EntityEffect.DEATH);
    if (this instanceof GlowPlayer) {
        GlowPlayer player = (GlowPlayer) this;
        List<ItemStack> items = null;
        boolean dropInventory = !world.getGameRuleMap().getBoolean(GameRules.KEEP_INVENTORY);
        if (dropInventory) {
            items = Arrays.stream(player.getInventory().getContents()).filter(stack -> !InventoryUtil.isEmpty(stack)).collect(Collectors.toList());
            player.getInventory().clear();
        }
        PlayerDeathEvent event = new PlayerDeathEvent(player, items, 0, player.getDisplayName() + " died.");
        EventFactory.getInstance().callEvent(event);
        server.broadcastMessage(event.getDeathMessage());
        if (dropInventory) {
            for (ItemStack item : items) {
                world.dropItemNaturally(getLocation(), item);
            }
        }
        player.setShoulderEntityRight(null);
        player.setShoulderEntityLeft(null);
        player.incrementStatistic(Statistic.DEATHS);
    } else {
        EntityDeathEvent deathEvent = new EntityDeathEvent(this, new ArrayList<>());
        if (world.getGameRuleMap().getBoolean(GameRules.DO_MOB_LOOT)) {
            LootData data = LootingManager.generate(this);
            deathEvent.getDrops().addAll(data.getItems());
            // Only drop experience when hit by a player within 5 seconds (100 game ticks)
            if (ticksLived - playerDamageTick <= 100 && data.getExperience() > 0) {
                ThreadLocalRandom random = ThreadLocalRandom.current();
                ExperienceSplitter.forEachCut(data.getExperience(), exp -> {
                    double modX = random.nextDouble() - 0.5;
                    double modZ = random.nextDouble() - 0.5;
                    Location xpLocation = new Location(world, location.getBlockX() + 0.5 + modX, location.getY(), location.getBlockZ() + 0.5 + modZ);
                    GlowExperienceOrb orb = (GlowExperienceOrb) world.spawnEntity(xpLocation, EntityType.EXPERIENCE_ORB);
                    orb.setExperience(exp);
                    orb.setSourceEntityId(this.getUniqueId());
                    if (getLastDamager() != null) {
                        orb.setTriggerEntityId(getLastDamager().getUniqueId());
                    }
                });
            }
        }
        deathEvent = EventFactory.getInstance().callEvent(deathEvent);
        for (ItemStack item : deathEvent.getDrops()) {
            world.dropItemNaturally(getLocation(), item);
        }
    }
    // to help keep code maintainable
    if (this instanceof GlowSlime) {
        GlowSlime slime = (GlowSlime) this;
        int size = slime.getSize();
        if (size > 1) {
            int count = 2 + ThreadLocalRandom.current().nextInt(3);
            SlimeSplitEvent event = EventFactory.getInstance().callEvent(new SlimeSplitEvent(slime, count));
            if (event.isCancelled() || event.getCount() <= 0) {
                return;
            }
            count = event.getCount();
            for (int i = 0; i < count; ++i) {
                Location spawnLoc = getLocation().clone();
                spawnLoc.add(ThreadLocalRandom.current().nextDouble(0.5, 3), 0, ThreadLocalRandom.current().nextDouble(0.5, 3));
                GlowSlime splitSlime = (GlowSlime) world.spawnEntity(spawnLoc, EntityType.SLIME);
                // Make the split slime the same name as the killed slime.
                if (getCustomName() != null && !getCustomName().isEmpty()) {
                    splitSlime.setCustomName(getCustomName());
                }
                splitSlime.setSize(size / 2);
            }
        }
    }
}
Also used : EntityDeathEvent(org.bukkit.event.entity.EntityDeathEvent) GlowExperienceOrb(net.glowstone.entity.objects.GlowExperienceOrb) Sound(org.bukkit.Sound) PlayerDeathEvent(org.bukkit.event.entity.PlayerDeathEvent) LootData(net.glowstone.util.loot.LootData) Objective(org.bukkit.scoreboard.Objective) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) GlowSlime(net.glowstone.entity.monster.GlowSlime) SlimeSplitEvent(org.bukkit.event.entity.SlimeSplitEvent) ItemStack(org.bukkit.inventory.ItemStack) Location(org.bukkit.Location)

Aggregations

EntityDeathEvent (org.bukkit.event.entity.EntityDeathEvent)10 LivingEntity (org.bukkit.entity.LivingEntity)8 ItemStack (org.bukkit.inventory.ItemStack)7 IronGolem (org.bukkit.entity.IronGolem)4 Player (org.bukkit.entity.Player)3 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)1 GlowSlime (net.glowstone.entity.monster.GlowSlime)1 GlowExperienceOrb (net.glowstone.entity.objects.GlowExperienceOrb)1 LootData (net.glowstone.util.loot.LootData)1 EntityIronGolem (net.minecraft.server.v1_11_R1.EntityIronGolem)1 PathfinderGoalLookAtPlayer (net.minecraft.server.v1_11_R1.PathfinderGoalLookAtPlayer)1 EntityIronGolem (net.minecraft.server.v1_12_R1.EntityIronGolem)1 PathfinderGoalLookAtPlayer (net.minecraft.server.v1_12_R1.PathfinderGoalLookAtPlayer)1 EntityIronGolem (net.minecraft.server.v1_8_R3.EntityIronGolem)1 EntityIronGolem (net.minecraft.server.v1_9_R1.EntityIronGolem)1 PathfinderGoalLookAtPlayer (net.minecraft.server.v1_9_R1.PathfinderGoalLookAtPlayer)1 Location (org.bukkit.Location)1 Sound (org.bukkit.Sound)1