From 9566488183e43ea711f265ede3be5b4ce788d286 Mon Sep 17 00:00:00 2001 From: Alex 'mcmonkey' Goodwin Date: Wed, 8 Jan 2020 09:03:26 -0800 Subject: [PATCH] list support for inventory.include, fixes #2116 --- .../denizen/objects/InventoryTag.java | 18 +++++++++--------- .../denizenscript/denizen/objects/NPCTag.java | 2 +- .../commands/item/InventoryCommand.java | 4 ++++ 3 files changed, 14 insertions(+), 10 deletions(-) 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 243c6810b3..8d24080ff2 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/InventoryTag.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/InventoryTag.java @@ -1519,21 +1519,19 @@ public static void registerTags() { }); // <--[tag] - // @attribute ]> + // @attribute |...]> // @returns InventoryTag // @description - // Returns a copy of the InventoryTag with an item added. + // Returns a copy of the InventoryTag with items added. // --> registerTag("include", (attribute, object) -> { if (!attribute.hasContext(1) || !ItemTag.matches(attribute.getContext(1))) { return null; } - ItemTag item = ItemTag.valueOf(attribute.getContext(1), attribute.context); - if (item == null) { + List items = ListTag.getListFor(attribute.getContextObject(1)).filter(ItemTag.class, attribute.context); + if (items.isEmpty()) { return null; } - int qty = 1; - InventoryTag dummyInv = new InventoryTag(Bukkit.createInventory(null, object.inventory.getType(), NMSHandler.getInstance().getTitle(object.inventory))); if (object.inventory.getType() == InventoryType.CHEST) { dummyInv.setSize(object.inventory.getSize()); @@ -1550,11 +1548,13 @@ public static void registerTags() { if (attribute.startsWith("qty", 2)) { Deprecations.qtyTags.warn(attribute.context); } - qty = attribute.getIntContext(2); + int qty = attribute.getIntContext(2); + items.get(0).setAmount(qty); attribute.fulfill(1); } - item.setAmount(qty); - dummyInv.add(0, item.getItemStack()); + for (ItemTag item: items) { + dummyInv.add(0, item.getItemStack()); + } return dummyInv; }); diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/NPCTag.java b/plugin/src/main/java/com/denizenscript/denizen/objects/NPCTag.java index af18e7a9fa..0ceb104db2 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/NPCTag.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/NPCTag.java @@ -849,7 +849,7 @@ else if (attribute.startsWith("list", 2)) { // @returns ElementTag // @mechanism NPCTag.skin // @description - // Returns whether the NPC has a custom skinskin. + // Returns whether the NPC has a custom skin. // --> registerTag("has_skin", (attribute, object) -> { return new ElementTag(object.getCitizen().data().has(NPC.PLAYER_SKIN_UUID_METADATA)); diff --git a/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/item/InventoryCommand.java b/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/item/InventoryCommand.java index fb69ca3919..bce276cf58 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/item/InventoryCommand.java +++ b/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/item/InventoryCommand.java @@ -107,6 +107,10 @@ public class InventoryCommand extends AbstractCommand { // @Usage // Use to adjust a specific item in the player's inventory. // - inventory adjust slot:5 "lore:Item modified!" + // + // @Usage + // Use to set a single stick into slot 10 of the player's inventory. + // - inventory set d: o:stick slot:10 // --> private enum Action {OPEN, CLOSE, COPY, MOVE, SWAP, ADD, REMOVE, SET, KEEP, EXCLUDE, FILL, CLEAR, UPDATE, ADJUST}