use of com.denizenscript.denizen.objects.ItemTag in project Denizen-For-Bukkit by DenizenScript.
the class PlayerBreaksItemScriptEvent method onPlayerItemBreak.
@EventHandler
public void onPlayerItemBreak(PlayerItemBreakEvent event) {
if (EntityTag.isNPC(event.getPlayer())) {
return;
}
item = new ItemTag(event.getBrokenItem());
this.event = event;
cancelled = false;
fire(event);
}
use of com.denizenscript.denizen.objects.ItemTag in project Denizen-For-Bukkit by DenizenScript.
the class PlayerConsumesScriptEvent method onPlayerConsumes.
@EventHandler
public void onPlayerConsumes(PlayerItemConsumeEvent event) {
if (EntityTag.isNPC(event.getPlayer())) {
return;
}
item = new ItemTag(event.getItem());
this.event = event;
fire(event);
}
use of com.denizenscript.denizen.objects.ItemTag 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);
}
}
}
use of com.denizenscript.denizen.objects.ItemTag in project Denizen-For-Bukkit by DenizenScript.
the class ItemRawNBT method setFullNBT.
public void setFullNBT(ItemTag item, MapTag input, TagContext context, boolean retainOld) {
CompoundTag compoundTag = retainOld ? NMSHandler.getItemHelper().getNbtData(item.getItemStack()) : null;
Map<String, Tag> result = compoundTag == null ? new LinkedHashMap<>() : new LinkedHashMap<>(compoundTag.getValue());
for (Map.Entry<StringHolder, ObjectTag> entry : input.map.entrySet()) {
try {
Tag tag = convertObjectToNbt(entry.getValue().toString(), context, "(item).");
if (tag != null) {
result.put(entry.getKey().str, tag);
}
} catch (Exception ex) {
Debug.echoError("Raw_Nbt input failed for root key '" + entry.getKey().str + "'.");
Debug.echoError(ex);
return;
}
}
compoundTag = NMSHandler.getInstance().createCompoundTag(result);
item.setItemStack(NMSHandler.getItemHelper().setNbtData(item.getItemStack(), compoundTag));
}
use of com.denizenscript.denizen.objects.ItemTag in project Denizen-For-Bukkit by DenizenScript.
the class ItemFlags method getObjectAttribute.
@Override
public ObjectTag getObjectAttribute(Attribute attribute) {
if (attribute == null) {
return null;
}
// -->
if (attribute.startsWith("with_flag")) {
ItemTag item = new ItemTag(this.item.getItemStack().clone());
FlagCommand.FlagActionProvider provider = new FlagCommand.FlagActionProvider();
provider.tracker = item.getFlagTracker();
DataAction action = DataActionHelper.parse(provider, attribute.getParam(), attribute.context);
// -->
if (attribute.startsWith("duration", 2)) {
provider.expiration = new TimeTag(TimeTag.now().millis() + attribute.getContextObject(2).asType(DurationTag.class, attribute.context).getMillis());
attribute.fulfill(1);
}
action.execute(attribute.context);
item.reapplyTracker(provider.tracker);
return item.getObjectAttribute(attribute.fulfill(1));
}
return null;
}
Aggregations