Skip to content

Commit

Permalink
Add new containsObjectsFrom(...) to make sure matchesArgumentList doe…
Browse files Browse the repository at this point in the history
…sn't unintentionally return false, leaving an argument to be misinterpreted. Remember: ALWAYS check your dLists for valid information!
  • Loading branch information
aufdemrand committed Nov 10, 2013
1 parent 5ea2cd3 commit aaa2670
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 11 deletions.
8 changes: 7 additions & 1 deletion src/main/java/net/aufdemrand/denizen/objects/aH.java
Expand Up @@ -227,7 +227,7 @@ public boolean matchesArgumentList(Class<? extends dObject> dClass) {

dList list = new dList(this.getValue().replace("li@", ""));

return list.filter(dClass) != null;
return list.containsObjectsFrom(dClass);
}


Expand All @@ -251,6 +251,12 @@ public <T extends dObject> T asType(Class<? extends dObject> clazz) {
public void reportUnhandled() {
dB.echoError('\'' + raw_value + "' is an unknown argument!");
}


@Override
public String toString() {
return raw_value;
}
}


Expand Down
35 changes: 25 additions & 10 deletions src/main/java/net/aufdemrand/denizen/objects/dList.java
Expand Up @@ -161,6 +161,20 @@ public String[] toArray() {
return list.toArray(new String[list.size()]);
}

// Returns if the list contains objects from the specified dClass
// by using the matches() method.
public boolean containsObjectsFrom(Class<? extends dObject> dClass) {

List<dObject> results = new ArrayList<dObject>();

// Iterate through elements until one matches() the dClass
for (String element : this)
if (ObjectFetcher.checkMatch(dClass, element))
return true;

return false;
}

// Return a list that includes only strings that match the values
// of an Enum array
public List<String> filter(Enum[] values) {
Expand Down Expand Up @@ -401,15 +415,15 @@ public String getAttribute(Attribute attribute) {
// -->
if (attribute.startsWith("find") &&
attribute.hasContext(1)) {
for (int i = 0; i < size(); i++) {
if (get(i).equalsIgnoreCase(attribute.getContext(1)))
return new Element(i + 1).getAttribute(attribute.fulfill(1));
}
for (int i = 0; i < size(); i++) {
if (get(i).toUpperCase().contains(attribute.getContext(1).toUpperCase()))
return new Element(i + 1).getAttribute(attribute.fulfill(1));
}
return new Element(-1).getAttribute(attribute.fulfill(1));
for (int i = 0; i < size(); i++) {
if (get(i).equalsIgnoreCase(attribute.getContext(1)))
return new Element(i + 1).getAttribute(attribute.fulfill(1));
}
for (int i = 0; i < size(); i++) {
if (get(i).toUpperCase().contains(attribute.getContext(1).toUpperCase()))
return new Element(i + 1).getAttribute(attribute.fulfill(1));
}
return new Element(-1).getAttribute(attribute.fulfill(1));
}

// <--[tag]
Expand Down Expand Up @@ -492,7 +506,7 @@ public String getAttribute(Attribute attribute) {
}
else {
return new Element(this.get(Utilities.getRandom().nextInt(this.size())))
.getAttribute(attribute.fulfill(1));
.getAttribute(attribute.fulfill(1));
}
}
}
Expand Down Expand Up @@ -546,4 +560,5 @@ public String getAttribute(Attribute attribute) {
: new Element(identify()).getAttribute(attribute));
}


}

0 comments on commit aaa2670

Please sign in to comment.