Search in sources :

Example 96 with ItemStack

use of org.bukkit.inventory.ItemStack in project EliteMobs by MagmaGuy.

the class ChickenHandler method superEggs.

public static void superEggs(Entity entity, int passiveStackAmount) {
    List<Chicken> tempChickenList = new ArrayList<>();
    if (entity instanceof Chicken && entity.hasMetadata(MetadataHandler.PASSIVE_ELITE_MOB_MD)) {
        tempChickenList.add((Chicken) entity);
    }
    if (tempChickenList.size() > 0) {
        Random random = new Random();
        int eggChance = random.nextInt(12000 / passiveStackAmount);
        //should spawn 1 by 1 but the odds of it spawning are scaled to fit config passivemob stack size
        if (eggChance == 1) {
            for (Chicken chicken : tempChickenList) {
                ItemStack eggStack = new ItemStack(EGG, 1);
                chicken.getWorld().dropItem(chicken.getLocation(), eggStack).setVelocity(ItemDropVelocity.ItemDropVelocity());
            }
        }
    }
}
Also used : Random(java.util.Random) ArrayList(java.util.ArrayList) Chicken(org.bukkit.entity.Chicken) ItemStack(org.bukkit.inventory.ItemStack)

Example 97 with ItemStack

use of org.bukkit.inventory.ItemStack in project EliteMobs by MagmaGuy.

the class DropsHandler method onDeath.

@EventHandler
public void onDeath(EntityDeathEvent event) {
    if (event.getEntity().hasMetadata(MetadataHandler.ELITE_MOB_MD) && !event.getEntity().hasMetadata(MetadataHandler.FORBIDDEN_MD) && event.getEntity().getMetadata(MetadataHandler.ELITE_MOB_MD).get(0).asInt() > 1) {
        List<ItemStack> droppedItems = event.getDrops();
        int mobLevel = (int) (event.getEntity().getMetadata(MetadataHandler.ELITE_MOB_MD).get(0).asInt() * ConfigValues.defaultConfig.getDouble("Aggressive EliteMob default loot multiplier"));
        for (ItemStack itemStack : droppedItems) {
            for (int i = 0; i < mobLevel; i++) {
                event.getEntity().getLocation().getWorld().dropItem(event.getEntity().getLocation(), itemStack);
            }
        }
        int droppedXP = event.getDroppedExp();
        event.setDroppedExp(droppedXP * mobLevel);
    }
}
Also used : ItemStack(org.bukkit.inventory.ItemStack) EventHandler(org.bukkit.event.EventHandler)

Example 98 with ItemStack

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

the class Commandhat method run.

@Override
protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
    if (args.length > 0 && (args[0].contains("rem") || args[0].contains("off") || args[0].equalsIgnoreCase("0"))) {
        final PlayerInventory inv = user.getBase().getInventory();
        final ItemStack head = inv.getHelmet();
        if (head == null || head.getType() == Material.AIR) {
            user.sendMessage(tl("hatEmpty"));
        } else {
            final ItemStack air = new ItemStack(Material.AIR);
            inv.setHelmet(air);
            InventoryWorkaround.addItems(user.getBase().getInventory(), head);
            user.sendMessage(tl("hatRemoved"));
        }
    } else {
        if (user.getBase().getItemInHand().getType() != Material.AIR) {
            final ItemStack hand = user.getBase().getItemInHand();
            if (hand.getType().getMaxDurability() == 0) {
                final PlayerInventory inv = user.getBase().getInventory();
                final ItemStack head = inv.getHelmet();
                inv.setHelmet(hand);
                inv.setItemInHand(head);
                user.sendMessage(tl("hatPlaced"));
            } else {
                user.sendMessage(tl("hatArmor"));
            }
        } else {
            user.sendMessage(tl("hatFail"));
        }
    }
}
Also used : PlayerInventory(org.bukkit.inventory.PlayerInventory) ItemStack(org.bukkit.inventory.ItemStack)

Example 99 with ItemStack

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

the class Commanditemdb method run.

@Override
protected void run(Server server, CommandSource sender, String commandLabel, String[] args) throws Exception {
    ItemStack itemStack = null;
    boolean itemHeld = false;
    if (args.length < 1) {
        if (sender.isPlayer()) {
            itemHeld = true;
            itemStack = sender.getPlayer().getItemInHand();
        }
        if (itemStack == null) {
            throw new NotEnoughArgumentsException();
        }
    } else {
        itemStack = ess.getItemDb().get(args[0]);
    }
    sender.sendMessage(tl("itemType", itemStack.getType().toString(), itemStack.getTypeId() + ":" + Integer.toString(itemStack.getDurability())));
    if (itemHeld && itemStack.getType() != Material.AIR) {
        int maxuses = itemStack.getType().getMaxDurability();
        int durability = ((maxuses + 1) - itemStack.getDurability());
        if (maxuses != 0) {
            sender.sendMessage(tl("durability", Integer.toString(durability)));
        }
    }
    final String itemNameList = ess.getItemDb().names(itemStack);
    if (itemNameList != null) {
        sender.sendMessage(tl("itemNames", ess.getItemDb().names(itemStack)));
    }
}
Also used : ItemStack(org.bukkit.inventory.ItemStack)

Example 100 with ItemStack

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

the class Commandpowertool method run.

@Override
protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
    final String command = getFinalArg(args, 0);
    final ItemStack itemStack = user.getBase().getItemInHand();
    powertool(server, user.getSource(), user, commandLabel, itemStack, command);
}
Also used : ItemStack(org.bukkit.inventory.ItemStack)

Aggregations

ItemStack (org.bukkit.inventory.ItemStack)1420 Player (org.bukkit.entity.Player)270 EventHandler (org.bukkit.event.EventHandler)197 ItemMeta (org.bukkit.inventory.meta.ItemMeta)192 ArrayList (java.util.ArrayList)151 Inventory (org.bukkit.inventory.Inventory)127 Material (org.bukkit.Material)103 Location (org.bukkit.Location)96 PlayerInventory (org.bukkit.inventory.PlayerInventory)84 Entity (org.bukkit.entity.Entity)67 Block (org.bukkit.block.Block)54 LivingEntity (org.bukkit.entity.LivingEntity)51 TagCompound (de.keyle.knbt.TagCompound)47 HashMap (java.util.HashMap)47 Map (java.util.Map)46 Vector (org.bukkit.util.Vector)44 Enchantment (org.bukkit.enchantments.Enchantment)41 SkullMeta (org.bukkit.inventory.meta.SkullMeta)41 Mage (com.elmakers.mine.bukkit.api.magic.Mage)39 Test (org.junit.Test)38