Skip to content

Commit

Permalink
InventoryTag.find_all_items
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Oct 21, 2021
1 parent 033989c commit b0335b5
Showing 1 changed file with 25 additions and 0 deletions.
Expand Up @@ -1828,6 +1828,31 @@ else if (meta.hasDisplayName() && CoreUtilities.toLowerCase(meta.getDisplayName(
return new ElementTag(-1);
});

// <--[tag]
// @attribute <InventoryTag.find_all_items[<matcher>]>
// @returns ListTag
// @description
// Returns a list of the location of all slots that contains an item that matches the given item matcher.
// Returns an empty list if there's no match.
// Uses the system behind <@link language Advanced Script Event Matching>.
// -->
tagProcessor.registerTag(ListTag.class, "find_all_items", (attribute, object) -> {
if (!attribute.hasContext(1)) {
return null;
}
ListTag result = new ListTag();
String matcher = attribute.getContext(1);
for (int i = 0; i < object.inventory.getSize(); i++) {
ItemStack item = object.inventory.getItem(i);
if (item != null) {
if (BukkitScriptEvent.tryItem(new ItemTag(item), matcher)) {
result.addObject(new ElementTag(i + 1));
}
}
}
return result;
});

tagProcessor.registerTag(ElementTag.class, "find", (attribute, object) -> {
Deprecations.inventoryNonMatcherTags.warn(attribute.context);
if (attribute.startsWith("material", 2)) {
Expand Down

0 comments on commit b0335b5

Please sign in to comment.