From b0335b5ac19ce2adcc80e6700d5f16f340c2ac4a Mon Sep 17 00:00:00 2001 From: Alex 'mcmonkey' Goodwin Date: Thu, 21 Oct 2021 06:22:20 -0700 Subject: [PATCH] InventoryTag.find_all_items --- .../denizen/objects/InventoryTag.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/InventoryTag.java b/plugin/src/main/java/com/denizenscript/denizen/objects/InventoryTag.java index 76ac08070d..67e3bf95cb 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/InventoryTag.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/InventoryTag.java @@ -1828,6 +1828,31 @@ else if (meta.hasDisplayName() && CoreUtilities.toLowerCase(meta.getDisplayName( return new ElementTag(-1); }); + // <--[tag] + // @attribute ]> + // @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)) {