use of net.aufdemrand.denizencore.utilities.text.StringHolder in project Denizen-For-Bukkit by DenizenScript.
the class YamlCommand method yaml.
@TagManager.TagEvents
public void yaml(ReplaceableTagEvent event) {
if (!event.matches("yaml")) {
return;
}
Attribute attribute = event.getAttributes();
// -->
if (attribute.getAttribute(2).equalsIgnoreCase("list")) {
dList list = new dList();
list.addAll(yamls.keySet());
event.setReplaced(list.getAttribute(attribute.fulfill(2)));
return;
}
// YAML tag requires name context and type context.
if ((!event.hasNameContext() || !(event.hasTypeContext() || attribute.getAttribute(2).equalsIgnoreCase("to_json"))) && !attribute.hasAlternative()) {
dB.echoError("YAML tag '" + event.raw_tag + "' is missing required context. Tag replacement aborted.");
return;
}
// Set id (name context) and path (type context)
String id = event.getNameContext().toUpperCase();
String path = event.getTypeContext();
// Check if there is a yaml file loaded with the specified id
if (!yamls.containsKey(id)) {
if (!attribute.hasAlternative()) {
dB.echoError("YAML tag '" + event.raw_tag + "' has specified an invalid ID, or the specified id has already" + " been closed. Tag replacement aborted. ID given: '" + id + "'.");
}
return;
}
// Catch up with what has already been processed.
attribute.fulfill(1);
// -->
if (attribute.startsWith("contains")) {
event.setReplaced(new Element(getYaml(id).contains(path)).getAttribute(attribute.fulfill(1)));
return;
}
// -->
if (attribute.startsWith("is_list")) {
event.setReplaced(new Element(getYaml(id).isList(path)).getAttribute(attribute.fulfill(1)));
return;
}
// -->
if (attribute.startsWith("read")) {
attribute.fulfill(1);
if (getYaml(id).isList(path)) {
List<String> value = getYaml(id).getStringList(path);
if (value == null) {
// If value is null, the key at the specified path didn't exist.
return;
} else {
event.setReplaced(new dList(value).getAttribute(attribute));
return;
}
} else {
String value = getYaml(id).getString(path);
if (value == null) {
// If value is null, the key at the specified path didn't exist.
return;
} else {
event.setReplaced(new Element(value).getAttribute(attribute));
return;
}
}
}
// -->
if (attribute.startsWith("list_deep_keys")) {
Set<StringHolder> keys;
if (path != null && path.length() > 0) {
YamlConfiguration section = getYaml(id).getConfigurationSection(path);
if (section == null) {
return;
}
keys = section.getKeys(true);
} else {
keys = getYaml(id).getKeys(true);
}
if (keys == null) {
return;
} else {
event.setReplaced(new dList(keys).getAttribute(attribute.fulfill(1)));
return;
}
}
// -->
if (attribute.startsWith("list_keys")) {
Set<StringHolder> keys;
if (path != null && path.length() > 0) {
YamlConfiguration section = getYaml(id).getConfigurationSection(path);
if (section == null) {
return;
}
keys = section.getKeys(false);
} else {
keys = getYaml(id).getKeys(false);
}
if (keys == null) {
return;
} else {
event.setReplaced(new dList(keys).getAttribute(attribute.fulfill(1)));
return;
}
}
// -->
if (attribute.startsWith("to_json")) {
JSONObject jsobj = new JSONObject(getYaml(id).getMap());
event.setReplaced(new Element(jsobj.toString()).getAttribute(attribute.fulfill(1)));
return;
}
}
use of net.aufdemrand.denizencore.utilities.text.StringHolder in project Denizen-For-Bukkit by DenizenScript.
the class AssignmentTrait method describe.
public void describe(CommandSender sender, int page) throws CommandException {
AssignmentScriptContainer assignmentScript = ScriptRegistry.getScriptContainer(assignment);
Paginator paginator = new Paginator().header("Assignment");
paginator.addLine("<e>Current assignment: " + (hasAssignment() ? this.assignment : "None.") + "");
paginator.addLine("");
if (!hasAssignment()) {
paginator.sendPage(sender, page);
return;
}
// Interact Scripts
boolean entriesPresent = false;
paginator.addLine(ChatColor.GRAY + "Interact Scripts:");
paginator.addLine("<e>Key: <a>Priority <b>Name");
if (assignmentScript.contains("INTERACT SCRIPTS")) {
entriesPresent = true;
for (String scriptEntry : assignmentScript.getStringList("INTERACT SCRIPTS")) {
String[] split = scriptEntry.split(" ", 2);
if (split.length == 2 && aH.matchesInteger(split[0])) {
paginator.addLine("<a>" + split[0] + "<b> " + split[1]);
} else {
paginator.addLine("<b>" + scriptEntry);
}
}
}
if (!entriesPresent) {
paginator.addLine("<c>No Interact Scripts assigned.");
}
paginator.addLine("");
if (!entriesPresent) {
if (!paginator.sendPage(sender, page)) {
throw new CommandException(Messages.COMMAND_PAGE_MISSING);
}
return;
}
// Scheduled Activities
entriesPresent = false;
paginator.addLine(ChatColor.GRAY + "Scheduled Scripts:");
paginator.addLine("<e>Key: <a>Time <b>Name");
if (assignmentScript.contains("SCHEDULED ACTIVITIES")) {
entriesPresent = true;
for (String scriptEntry : assignmentScript.getStringList("SCHEDULED ACTIVITIES")) {
paginator.addLine("<a>" + scriptEntry.split(" ")[0] + "<b> " + scriptEntry.split(" ", 2)[1]);
}
}
if (!entriesPresent) {
paginator.addLine("<c>No scheduled scripts activities.");
}
paginator.addLine("");
// Actions
entriesPresent = false;
paginator.addLine(ChatColor.GRAY + "Actions:");
paginator.addLine("<e>Key: <a>Action name <b>Script Size");
if (assignmentScript.contains("ACTIONS")) {
entriesPresent = true;
}
if (entriesPresent) {
for (StringHolder action : assignmentScript.getConfigurationSection("ACTIONS").getKeys(false)) {
paginator.addLine("<a>" + action.str + " <b>" + assignmentScript.getStringList("ACTIONS." + action.str).size());
}
} else {
paginator.addLine("<c>No actions defined in the assignment.");
}
paginator.addLine("");
if (!paginator.sendPage(sender, page)) {
throw new CommandException(Messages.COMMAND_PAGE_MISSING, page);
}
}
Aggregations