Skip to content

Commit

Permalink
allow multiple indices in inventory.slot[...]
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Sep 4, 2019
1 parent b1a3b5b commit ab0ecea
Showing 1 changed file with 34 additions and 12 deletions.
Expand Up @@ -2020,23 +2020,45 @@ else if (item != null && item.hasItemMeta() && item.getItemMeta().hasDisplayName
}

// <--[tag]
// @attribute <InventoryTag.slot[<#>]>
// @returns ItemTag
// @attribute <InventoryTag.slot[<#>|...]>
// @returns ItemTag or ListTag(ItemTag)
// @description
// Returns the item in the specified slot.
// If one slot is specified, returns the item in the specified slot.
// If more than what slot is specified, returns a list of the item in each given slot.
// -->
if (attribute.startsWith("slot")
&& attribute.hasContext(1)
&& ArgumentHelper.matchesInteger(attribute.getContext(1))) {
int slot = new ElementTag(attribute.getContext(1)).asInt() - 1;
if (slot < 0) {
slot = 0;
&& attribute.hasContext(1)) {
ListTag slots = ListTag.getListFor(attribute.getContextObject(1));
if (slots.size() == 0) {
if (!attribute.hasAlternative()) {
Debug.echoError("Cannot get a list of zero slots.");
}
return null;
}
else if (slots.size() == 1) {
int slot = new ElementTag(attribute.getContext(1)).asInt() - 1;
if (slot < 0) {
slot = 0;
}
else if (slot > getInventory().getSize() - 1) {
slot = getInventory().getSize() - 1;
}
return new ItemTag(getInventory().getItem(slot)).getAttribute(attribute.fulfill(1));
}
else if (slot > getInventory().getSize() - 1) {
slot = getInventory().getSize() - 1;
else {
ListTag result = new ListTag();
for (String slotText : slots) {
int slot = new ElementTag(slotText).asInt() - 1;
if (slot < 0) {
slot = 0;
}
else if (slot > getInventory().getSize() - 1) {
slot = getInventory().getSize() - 1;
}
result.addObject(new ItemTag(getInventory().getItem(slot)));
}
return result.getAttribute(attribute.fulfill(1));
}
return new ItemTag(getInventory().getItem(slot))
.getAttribute(attribute.fulfill(1));
}

// <--[tag]
Expand Down

0 comments on commit ab0ecea

Please sign in to comment.