// @description
// Returns the value of the script's YAML as either an Element or dList.
// -->
if (attribute.startsWith("yaml_key")
&& attribute.hasContext(1)) {
ScriptContainer container = getContainer();
if (container == null) {
dB.echoError("Missing script container?!");
return new Element(identify()).getAttribute(attribute);
}
YamlConfiguration section = container.getConfigurationSection("");
if (section == null) {
dB.echoError("Missing YAML section?!");
return new Element(identify()).getAttribute(attribute);
}
Object obj = section.get(attribute.getContext(1).toUpperCase());
if (obj == null) return null;
if (obj instanceof List) {
dList list = new dList();
for (Object each : (List<Object>) obj)
list.add(TagManager.tag(attribute.getScriptEntry() == null ? null: attribute.getScriptEntry().getPlayer(),
attribute.getScriptEntry() == null ? null: attribute.getScriptEntry().getNPC(), each.toString(), false, attribute.getScriptEntry()));
return list.getAttribute(attribute.fulfill(1));
}
else return new Element(TagManager.tag(attribute.getScriptEntry() == null ? null: attribute.getScriptEntry().getPlayer(),
attribute.getScriptEntry() == null ? null: attribute.getScriptEntry().getNPC(), obj.toString(), false, attribute.getScriptEntry()))
.getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <s@script.list_keys[<constant_name>]>
// @returns dList
// @description
// Returns a list of all keys within a script.
// -->
if (attribute.startsWith("list_keys")) {
return new dList(getContainer().getConfigurationSection(attribute.hasContext(1) ? attribute.getContext(1): "").getKeys(false))
.getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <s@script.list_deep_keys[<constant_name>]>
// @returns dList
// @description
// Returns a list of all keys within a script, searching recursively.
// -->
if (attribute.startsWith("list_deep_keys")) {
return new dList(getContainer().getConfigurationSection(attribute.hasContext(1) ? attribute.getContext(1): "").getKeys(true))
.getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <s@script.to_json>
// @returns Element
// @description
// Converts the YAML Script Container to a JSON array.
// Best used with 'yaml data' type scripts.
// -->
if (attribute.startsWith("to_json")) {
JSONObject jsobj = new JSONObject(container.getConfigurationSection("").getMap());
jsobj.remove("TYPE");
return new Element(jsobj.toString()).getAttribute(attribute.fulfill(1));
}
/////////////////