Search in sources :

Example 36 with ItemStack

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

the class dInventory method removeBook.

/**
     * Remove a book from this inventory, comparing
     * only its title and author with books in the
     * inventory, but ignoring its text, thus having
     * Denizen support for updatable quest journals
     * and their like
     *
     * @param title    The title of the book
     * @param author   The author of the book
     * @param quantity The number of books to remove
     * @return The resulting dInventory
     */
public dInventory removeBook(String title, String author, int quantity) {
    if (inventory == null || (title == null && author == null)) {
        return this;
    }
    for (ItemStack invStack : inventory) {
        if (quantity == 0) {
            break;
        }
        if (invStack != null && invStack.getItemMeta() instanceof BookMeta) {
            BookMeta invMeta = (BookMeta) invStack.getItemMeta();
            String invTitle = invMeta.getTitle();
            String invAuthor = invMeta.getAuthor();
            if ((invTitle == null && title != null) || (invAuthor == null && author != null)) {
                continue;
            } else if (invTitle == null || invAuthor == null) {
                continue;
            }
            if (invAuthor.equalsIgnoreCase(author) && invTitle.equalsIgnoreCase(title)) {
                // need to
                if (quantity - invStack.getAmount() < 0) {
                    invStack.setAmount((quantity - invStack.getAmount()) * -1);
                } else {
                    inventory.removeItem(invStack);
                    // Update the quantity we still have to remove
                    quantity -= invStack.getAmount();
                }
            }
        }
    }
    return this;
}
Also used : ItemStack(org.bukkit.inventory.ItemStack) BookMeta(org.bukkit.inventory.meta.BookMeta)

Example 37 with ItemStack

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

the class EntityFirework method getPropertyString.

/////////
// Property Methods
///////
@Override
public String getPropertyString() {
    ItemStack item = new ItemStack(Material.FIREWORK);
    item.setItemMeta(((Firework) firework.getBukkitEntity()).getFireworkMeta());
    return new dItem(item).identify();
}
Also used : net.aufdemrand.denizen.objects.dItem(net.aufdemrand.denizen.objects.dItem) ItemStack(org.bukkit.inventory.ItemStack)

Example 38 with ItemStack

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

the class InventoryContents method getContentsWithLore.

public dList getContentsWithLore(String lore, boolean simple) {
    if (inventory.getInventory() == null) {
        return null;
    }
    dList contents = new dList();
    lore = ChatColor.stripColor(lore);
    for (ItemStack item : inventory.getInventory().getContents()) {
        if (item != null && item.getType() != Material.AIR) {
            if (item.hasItemMeta() && item.getItemMeta().hasLore()) {
                for (String line : item.getItemMeta().getLore()) {
                    // the context
                    if (ChatColor.stripColor(line).equalsIgnoreCase(lore)) {
                        if (simple) {
                            contents.add(new dItem(item).identifySimple());
                        } else {
                            contents.add(new dItem(item).identify());
                        }
                        break;
                    }
                }
            }
        }
    }
    return contents;
}
Also used : net.aufdemrand.denizen.objects.dItem(net.aufdemrand.denizen.objects.dItem) net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList) ItemStack(org.bukkit.inventory.ItemStack)

Example 39 with ItemStack

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

the class InventoryContents method getContents.

public dList getContents(int simpleOrFull) {
    if (inventory.getInventory() == null) {
        return null;
    }
    dList contents = new dList();
    boolean containsNonAir = false;
    for (ItemStack item : inventory.getInventory().getContents()) {
        if (item != null && item.getType() != Material.AIR) {
            containsNonAir = true;
            if (simpleOrFull == 1) {
                contents.add(new dItem(item).identifySimple());
            } else if (simpleOrFull == 2) {
                contents.add(new dItem(item).getFullString());
            } else {
                contents.add(new dItem(item).identify());
            }
        } else {
            contents.add("i@air");
        }
    }
    if (!containsNonAir) {
        contents.clear();
    } else {
        contents = dList.valueOf(contents.identify().replaceAll("(\\|i@air)*$", ""));
    }
    return contents;
}
Also used : net.aufdemrand.denizen.objects.dItem(net.aufdemrand.denizen.objects.dItem) net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList) ItemStack(org.bukkit.inventory.ItemStack)

Example 40 with ItemStack

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

the class ItemAttributeNBT method getPropertyString.

@Override
public String getPropertyString() {
    ItemStack itemStack = item.getItemStack();
    List<CustomNBT.AttributeReturn> nbtKeys = CustomNBT.getAttributes(itemStack);
    if (nbtKeys != null && !nbtKeys.isEmpty()) {
        dList list = new dList();
        for (CustomNBT.AttributeReturn atr : nbtKeys) {
            list.add(EscapeTags.Escape(atr.attr) + "/" + EscapeTags.Escape(atr.slot) + "/" + atr.op + "/" + atr.amt);
        }
        return list.identify();
    }
    return null;
}
Also used : net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList) ItemStack(org.bukkit.inventory.ItemStack) CustomNBT(net.aufdemrand.denizen.utilities.nbt.CustomNBT)

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