Skip to content

Commit

Permalink
list support for inventory.include, fixes #2116
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Jan 8, 2020
1 parent 504ea6f commit 9566488
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
Expand Up @@ -1519,21 +1519,19 @@ public static void registerTags() {
});

// <--[tag]
// @attribute <InventoryTag.include[<item>]>
// @attribute <InventoryTag.include[<item>|...]>
// @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<ItemTag> 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());
Expand All @@ -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;
});

Expand Down
Expand Up @@ -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));
Expand Down
Expand Up @@ -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:<player.inventory> o:stick slot:10
// -->

private enum Action {OPEN, CLOSE, COPY, MOVE, SWAP, ADD, REMOVE, SET, KEEP, EXCLUDE, FILL, CLEAR, UPDATE, ADJUST}
Expand Down

0 comments on commit 9566488

Please sign in to comment.