use of com.denizenscript.denizen.objects.ItemTag in project Denizen-For-Bukkit by DenizenScript.
the class PotionSplashScriptEvent method onPotionSplash.
@EventHandler
public void onPotionSplash(PotionSplashEvent event) {
potion = new ItemTag(event.getPotion().getItem());
location = new LocationTag(event.getEntity().getLocation());
this.event = event;
fire(event);
}
use of com.denizenscript.denizen.objects.ItemTag in project Denizen-For-Bukkit by DenizenScript.
the class EntityEquipment method registerTags.
public static void registerTags() {
// <--[tag]
// @attribute <EntityTag.equipment>
// @returns ListTag(ItemTag)
// @mechanism EntityTag.equipment
// @group inventory
// @description
// Returns a ListTag containing the entity's equipment.
// Output list is boots|leggings|chestplate|helmet
// -->
PropertyParser.<EntityEquipment, ObjectTag>registerTag(ObjectTag.class, "equipment", (attribute, object) -> {
org.bukkit.inventory.EntityEquipment equipment = object.entity.getLivingEntity().getEquipment();
if (attribute.startsWith("equipment.boots")) {
Deprecations.entityEquipmentSubtags.warn(attribute.context);
attribute.fulfill(1);
ItemStack boots = equipment.getBoots();
return new ItemTag(boots != null ? boots : new ItemStack(Material.AIR));
} else if (attribute.startsWith("equipment.chestplate") || attribute.startsWith("equipment.chest")) {
Deprecations.entityEquipmentSubtags.warn(attribute.context);
attribute.fulfill(1);
ItemStack chestplate = equipment.getChestplate();
return new ItemTag(chestplate != null ? chestplate : new ItemStack(Material.AIR));
} else if (attribute.startsWith("equipment.helmet") || attribute.startsWith("equipment.head")) {
Deprecations.entityEquipmentSubtags.warn(attribute.context);
attribute.fulfill(1);
ItemStack helmet = equipment.getHelmet();
return new ItemTag(helmet != null ? helmet : new ItemStack(Material.AIR));
} else if (attribute.startsWith("equipment.leggings") || attribute.startsWith("equipment.legs")) {
Deprecations.entityEquipmentSubtags.warn(attribute.context);
attribute.fulfill(1);
ItemStack leggings = equipment.getLeggings();
return new ItemTag(leggings != null ? leggings : new ItemStack(Material.AIR));
}
return object.entity.getEquipment();
});
// <--[tag]
// @attribute <EntityTag.equipment_map>
// @returns MapTag
// @mechanism EntityTag.equipment
// @group inventory
// @description
// Returns a MapTag containing the entity's equipment.
// Output keys are boots, leggings, chestplate, helmet.
// Air items will be left out of the map.
// -->
PropertyParser.<EntityEquipment, MapTag>registerTag(MapTag.class, "equipment_map", (attribute, object) -> {
MapTag output = new MapTag();
org.bukkit.inventory.EntityEquipment equip = object.entity.getLivingEntity().getEquipment();
InventoryTag.addToMapIfNonAir(output, "boots", equip.getBoots());
InventoryTag.addToMapIfNonAir(output, "leggings", equip.getLeggings());
InventoryTag.addToMapIfNonAir(output, "chestplate", equip.getChestplate());
InventoryTag.addToMapIfNonAir(output, "helmet", equip.getHelmet());
return output;
});
}
use of com.denizenscript.denizen.objects.ItemTag in project Denizen-For-Bukkit by DenizenScript.
the class EntityFirework method getPropertyString.
@Override
public String getPropertyString() {
ItemStack item = new ItemStack(Material.FIREWORK_ROCKET);
item.setItemMeta(((Firework) firework.getBukkitEntity()).getFireworkMeta());
return new ItemTag(item).identify();
}
use of com.denizenscript.denizen.objects.ItemTag in project Denizen-For-Bukkit by DenizenScript.
the class ItemChargedProjectile method adjust.
@Override
public void adjust(Mechanism mechanism) {
// -->
if (mechanism.matches("charged_projectiles")) {
CrossbowMeta meta = (CrossbowMeta) item.getItemMeta();
meta.setChargedProjectiles(null);
for (ItemTag projectile : mechanism.valueAsType(ListTag.class).filter(ItemTag.class, mechanism.context)) {
try {
meta.addChargedProjectile(projectile.getItemStack());
} catch (IllegalArgumentException e) {
mechanism.echoError("Charged crossbow projectiles may only be arrows or fireworks!");
}
}
item.setItemMeta(meta);
}
// -->
if (mechanism.matches("add_charged_projectile") && mechanism.requireObject(ItemTag.class)) {
CrossbowMeta meta = (CrossbowMeta) item.getItemMeta();
try {
meta.addChargedProjectile(mechanism.valueAsType(ItemTag.class).getItemStack());
} catch (IllegalArgumentException e) {
mechanism.echoError("Charged crossbow projectiles may only be arrows or fireworks!");
}
item.setItemMeta(meta);
}
// -->
if (mechanism.matches("remove_charged_projectiles")) {
CrossbowMeta meta = (CrossbowMeta) item.getItemMeta();
meta.setChargedProjectiles(null);
item.setItemMeta(meta);
}
}
use of com.denizenscript.denizen.objects.ItemTag in project Denizen-For-Bukkit by DenizenScript.
the class ItemChargedProjectile method getChargedProjectiles.
public ListTag getChargedProjectiles() {
CrossbowMeta meta = (CrossbowMeta) item.getItemMeta();
ListTag list = new ListTag();
if (!meta.hasChargedProjectiles()) {
return list;
}
for (ItemStack projectile : meta.getChargedProjectiles()) {
list.addObject(new ItemTag(projectile));
}
return list;
}
Aggregations