public String getAttribute(Attribute attribute) {
if (attribute == null) return "null";
if (attribute.startsWith("book")) {
BookMeta bookInfo = (BookMeta) item.getItemStack().getItemMeta();
attribute = attribute.fulfill(1);
if (item.getItemStack().getType() == Material.WRITTEN_BOOK) {
// <--[tag]
// @attribute <i@item.book.author>
// @returns Element
// @mechanism dItem.book
// @group properties
// @description
// Returns the author of the book.
// -->
if (attribute.startsWith("author"))
return new Element(bookInfo.getAuthor())
.getAttribute(attribute.fulfill(1));
// <--[tag]
// @attribute <i@item.book.title>
// @returns Element
// @mechanism dItem.book
// @group properties
// @description
// Returns the title of the book.
// -->
if (attribute.startsWith("title"))
return new Element(bookInfo.getTitle())
.getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <i@item.book.page_count>
// @returns Element(Number)
// @mechanism dItem.book
// @group properties
// @description
// Returns the number of pages in the book.
// -->
if (attribute.startsWith("page_count"))
return new Element(bookInfo.getPageCount())
.getAttribute(attribute.fulfill(1));
// <--[tag]
// @attribute <i@item.book.get_page[<#>]>
// @returns Element
// @mechanism dItem.book
// @group properties
// @description
// Returns the page specified from the book as an element.
// -->
if (attribute.startsWith("get_page") && aH.matchesInteger(attribute.getContext(1)))
return new Element(bookInfo.getPage(attribute.getIntContext(1)))
.getAttribute(attribute.fulfill(1));
// Deprecated in favor of pages.escape_contents
if (attribute.startsWith("pages.escaped")) {
StringBuilder output = new StringBuilder();
for (String page: bookInfo.getPages()) {
output.append(EscapeTags.Escape(page)).append("|");
}
return new dList(output.length() > 0 ?
output.substring(0, output.length() - 1): output.toString())
.getAttribute(attribute.fulfill(2));
}
// <--[tag]
// @attribute <i@item.book.pages>
// @returns dList
// @mechanism dItem.book
// @group properties
// @description
// Returns the pages of the book as a dList.
// -->
if (attribute.startsWith("pages"))
return new dList(bookInfo.getPages())
.getAttribute(attribute.fulfill(1));
// <--[tag]
// @attribute <i@item.book>
// @returns Element