Search in sources :

Example 16 with EntityEquipment

use of org.bukkit.inventory.EntityEquipment in project Essentials by drtshock.

the class SpawnMob method defaultMobData.

private static void defaultMobData(final EntityType type, final Entity spawned) {
    if (type == EntityType.SKELETON) {
        final EntityEquipment invent = ((LivingEntity) spawned).getEquipment();
        InventoryWorkaround.setItemInMainHand(invent, new ItemStack(Material.BOW, 1));
        InventoryWorkaround.setItemInMainHandDropChance(invent, 0.1f);
        invent.setBoots(new ItemStack(Material.GOLD_BOOTS, 1));
        invent.setBootsDropChance(0.0f);
    }
    if (type == EntityType.PIG_ZOMBIE) {
        final PigZombie zombie = ((PigZombie) spawned);
        setVillager(zombie, false);
        final EntityEquipment invent = zombie.getEquipment();
        InventoryWorkaround.setItemInMainHand(invent, new ItemStack(Material.GOLD_SWORD, 1));
        InventoryWorkaround.setItemInMainHandDropChance(invent, 0.1f);
        invent.setBoots(new ItemStack(Material.GOLD_BOOTS, 1));
        invent.setBootsDropChance(0.0f);
    }
    if (type == EntityType.ZOMBIE) {
        final Zombie zombie = ((Zombie) spawned);
        setVillager(zombie, false);
        final EntityEquipment invent = zombie.getEquipment();
        invent.setBoots(new ItemStack(Material.GOLD_BOOTS, 1));
        invent.setBootsDropChance(0.0f);
    }
    if (type == EntityType.HORSE) {
        ((Horse) spawned).setJumpStrength(1.2);
    }
}
Also used : EntityEquipment(org.bukkit.inventory.EntityEquipment) ItemStack(org.bukkit.inventory.ItemStack)

Example 17 with EntityEquipment

use of org.bukkit.inventory.EntityEquipment in project InfernalMobs by NyaaCat.

the class AbilityArmoured method onMobSpawn.

@Override
public void onMobSpawn(InfernalMobSpawnEvent ev) {
    Mob mob = ev.mob;
    LivingEntity mobEntity = ev.mobEntity;
    mobEntity.setCanPickupItems(false);
    EntityEquipment ee = mobEntity.getEquipment();
    boolean isCloaked = mob.abilityList.contains(EnumAbilities.CLOAKED);
    // helmet & chestplate required for all mobs
    ee.setHelmetDropChance(0.0f);
    ee.setChestplateDropChance(0.0f);
    ee.setHelmet(new ItemStack(Material.DIAMOND_HELMET, 1));
    ee.setChestplate(new ItemStack(Material.DIAMOND_CHESTPLATE, 1));
    // leggings & boots for all visible mobs
    ee.setLeggingsDropChance(0.0f);
    ee.setBootsDropChance(0.0f);
    ee.setLeggings(new ItemStack(Material.DIAMOND_LEGGINGS, 1));
    ee.setBoots(new ItemStack(Material.DIAMOND_BOOTS, 1));
    // skeletons use bow
    if (mobEntity.getType() == EntityType.SKELETON) {
        ee.setItemInMainHand(new ItemStack(Material.BOW, 1));
        ee.setItemInMainHandDropChance(0);
    } else {
        // else use sword
        ItemStack sword = new ItemStack(Material.DIAMOND_SWORD, 1);
        sword.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, 4);
        ee.setItemInMainHand(sword);
        ee.setItemInMainHandDropChance(0);
    }
}
Also used : Mob(com.jacob_vejvoda.infernal_mobs.persist.Mob) EntityEquipment(org.bukkit.inventory.EntityEquipment) ItemStack(org.bukkit.inventory.ItemStack)

Example 18 with EntityEquipment

use of org.bukkit.inventory.EntityEquipment in project MagicPlugin by elBukkit.

the class TakeItemAction method perform.

