Skip to content

Commit

Permalink
Add tag list.set.at
Browse files Browse the repository at this point in the history
Yay further overpowered list control
  • Loading branch information
mcmonkey4eva committed Nov 23, 2014
1 parent a45480d commit fa75a28
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/main/java/net/aufdemrand/denizen/objects/dList.java
Expand Up @@ -612,6 +612,40 @@ else if (get(n).startsWith("e@") || get(n).startsWith("n@")) {
}
}

// <--[tag]
// @attribute <li@list.set[...|...].at[<#>]>
// @returns dList
// @description
// returns a new dList with the items specified inserted to the specified location, replacing the element
// already at that location.
// EG, .set[two].at[2] on a list of "one|four" will return "one|two|three".
// -->
if (attribute.startsWith("set") &&
attribute.hasContext(1)) {
if (this.size() == 0)
return null;
dList items = dList.valueOf(attribute.getContext(1));
attribute = attribute.fulfill(1);
if (attribute.startsWith("at")
&& attribute.hasContext(1)) {
dList result = new dList(this);
int index = new Element(attribute.getContext(1)).asInt() - 1;
if (index < 0)
index = 0;
if (index > result.size() - 1)
index = result.size() - 1;
result.remove(index);
for (int i = 0; i < items.size(); i++) {
result.add(index + i, items.get(i));
}
return result.getAttribute(attribute.fulfill(1));
}
else {
dB.echoError("The tag li@list.set[...] requires an at[#] tag follow it!");
return null;
}
}

// <--[tag]
// @attribute <li@list.include[...|...]>
// @returns dList
Expand Down

0 comments on commit fa75a28

Please sign in to comment.