Skip to content

Commit

Permalink
Add tag script.yaml_key[...]
Browse files Browse the repository at this point in the history
A way to read a script as if it were YAML.
  • Loading branch information
mcmonkey4eva committed Sep 24, 2014
1 parent 8c015f1 commit 597aba4
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/main/java/net/aufdemrand/denizen/objects/dScript.java
Expand Up @@ -331,6 +331,31 @@ else return new Element(TagManager.tag(attribute.getScriptEntry().getPlayer(),
.getAttribute(attribute.fulfill(1));
}

// <--[tag]
// @attribute <s@script.yaml_key[<constant_name>]>
// @returns Element or dList
// @description
// Returns the value of the script's YAML as either an Element or dList.
// -->
if (attribute.startsWith("yaml_key")) {
if (!attribute.hasContext(1)) return Element.NULL.getAttribute(attribute.fulfill(1));

Object obj = getContainer().getConfigurationSection("").get(attribute.getContext(1).toUpperCase());
if (obj == null) return Element.NULL.getAttribute(attribute.fulfill(1));

if (obj instanceof List) {
dList list = new dList();
for (Object each : (List<Object>) obj)
list.add(TagManager.tag(attribute.getScriptEntry().getPlayer(),
attribute.getScriptEntry().getNPC(), each.toString(), false, attribute.getScriptEntry()));
return list.getAttribute(attribute.fulfill(1));

}
else return new Element(TagManager.tag(attribute.getScriptEntry().getPlayer(),
attribute.getScriptEntry().getNPC(), obj.toString(), false, attribute.getScriptEntry()))
.getAttribute(attribute.fulfill(1));
}

// <--[tag]
// @attribute <s@script.step[<player>]>
// @returns Element
Expand Down

0 comments on commit 597aba4

Please sign in to comment.