use of org.bukkit.inventory.meta.BundleMeta in project Denizen-For-Bukkit by DenizenScript.
the class ItemInventory method adjust.
@Override
public void adjust(Mechanism mechanism) {
// -->
if (mechanism.matches("inventory_contents") && mechanism.hasValue()) {
List<ItemStack> items = new ArrayList<>();
for (ItemTag item : mechanism.valueAsType(ListTag.class).filter(ItemTag.class, mechanism.context)) {
items.add(item.getItemStack());
}
if (item.getItemMeta() instanceof BlockStateMeta) {
BlockStateMeta bsm = ((BlockStateMeta) item.getItemMeta());
InventoryHolder invHolder = (InventoryHolder) bsm.getBlockState();
if (items.size() > getInventoryFor(invHolder).getSize()) {
mechanism.echoError("Invalid inventory_contents input size; expected " + getInventoryFor(invHolder).getSize() + " or less.");
return;
}
getInventoryFor(invHolder).setContents(items.toArray(new ItemStack[0]));
bsm.setBlockState((BlockState) invHolder);
item.setItemMeta(bsm);
} else if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_17)) {
BundleMeta bundle = (BundleMeta) item.getItemMeta();
bundle.setItems(items);
item.setItemMeta(bundle);
}
}
if (mechanism.matches("inventory") && mechanism.hasValue()) {
Deprecations.itemInventoryTag.warn(mechanism.context);
Argument argument = new Argument("");
argument.unsetValue();
argument.object = mechanism.getValue();
Map.Entry<Integer, InventoryTag> inventoryPair = Conversion.getInventory(argument, mechanism.context);
if (inventoryPair == null || inventoryPair.getValue().getInventory() == null) {
return;
}
ListTag items = InventoryContents.getFrom(inventoryPair.getValue()).getContents(false);
ItemStack[] itemArray = new ItemStack[items.size()];
for (int i = 0; i < itemArray.length; i++) {
itemArray[i] = ((ItemTag) items.objectForms.get(i)).getItemStack().clone();
}
if (item.getItemMeta() instanceof BlockStateMeta) {
BlockStateMeta bsm = ((BlockStateMeta) item.getItemMeta());
InventoryHolder invHolder = (InventoryHolder) bsm.getBlockState();
if (items.size() > getInventoryFor(invHolder).getSize()) {
mechanism.echoError("Invalid inventory mechanism input size; expected " + getInventoryFor(invHolder).getSize() + " or less.");
return;
}
getInventoryFor(invHolder).setContents(itemArray);
bsm.setBlockState((BlockState) invHolder);
item.setItemMeta(bsm);
} else if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_17)) {
BundleMeta bundle = (BundleMeta) item.getItemMeta();
bundle.setItems(Arrays.asList(itemArray));
item.setItemMeta(bundle);
}
}
}
Aggregations