Search in sources :

Example 26 with ItemStack

use of org.bukkit.inventory.ItemStack in project Bukkit by Bukkit.

the class PotionTest method ItemStackConversion.

@Test
public void ItemStackConversion() {
    Potion potion = new Potion(PotionType.POISON);
    ItemStack itemstack = potion.toItemStack(1);
    assertThat(itemstack.getType(), is(Material.POTION));
    assertTrue(itemstack.getAmount() == 1);
    assertTrue(itemstack.getDurability() == potion.toDamageValue());
}
Also used : ItemStack(org.bukkit.inventory.ItemStack) Test(org.junit.Test)

Example 27 with ItemStack

use of org.bukkit.inventory.ItemStack in project Bukkit by Bukkit.

the class PotionTest method applyToItemStack.

@Test
public void applyToItemStack() {
    Potion potion = new Potion(PotionType.POISON);
    ItemStack stack = new ItemStack(Material.POTION, 1);
    potion.apply(stack);
    assertTrue(stack.getDurability() == potion.toDamageValue());
}
Also used : ItemStack(org.bukkit.inventory.ItemStack) Test(org.junit.Test)

Example 28 with ItemStack

use of org.bukkit.inventory.ItemStack in project Denizen-For-Bukkit by DenizenScript.

the class dInventory method setSlots.

/**
     * Set items in an inventory, starting with a specified slot
     *
     * @param slot  The slot to start from
     * @param items The items to add
     * @return The resulting dInventory
     */
public dInventory setSlots(int slot, ItemStack[] items, int c) {
    if (inventory == null || items == null) {
        return this;
    }
    for (int i = 0; i < c; i++) {
        if (i >= items.length || items[i] == null) {
            inventory.setItem(slot + i, new ItemStack(Material.AIR));
        }
        ItemStack item = items[i];
        if (slot + i < 0 || slot + i >= inventory.getSize()) {
            break;
        }
        inventory.setItem(slot + i, item);
    }
    if (Depends.citizens != null && dNPC.matches(idHolder)) {
        // TODO: Directly store holder
        dNPC.valueOf(idHolder).getInventoryTrait().setContents(inventory.getContents());
    }
    return this;
}
Also used : ItemStack(org.bukkit.inventory.ItemStack)

Example 29 with ItemStack

use of org.bukkit.inventory.ItemStack in project Denizen-For-Bukkit by DenizenScript.

the class dInventory method getEquipment.

public dList getEquipment() {
    ItemStack[] equipment = null;
    if (inventory instanceof PlayerInventory) {
        equipment = ((PlayerInventory) inventory).getArmorContents();
    } else if (inventory instanceof HorseInventory) {
        equipment = new ItemStack[] { ((HorseInventory) inventory).getSaddle(), ((HorseInventory) inventory).getArmor() };
    }
    if (equipment == null) {
        return null;
    }
    dList equipmentList = new dList();
    for (ItemStack item : equipment) {
        equipmentList.add(new dItem(item).identify());
    }
    return equipmentList;
}
Also used : PlayerInventory(org.bukkit.inventory.PlayerInventory) HorseInventory(org.bukkit.inventory.HorseInventory) ItemStack(org.bukkit.inventory.ItemStack)

Example 30 with ItemStack

use of org.bukkit.inventory.ItemStack in project Denizen-For-Bukkit by DenizenScript.

the class dInventory method add.

/////////////////////
//   INVENTORY MANIPULATION
/////////////////
// Somewhat simplified version of CraftBukkit's current code
public dInventory add(int slot, ItemStack... items) {
    if (inventory == null || items == null) {
        return this;
    }
    for (int i = 0; i < items.length; i++) {
        ItemStack item = items[i];
        if (item == null) {
            continue;
        }
        int amount = item.getAmount();
        int max = item.getMaxStackSize();
        while (true) {
            // Do we already have a stack of it?
            int firstPartial = firstPartial(slot, item);
            // Drat! no partial stack
            if (firstPartial == -1) {
                // Find a free spot!
                int firstFree = firstEmpty(slot);
                if (firstFree == -1) {
                    // No space at all!
                    break;
                } else {
                    // More than a single stack!
                    if (amount > max) {
                        ItemStack clone = item.clone();
                        clone.setAmount(max);
                        inventory.setItem(firstFree, clone);
                        item.setAmount(amount -= max);
                    } else {
                        // Just store it
                        inventory.setItem(firstFree, item);
                        break;
                    }
                }
            } else {
                // So, apparently it might only partially fit, well lets do just that
                ItemStack partialItem = inventory.getItem(firstPartial);
                int partialAmount = partialItem.getAmount();
                int total = amount + partialAmount;
                // Check if it fully fits
                if (total <= max) {
                    partialItem.setAmount(total);
                    break;
                }
                // It fits partially
                partialItem.setAmount(max);
                item.setAmount(amount = total - max);
            }
        }
    }
    return this;
}
Also used : ItemStack(org.bukkit.inventory.ItemStack)

Aggregations

ItemStack (org.bukkit.inventory.ItemStack)1282 Player (org.bukkit.entity.Player)262 EventHandler (org.bukkit.event.EventHandler)183 ItemMeta (org.bukkit.inventory.meta.ItemMeta)167 ArrayList (java.util.ArrayList)130 Inventory (org.bukkit.inventory.Inventory)115 Location (org.bukkit.Location)88 Material (org.bukkit.Material)87 PlayerInventory (org.bukkit.inventory.PlayerInventory)84 Entity (org.bukkit.entity.Entity)63 Block (org.bukkit.block.Block)52 TagCompound (de.keyle.knbt.TagCompound)47 Map (java.util.Map)44 LivingEntity (org.bukkit.entity.LivingEntity)44 HashMap (java.util.HashMap)40 Mage (com.elmakers.mine.bukkit.api.magic.Mage)39 Enchantment (org.bukkit.enchantments.Enchantment)38 SkullMeta (org.bukkit.inventory.meta.SkullMeta)38 Vector (org.bukkit.util.Vector)35 Test (org.junit.Test)32