Search in sources :

Example 51 with ElementTag

use of com.denizenscript.denizencore.objects.core.ElementTag in project Denizen-For-Bukkit by DenizenScript.

the class ItemBook method getBookMap.

public MapTag getBookMap() {
    MapTag outMap = new MapTag();
    BookMeta bookInfo = (BookMeta) item.getItemMeta();
    if (item.getBukkitMaterial().equals(Material.WRITTEN_BOOK) && bookInfo.hasAuthor() && bookInfo.hasTitle()) {
        outMap.putObject("author", new ElementTag(bookInfo.getAuthor(), true));
        outMap.putObject("title", new ElementTag(bookInfo.getTitle(), true));
    }
    if (bookInfo.hasPages()) {
        List<BaseComponent[]> pages = bookInfo.spigot().getPages();
        ListTag pageList = new ListTag(pages.size());
        for (BaseComponent[] page : pages) {
            pageList.addObject(new ElementTag(FormattedTextHelper.stringify(page, ChatColor.BLACK), true));
        }
        outMap.putObject("pages", pageList);
    }
    return outMap;
}
Also used : BaseComponent(net.md_5.bungee.api.chat.BaseComponent) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) BookMeta(org.bukkit.inventory.meta.BookMeta) ListTag(com.denizenscript.denizencore.objects.core.ListTag) MapTag(com.denizenscript.denizencore.objects.core.MapTag)

Example 52 with ElementTag

use of com.denizenscript.denizencore.objects.core.ElementTag in project Denizen-For-Bukkit by DenizenScript.

the class ItemAttributeNBT method adjust.

@Override
public void adjust(Mechanism mechanism) {
    if (mechanism.matches("nbt_attributes")) {
        Deprecations.legacyAttributeProperties.warn(mechanism.context);
        if (item.getMaterial().getMaterial() == Material.AIR) {
            mechanism.echoError("Cannot apply NBT to AIR!");
            return;
        }
        ListTag list = mechanism.valueAsType(ListTag.class);
        ItemStack itemStack = item.getItemStack();
        itemStack = CustomNBT.clearNBT(itemStack, CustomNBT.KEY_ATTRIBUTES);
        for (String string : list) {
            String[] split = string.split("/");
            if (split.length != 4) {
                mechanism.echoError("Invalid nbt_attributes input: must have 4 values per attribute.");
                continue;
            }
            String attribute = EscapeTagBase.unEscape(split[0]);
            String slot = EscapeTagBase.unEscape(split[1]);
            int op = new ElementTag(split[2]).asInt();
            double amt = new ElementTag(split[3]).asDouble();
            itemStack = CustomNBT.addAttribute(itemStack, attribute, slot, op, amt);
        }
        item.setItemStack(itemStack);
    }
}
Also used : ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) ItemStack(org.bukkit.inventory.ItemStack) ListTag(com.denizenscript.denizencore.objects.core.ListTag)

Example 53 with ElementTag

use of com.denizenscript.denizencore.objects.core.ElementTag in project Denizen-For-Bukkit by DenizenScript.

the class ItemEnchantments method getObjectAttribute.

@Override
public ObjectTag getObjectAttribute(Attribute attribute) {
    if (attribute == null) {
        return null;
    }
    // -->
    if (attribute.startsWith("is_enchanted")) {
        return new ElementTag(getEnchantments().size() > 0).getObjectAttribute(attribute.fulfill(1));
    }
    if (attribute.startsWith("enchantments.with_levels")) {
        Deprecations.itemEnchantmentTags.warn(attribute.context);
        Set<Map.Entry<Enchantment, Integer>> enchantments = getEnchantments();
        ListTag enchants = new ListTag();
        for (Map.Entry<Enchantment, Integer> enchantment : enchantments) {
            enchants.add(new EnchantmentTag(enchantment.getKey()).getCleanName() + "," + enchantment.getValue());
        }
        return enchants.getObjectAttribute(attribute.fulfill(2));
    }
    if (attribute.startsWith("enchantments.levels")) {
        Deprecations.itemEnchantmentTags.warn(attribute.context);
        Set<Map.Entry<Enchantment, Integer>> enchantments = getEnchantments();
        ListTag enchants = new ListTag();
        for (Map.Entry<Enchantment, Integer> enchantment : enchantments) {
            enchants.add(String.valueOf(enchantment.getValue()));
        }
        return enchants.getObjectAttribute(attribute.fulfill(2));
    }
    if (attribute.startsWith("enchantments.level") && attribute.hasContext(2)) {
        Deprecations.itemEnchantmentTags.warn(attribute.context);
        Set<Map.Entry<Enchantment, Integer>> enchantments = getEnchantments();
        if (enchantments.size() > 0) {
            for (Map.Entry<Enchantment, Integer> enchantment : enchantments) {
                if (enchantment.getKey().getName().equalsIgnoreCase(attribute.getContext(2)) || new EnchantmentTag(enchantment.getKey()).getCleanName().equalsIgnoreCase(attribute.getContext(2))) {
                    return new ElementTag(enchantment.getValue()).getObjectAttribute(attribute.fulfill(2));
                }
            }
        }
        return new ElementTag(0).getObjectAttribute(attribute.fulfill(2));
    }
    // -->
    if (attribute.startsWith("enchantment_types")) {
        Set<Map.Entry<Enchantment, Integer>> enchantments = getEnchantments();
        ListTag enchants = new ListTag();
        for (Map.Entry<Enchantment, Integer> enchantment : enchantments) {
            enchants.addObject(new EnchantmentTag(enchantment.getKey()));
        }
        return enchants.getObjectAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("enchantments")) {
        Deprecations.itemEnchantmentsLegacy.warn(attribute.context);
        Set<Map.Entry<Enchantment, Integer>> enchantments = getEnchantments();
        ListTag enchants = new ListTag();
        for (Map.Entry<Enchantment, Integer> enchantment : enchantments) {
            enchants.add(new EnchantmentTag(enchantment.getKey()).getCleanName());
        }
        return enchants.getObjectAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("enchantment_map")) {
        return getEnchantmentMap().getObjectAttribute(attribute.fulfill(1));
    }
    return null;
}
Also used : ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) EnchantmentTag(com.denizenscript.denizen.objects.EnchantmentTag) Enchantment(org.bukkit.enchantments.Enchantment) ListTag(com.denizenscript.denizencore.objects.core.ListTag)