@Override
public SpellResult perform(CastContext context) {
    Entity target = context.getTargetEntity();
    if (target == null) {
        return SpellResult.NO_TARGET;
    }
    ItemStack item = null;
    if (target instanceof LivingEntity) {
        LivingEntity livingEntity = (LivingEntity) target;
        if (displayName == null) {
            EntityEquipment equipment = livingEntity.getEquipment();
            item = equipment.getItemInMainHand();
            ;
            equipment.setItemInMainHand(null);
        } else {
            if (!(target instanceof Player)) {
                return SpellResult.PLAYER_REQUIRED;
            }
            Player targetPlayer = (Player) target;
            PlayerInventory playerInventory = targetPlayer.getInventory();
            for (int i = 0; i < playerInventory.getSize(); i++) {
                ItemStack inventoryItem = playerInventory.getItem(i);
                if (InventoryUtils.isEmpty(inventoryItem))
                    continue;
                ItemMeta meta = inventoryItem.getItemMeta();
                if (meta == null || !meta.hasDisplayName())
                    continue;
                if (meta.getDisplayName().equals(displayName)) {
                    item = inventoryItem;
                    playerInventory.setItem(i, null);
                    break;
                }
            }
        }
    } else if (target instanceof Item) {
        Item itemEntity = (Item) target;
        item = itemEntity.getItemStack();
        if (displayName != null) {
            ItemMeta itemMeta = item.getItemMeta();
            if (itemMeta == null || !itemMeta.hasDisplayName() || !itemMeta.getDisplayName().equals(displayName)) {
                item = null;
            }
        }
        if (item != null) {
            itemEntity.remove();
        }
    }
    if (InventoryUtils.isEmpty(item)) {
        return SpellResult.NO_TARGET;
    }
    context.getMage().giveItem(item);
    return SpellResult.CAST;
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Item(org.bukkit.entity.Item) Player(org.bukkit.entity.Player) EntityEquipment(org.bukkit.inventory.EntityEquipment) PlayerInventory(org.bukkit.inventory.PlayerInventory) ItemStack(org.bukkit.inventory.ItemStack) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Example 19 with EntityEquipment

use of org.bukkit.inventory.EntityEquipment in project InfernalMobs by NyaaCat.

the class AbilityArmoured method onMobSpawn.

@Override
public void onMobSpawn(InfernalMobSpawnEvent ev) {
    Mob mob = ev.mob;
    LivingEntity mobEntity = ev.mobEntity;
    mobEntity.setCanPickupItems(false);
    EntityEquipment ee = mobEntity.getEquipment();
    boolean isCloaked = mob.abilityList.contains(EnumAbilities.CLOAKED);
    // helmet & chestplate required for all mobs
    ee.setHelmetDropChance(0.0f);
    ee.setChestplateDropChance(0.0f);
    ee.setHelmet(new ItemStack(Material.DIAMOND_HELMET, 1));
    ee.setChestplate(new ItemStack(Material.DIAMOND_CHESTPLATE, 1));
    // leggings & boots for all visible mobs
    ee.setLeggingsDropChance(0.0f);
    ee.setBootsDropChance(0.0f);
    ee.setLeggings(new ItemStack(Material.DIAMOND_LEGGINGS, 1));
    ee.setBoots(new ItemStack(Material.DIAMOND_BOOTS, 1));
    // skeletons use bow
    if (mobEntity.getType() == EntityType.SKELETON) {
        ee.setItemInMainHand(new ItemStack(Material.BOW, 1));
        ee.setItemInMainHandDropChance(0);
    } else {
        // else use sword
        ItemStack sword = new ItemStack(Material.DIAMOND_SWORD, 1);
        sword.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, 4);
        ee.setItemInMainHand(sword);
        ee.setItemInMainHandDropChance(0);
    }
}
Also used : Mob(com.jacob_vejvoda.infernal_mobs.persist.Mob) EntityEquipment(org.bukkit.inventory.EntityEquipment) ItemStack(org.bukkit.inventory.ItemStack)

Example 20 with EntityEquipment

use of org.bukkit.inventory.EntityEquipment in project CitizensAPI by CitizensDev.

the class Equipment method onSpawn.

@Override
@SuppressWarnings("deprecation")
public void onSpawn() {
    if (!(npc.getEntity() instanceof LivingEntity) && !(npc.getEntity() instanceof ArmorStand))
        return;
    if (npc.getEntity() instanceof Enderman) {
        Enderman enderman = (Enderman) npc.getEntity();
        if (equipment[0] != null) {
            if (SpigotUtil.isUsing1_13API()) {
                enderman.setCarriedBlock(equipment[0].getType().createBlockData());
            } else {
                enderman.setCarriedMaterial(equipment[0].getData());
            }
        }
    } else {
        EntityEquipment equip = getEquipmentFromEntity(npc.getEntity());
        if (equipment[0] != null) {
            equip.setItemInHand(equipment[0]);
        }
        equip.setHelmet(equipment[1]);
        equip.setChestplate(equipment[2]);
        equip.setLeggings(equipment[3]);
        equip.setBoots(equipment[4]);
        try {
            equip.setItemInOffHand(equipment[5]);
        } catch (NoSuchMethodError e) {
        }
    }
    if (npc.getEntity() instanceof Player) {
        ((Player) npc.getEntity()).updateInventory();
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) ArmorStand(org.bukkit.entity.ArmorStand) Enderman(org.bukkit.entity.Enderman) EntityEquipment(org.bukkit.inventory.EntityEquipment)

Aggregations

EntityEquipment (org.bukkit.inventory.EntityEquipment)26 ItemStack (org.bukkit.inventory.ItemStack)15 LivingEntity (org.bukkit.entity.LivingEntity)8 Player (org.bukkit.entity.Player)6 Entity (org.bukkit.entity.Entity)5 ArrayList (java.util.ArrayList)4 Location (org.bukkit.Location)4 Item (org.bukkit.entity.Item)4 Pair (com.mojang.datafixers.util.Pair)3 Mage (com.elmakers.mine.bukkit.api.magic.Mage)2 Mob (com.jacob_vejvoda.infernal_mobs.persist.Mob)2 LinkedList (java.util.LinkedList)2 UUID (java.util.UUID)2 AttributeManager (net.glowstone.entity.AttributeManager)2 GlowLeashHitch (net.glowstone.entity.objects.GlowLeashHitch)2 CompoundTag (net.glowstone.util.nbt.CompoundTag)2 AttributeModifier (org.bukkit.attribute.AttributeModifier)2 Enderman (org.bukkit.entity.Enderman)2 LeashHitch (org.bukkit.entity.LeashHitch)2 PlayerInventory (org.bukkit.inventory.PlayerInventory)2