Skip to content

Commit

Permalink
Add <li@list.formatted> so list contents can be displayed in a non-sc…
Browse files Browse the repository at this point in the history
…ary way to mortals.
  • Loading branch information
davidcernat committed Sep 25, 2013
1 parent f2dec7f commit 2ef9dc7
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/main/java/net/aufdemrand/denizen/objects/dList.java
Expand Up @@ -236,6 +236,28 @@ public String getAttribute(Attribute attribute) {
.getAttribute(attribute.fulfill(1));
}

// <--[tag]
// @attribute <li@list.formatted>
// @returns Element
// @description
// returns formatted list useful for display in quests, messages, etc.
// -->
if (attribute.startsWith("formatted")) {
if (isEmpty()) return new Element("").getAttribute(attribute.fulfill(1));
StringBuilder dScriptArg = new StringBuilder();

for (int n = 0; n < this.size(); n++) {

dScriptArg.append(this.get(n).replaceAll("\\w\\w?@", ""));

if (n == this.size() - 2) dScriptArg.append(" and ");
else dScriptArg.append(", ");
}

return new Element(dScriptArg.toString().substring(0, dScriptArg.length() - 2))
.getAttribute(attribute.fulfill(1));
}

// <--[tag]
// @attribute <li@list.size>
// @returns Element(Number)
Expand Down

0 comments on commit 2ef9dc7

Please sign in to comment.