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;
}
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();
}
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;
}
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;
}
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;
}
Aggregations