Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add what seems to be the rest of the tag meta. #376

Merged
merged 2 commits into from
Aug 20, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/main/java/net/aufdemrand/denizen/objects/dCuboid.java
Original file line number Diff line number Diff line change
Expand Up @@ -402,19 +402,35 @@ public String toString() {
public String getAttribute(Attribute attribute) {
if (attribute == null) return null;


// <--
// <cu@cuboid.get_blocks> -> dList(dLocation)
// Returns each block location within the dCuboid.
// -->
if (attribute.startsWith("get_blocks"))
return new dList(getBlocks())
.getAttribute(attribute.fulfill(1));

// <--
// <cu@cuboid.get_outline> -> dList(dLocation)
// Returns each block location on the outline of the dCuboid.
// -->
if (attribute.startsWith("get_outline"))
return new dList(getOutline())
.getAttribute(attribute.fulfill(1));

// <--
// <cu@cuboid.filter> -> dList(dLocation)
// Returns the block locations from the dCuboid's filter.
// -->
if (attribute.startsWith("filter"))
return new dList(filter)
.getAttribute(attribute.fulfill(1));

// <--
// <cu@cuboid.is_within[<location>]> -> Element(Boolean)
// Returns true if the dCuboid is within the location.
// Otherise, returns false.
// -->
if (attribute.startsWith("is_within")) {
dLocation loc = dLocation.valueOf(attribute.getContext(1));
return new Element(isInsideCuboid(loc))
Expand Down
83 changes: 80 additions & 3 deletions src/main/java/net/aufdemrand/denizen/objects/dItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -526,36 +526,67 @@ public String getAttribute(Attribute attribute) {

if (attribute == null) return null;

// <--
// <i@item.qty> -> Element(Number)
// Returns the number of items in the dItem's itemstack.
// -->
if (attribute.startsWith("qty"))
return new Element(String.valueOf(getItemStack().getAmount()))
.getAttribute(attribute.fulfill(1));

// Needs to be above "id" or it won't work
// <--
// <i@item.identify> -> Element
// Returns the dItem identification for the item.
// -->
if (attribute.startsWith("identify")) {
return new Element(identify())
.getAttribute(attribute.fulfill(1));
}

// <--
// <i@item.id> -> Element(Number)
// Returns the item ID number of the dItem.
// -->
if (attribute.startsWith("id"))
return new Element(String.valueOf(getItemStack().getTypeId()))
.getAttribute(attribute.fulfill(1));

// <--
// <i@item.max_stack> -> Element(Number)
// Returns the max number of this item possible in a single stack.
// -->
if (attribute.startsWith("max_stack"))
return new Element(String.valueOf(getItemStack().getMaxStackSize()))
.getAttribute(attribute.fulfill(1));

// <--
// <i@item.data> -> Element(Number)
// Returns the data value of the material of the dItem.
// -->
if (attribute.startsWith("data"))
return new Element(String.valueOf(getItemStack().getData().getData()))
.getAttribute(attribute.fulfill(1));

// <--
// <i@item.durability> -> Element(Number)
// Returns the durability of the dItem.
// -->
if (attribute.startsWith("durability"))
return new Element(String.valueOf(getItemStack().getDurability()))
.getAttribute(attribute.fulfill(1));

// <--
// <i@item.repairable> -> Element(Boolean)
// Returns true if the dItem can be repaired. Otherwise, returns false.
// -->
if (attribute.startsWith("repairable"))
return new Element(String.valueOf(isRepairable()))
.getAttribute(attribute.fulfill(1));

// <--
// <i@item.material.formatted> -> Element
// Returns the formatted material name of the dItem.
// -->
if (attribute.startsWith("material.formatted")) {

String id = item.getType().name().toLowerCase();
Expand Down Expand Up @@ -595,47 +626,89 @@ public String getAttribute(Attribute attribute) {
}
}

// <--
// <i@item.material> -> Element
// Returns the material name of the dItem.
// -->
if (attribute.startsWith("material"))
return new Element(getItemStack().getType().toString())
.getAttribute(attribute.fulfill(1));

// <--
// <i@item.display> -> Element
// Returns the display name of the dItem.
// -->
if (attribute.startsWith("display"))
if (getItemStack().hasItemMeta() && getItemStack().getItemMeta().hasDisplayName())
return new Element(getItemStack().getItemMeta().getDisplayName())
.getAttribute(attribute.fulfill(1));

// <--
// <i@item.enchantments> -> dList
// Returns a list of enchantment names on the dItem.
// -->
if (attribute.startsWith("enchantments")) {
// TODO ?
if (getItemStack().hasItemMeta() && getItemStack().getItemMeta().hasEnchants()) {
List<String> enchants = new ArrayList<String>();
for (Enchantment enchantment : getItemStack().getEnchantments().keySet())
enchants.add(enchantment.getName());
return new dList(enchants)
.getAttribute(attribute.fulfill(1));
}
}

if (attribute.startsWith("book")) {
if (getItemStack().getType() == Material.WRITTEN_BOOK) {
attribute.fulfill(1);
BookMeta bookInfo = (BookMeta) getItemStack().getItemMeta();

// <--
// <i@item.book.author> -> Element
// Returns the author of the book.
// -->
if (attribute.startsWith("author"))
return new Element(bookInfo.getAuthor())
.getAttribute(attribute.fulfill(1));

// <--
// <i@item.book.title> -> Element
// Returns the title of the book.
// -->
if (attribute.startsWith("title"))
return new Element(bookInfo.getTitle())
.getAttribute(attribute.fulfill(1));

// <--
// <i@item.book.page_count> -> Element(Number)
// Returns the number of pages in the book.
// -->
if (attribute.startsWith("page_count"))
return new Element(bookInfo.getPageCount())
.getAttribute(attribute.fulfill(1));

// <--
// <i@item.book.get_page[<#>]> -> Element
// Returns the page specified from the book.
// -->
if (attribute.startsWith("get_page") && aH.matchesInteger(attribute.getContext(1)))
return new Element(bookInfo.getPage(attribute.getIntContext(1)))
.getAttribute(attribute.fulfill(1));

// <--
// <i@item.book.pages> -> dList
// Returns the pages of the book as a dList.
// -->
if (attribute.startsWith("pages"))
return new dList(bookInfo.getPages())
.getAttribute(attribute.fulfill(1));

} else dB.echoError("Item referenced is not a written book!");
}

// <--
// <i@item.scriptname> -> Element
// Returns the script name of the dItem.
// -->
if (attribute.startsWith("scriptname")) // Note: Update this when the id: is stored less stupidly!
if (getItemStack().hasItemMeta() && getItemStack().getItemMeta().hasLore()) {
List<String> loreList = new ArrayList<String>();
Expand All @@ -644,7 +717,11 @@ public String getAttribute(Attribute attribute) {
return new Element(itemLore.substring(5)).getAttribute(attribute.fulfill(1));
}

// Return all lore except for lore that holds item script ID
// <--
// <i@item.lore> -> dList
// Returns lore as a dList except for the "invisible"
// lore that holds the item script ID.
// -->
if (attribute.startsWith("lore")) {
if (getItemStack().hasItemMeta() && getItemStack().getItemMeta().hasLore()) {

Expand Down
18 changes: 18 additions & 0 deletions src/main/java/net/aufdemrand/denizen/objects/dScript.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,17 +135,31 @@ public dObject setPrefix(String prefix) {
public String getAttribute(Attribute attribute) {
if (attribute == null) return "null";

// <--
// <s@script.container_type> -> Element
// Returns the container type of a dScript.
// -->
if (attribute.startsWith("container_type"))
return new Element(container.getType())
.getAttribute(attribute.fulfill(1));

// <--
// <s@script.cooled_down[<player>]> -> Element(Boolean)
// Returns true if the script has been cooled down for the
// player (defaults to current). Otherwise, returns false.
// -->
if (attribute.startsWith("cooled_down")) {
dPlayer player = (attribute.hasContext(1) ? dPlayer.valueOf(attribute.getContext(1))
: attribute.getScriptEntry().getPlayer());
return new Element(container.checkCooldown(player))
.getAttribute(attribute.fulfill(1));
}

// <--
// <s@script.requirements[<player>].check[<path>]> -> Element
// Returns true if the player specified (defaults to current) has the
// requirement. Otherwise, returns false.
// -->
if (attribute.startsWith("requirements.check")) {
dPlayer player = (attribute.hasContext(1) ? dPlayer.valueOf(attribute.getContext(1))
: attribute.getScriptEntry().getPlayer());
Expand All @@ -156,6 +170,10 @@ public String getAttribute(Attribute attribute) {
.getAttribute(attribute.fulfill(2));
}

// <--
// <s@script.cooldown[<player>]> -> Duration
// Returns the time left for the player to cooldown for the script.
// -->
if (attribute.startsWith("cooldown")) {
dPlayer player = (attribute.hasContext(1) ? dPlayer.valueOf(attribute.getContext(1))
: attribute.getScriptEntry().getPlayer());
Expand Down