Search in sources :

Example 26 with ItemTag

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);
}
Also used : LocationTag(com.denizenscript.denizen.objects.LocationTag) ItemTag(com.denizenscript.denizen.objects.ItemTag) EventHandler(org.bukkit.event.EventHandler)

Example 27 with ItemTag

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;
    });
}
Also used : ObjectTag(com.denizenscript.denizencore.objects.ObjectTag) ItemStack(org.bukkit.inventory.ItemStack) ItemTag(com.denizenscript.denizen.objects.ItemTag) MapTag(com.denizenscript.denizencore.objects.core.MapTag)

Example 28 with ItemTag

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();
}
Also used : ItemStack(org.bukkit.inventory.ItemStack) ItemTag(com.denizenscript.denizen.objects.ItemTag)

Example 29 with ItemTag

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);
    }
}
Also used : ItemTag(com.denizenscript.denizen.objects.ItemTag) ListTag(com.denizenscript.denizencore.objects.core.ListTag) CrossbowMeta(org.bukkit.inventory.meta.CrossbowMeta)

Example 30 with ItemTag

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;
}
Also used : ItemStack(org.bukkit.inventory.ItemStack) ItemTag(com.denizenscript.denizen.objects.ItemTag) ListTag(com.denizenscript.denizencore.objects.core.ListTag) CrossbowMeta(org.bukkit.inventory.meta.CrossbowMeta)

Aggregations

ItemTag (com.denizenscript.denizen.objects.ItemTag)77 EventHandler (org.bukkit.event.EventHandler)35 ItemStack (org.bukkit.inventory.ItemStack)20 LocationTag (com.denizenscript.denizen.objects.LocationTag)19 EntityTag (com.denizenscript.denizen.objects.EntityTag)14 ListTag (com.denizenscript.denizencore.objects.core.ListTag)14 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)13 PlayerTag (com.denizenscript.denizen.objects.PlayerTag)9 Item (org.bukkit.entity.Item)7 Argument (com.denizenscript.denizencore.objects.Argument)6 List (java.util.List)6 InvalidArgumentsException (com.denizenscript.denizencore.exceptions.InvalidArgumentsException)5 ScriptTag (com.denizenscript.denizencore.objects.core.ScriptTag)5 HumanEntity (org.bukkit.entity.HumanEntity)5 Player (org.bukkit.entity.Player)5 InventoryTag (com.denizenscript.denizen.objects.InventoryTag)4 BukkitTagContext (com.denizenscript.denizen.tags.BukkitTagContext)4 DurationTag (com.denizenscript.denizencore.objects.core.DurationTag)4 ArrayList (java.util.ArrayList)4 MaterialTag (com.denizenscript.denizen.objects.MaterialTag)3