Example 54 with ElementTag

use of com.denizenscript.denizencore.objects.core.ElementTag in project Denizen-For-Bukkit by DenizenScript.

the class ItemNBT method getObjectAttribute.

@Override
public ObjectTag getObjectAttribute(Attribute attribute) {
    if (attribute == null) {
        return null;
    }
    if (attribute.startsWith("has_nbt")) {
        Deprecations.itemNbt.warn(attribute.context);
        return new ElementTag(CustomNBT.hasCustomNBT(item.getItemStack(), attribute.getParam(), CustomNBT.KEY_DENIZEN)).getObjectAttribute(attribute.fulfill(1));
    }
    if (attribute.startsWith("nbt_keys")) {
        Deprecations.itemNbt.warn(attribute.context);
        return new ListTag(CustomNBT.listNBT(item.getItemStack(), CustomNBT.KEY_DENIZEN)).getObjectAttribute(attribute.fulfill(1));
    }
    if (attribute.matches("nbt")) {
        Deprecations.itemNbt.warn(attribute.context);
        if (!attribute.hasParam()) {
            ListTag list = getNBTDataList();
            if (list == null) {
                return null;
            }
            return list.getObjectAttribute(attribute.fulfill(1));
        }
        String res = CustomNBT.getCustomNBT(item.getItemStack(), attribute.getParam(), CustomNBT.KEY_DENIZEN);
        if (res == null) {
            return null;
        }
        return new ElementTag(res).getObjectAttribute(attribute.fulfill(1));
    }
    return null;
}
Also used : ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) ListTag(com.denizenscript.denizencore.objects.core.ListTag)

Example 55 with ElementTag

use of com.denizenscript.denizencore.objects.core.ElementTag in project Denizen-For-Bukkit by DenizenScript.

the class ItemSpawnerRange method getObjectAttribute.

@Override
public ObjectTag getObjectAttribute(Attribute attribute) {
    if (attribute == null) {
        return null;
    }
    // -->
    if (attribute.startsWith("spawner_range")) {
        BlockStateMeta meta = (BlockStateMeta) item.getItemMeta();
        CreatureSpawner state = (CreatureSpawner) meta.getBlockState();
        return new ElementTag(state.getSpawnRange()).getObjectAttribute(attribute.fulfill(1));
    }
    return null;
}
Also used : BlockStateMeta(org.bukkit.inventory.meta.BlockStateMeta) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) CreatureSpawner(org.bukkit.block.CreatureSpawner)

Aggregations

ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)237 ListTag (com.denizenscript.denizencore.objects.core.ListTag)86 EntityTag (com.denizenscript.denizen.objects.EntityTag)66 LocationTag (com.denizenscript.denizen.objects.LocationTag)49 PlayerTag (com.denizenscript.denizen.objects.PlayerTag)48 InvalidArgumentsException (com.denizenscript.denizencore.exceptions.InvalidArgumentsException)43 DurationTag (com.denizenscript.denizencore.objects.core.DurationTag)40 List (java.util.List)40 Argument (com.denizenscript.denizencore.objects.Argument)28 Player (org.bukkit.entity.Player)28 MapTag (com.denizenscript.denizencore.objects.core.MapTag)27 EventHandler (org.bukkit.event.EventHandler)26 NPCTag (com.denizenscript.denizen.objects.NPCTag)24 ObjectTag (com.denizenscript.denizencore.objects.ObjectTag)22 ItemTag (com.denizenscript.denizen.objects.ItemTag)19 ScriptTag (com.denizenscript.denizencore.objects.core.ScriptTag)18 ArrayList (java.util.ArrayList)16 Entity (org.bukkit.entity.Entity)16 MaterialTag (com.denizenscript.denizen.objects.MaterialTag)12 ScriptEntry (com.denizenscript.denizencore.scripts.ScriptEntry)12