Skip to content

Commit

Permalink
ListTag.count_matches
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Mar 8, 2022
1 parent 049671c commit 195e456
Showing 1 changed file with 23 additions and 0 deletions.
Expand Up @@ -1637,6 +1637,29 @@ else if (input.size() > 1) {
return new ElementTag(count);
});

// <--[tag]
// @attribute <ListTag.count_matches[<matcher>]>
// @returns ElementTag(Number)
// @description
// returns how many times a value in the list matches the matcher,
// using the system behind <@link language Advanced Script Event Matching>,
// For example: a list of "one|two|three" .count[t*] returns 2.
// -->
tagProcessor.registerStaticTag(ElementTag.class, "count_matches", (attribute, object) -> {
if (!attribute.hasParam()) {
attribute.echoError("The tag ListTag.count_matches[...] must have a value.");
return null;
}
ScriptEvent.MatchHelper matcher = ScriptEvent.createMatcher(attribute.getParam());
int count = 0;
for (String s : object) {
if (matcher.doesMatch(s)) {
count++;
}
}
return new ElementTag(count);
});

// <--[tag]
// @attribute <ListTag.sum>
// @returns ElementTag(Decimal)
Expand Down

0 comments on commit 195e456

Please sign in to comment.