diff --git a/src/main/java/net/aufdemrand/denizen/objects/dCuboid.java b/src/main/java/net/aufdemrand/denizen/objects/dCuboid.java index 0d99481399..ee0e8728f2 100644 --- a/src/main/java/net/aufdemrand/denizen/objects/dCuboid.java +++ b/src/main/java/net/aufdemrand/denizen/objects/dCuboid.java @@ -402,19 +402,35 @@ public String toString() { public String getAttribute(Attribute attribute) { if (attribute == null) return null; - + // <-- + // -> dList(dLocation) + // Returns each block location within the dCuboid. + // --> if (attribute.startsWith("get_blocks")) return new dList(getBlocks()) .getAttribute(attribute.fulfill(1)); + // <-- + // -> 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)); + // <-- + // -> dList(dLocation) + // Returns the block locations from the dCuboid's filter. + // --> if (attribute.startsWith("filter")) return new dList(filter) .getAttribute(attribute.fulfill(1)); + // <-- + // ]> -> 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)) diff --git a/src/main/java/net/aufdemrand/denizen/objects/dItem.java b/src/main/java/net/aufdemrand/denizen/objects/dItem.java index 66878d3a00..d2e70e2361 100644 --- a/src/main/java/net/aufdemrand/denizen/objects/dItem.java +++ b/src/main/java/net/aufdemrand/denizen/objects/dItem.java @@ -526,36 +526,67 @@ public String getAttribute(Attribute attribute) { if (attribute == null) return null; + // <-- + // -> 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 + // <-- + // -> Element + // Returns the dItem identification for the item. + // --> if (attribute.startsWith("identify")) { return new Element(identify()) .getAttribute(attribute.fulfill(1)); } + // <-- + // -> 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)); + // <-- + // -> 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)); + // <-- + // -> 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)); + // <-- + // -> Element(Number) + // Returns the durability of the dItem. + // --> if (attribute.startsWith("durability")) return new Element(String.valueOf(getItemStack().getDurability())) .getAttribute(attribute.fulfill(1)); + // <-- + // -> 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)); + // <-- + // -> Element + // Returns the formatted material name of the dItem. + // --> if (attribute.startsWith("material.formatted")) { String id = item.getType().name().toLowerCase(); @@ -595,17 +626,35 @@ public String getAttribute(Attribute attribute) { } } + // <-- + // -> Element + // Returns the material name of the dItem. + // --> if (attribute.startsWith("material")) return new Element(getItemStack().getType().toString()) .getAttribute(attribute.fulfill(1)); + // <-- + // -> 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)); + // <-- + // -> dList + // Returns a list of enchantment names on the dItem. + // --> if (attribute.startsWith("enchantments")) { - // TODO ? + if (getItemStack().hasItemMeta() && getItemStack().getItemMeta().hasEnchants()) { + List enchants = new ArrayList(); + for (Enchantment enchantment : getItemStack().getEnchantments().keySet()) + enchants.add(enchantment.getName()); + return new dList(enchants) + .getAttribute(attribute.fulfill(1)); + } } if (attribute.startsWith("book")) { @@ -613,22 +662,42 @@ public String getAttribute(Attribute attribute) { attribute.fulfill(1); BookMeta bookInfo = (BookMeta) getItemStack().getItemMeta(); + // <-- + // -> Element + // Returns the author of the book. + // --> if (attribute.startsWith("author")) return new Element(bookInfo.getAuthor()) .getAttribute(attribute.fulfill(1)); + // <-- + // -> Element + // Returns the title of the book. + // --> if (attribute.startsWith("title")) return new Element(bookInfo.getTitle()) .getAttribute(attribute.fulfill(1)); + // <-- + // -> Element(Number) + // Returns the number of pages in the book. + // --> if (attribute.startsWith("page_count")) return new Element(bookInfo.getPageCount()) .getAttribute(attribute.fulfill(1)); + // <-- + // ]> -> 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)); + // <-- + // -> dList + // Returns the pages of the book as a dList. + // --> if (attribute.startsWith("pages")) return new dList(bookInfo.getPages()) .getAttribute(attribute.fulfill(1)); @@ -636,6 +705,10 @@ public String getAttribute(Attribute attribute) { } else dB.echoError("Item referenced is not a written book!"); } + // <-- + // -> 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 loreList = new ArrayList(); @@ -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 + // <-- + // -> 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()) { diff --git a/src/main/java/net/aufdemrand/denizen/objects/dScript.java b/src/main/java/net/aufdemrand/denizen/objects/dScript.java index 8f0167ff64..12e915c000 100644 --- a/src/main/java/net/aufdemrand/denizen/objects/dScript.java +++ b/src/main/java/net/aufdemrand/denizen/objects/dScript.java @@ -135,10 +135,19 @@ public dObject setPrefix(String prefix) { public String getAttribute(Attribute attribute) { if (attribute == null) return "null"; + // <-- + // -> Element + // Returns the container type of a dScript. + // --> if (attribute.startsWith("container_type")) return new Element(container.getType()) .getAttribute(attribute.fulfill(1)); + // <-- + // ]> -> 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()); @@ -146,6 +155,11 @@ public String getAttribute(Attribute attribute) { .getAttribute(attribute.fulfill(1)); } + // <-- + // ].check[]> -> 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()); @@ -156,6 +170,10 @@ public String getAttribute(Attribute attribute) { .getAttribute(attribute.fulfill(2)); } + // <-- + // ]> -> 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());