Search in sources :

Example 36 with ListTag

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

the class ItemPatterns method adjust.

@Override
public void adjust(Mechanism mechanism) {
    // -->
    if (mechanism.matches("patterns")) {
        List<Pattern> patterns = new ArrayList<>();
        ListTag list = mechanism.valueAsType(ListTag.class);
        List<String> split;
        for (String string : list) {
            try {
                split = CoreUtilities.split(string, '/', 2);
                patterns.add(new Pattern(DyeColor.valueOf(split.get(0).toUpperCase()), PatternType.valueOf(split.get(1).toUpperCase())));
            } catch (Exception e) {
                Debug.echoError("Could not apply pattern to banner: " + string);
            }
        }
        setPatterns(patterns);
    }
}
Also used : Pattern(org.bukkit.block.banner.Pattern) ArrayList(java.util.ArrayList) ListTag(com.denizenscript.denizencore.objects.core.ListTag)

Example 37 with ListTag

use of com.denizenscript.denizencore.objects.core.ListTag 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 38 with ListTag

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

the class ItemNBT method adjust.

@Override
public void adjust(Mechanism mechanism) {
    if (mechanism.matches("remove_nbt")) {
        Deprecations.itemNbt.warn(mechanism.context);
        if (item.getMaterial().getMaterial() == Material.AIR) {
            mechanism.echoError("Cannot apply NBT to AIR!");
            return;
        }
        ItemStack itemStack = item.getItemStack();
        List<String> list;
        if (mechanism.hasValue()) {
            list = mechanism.valueAsType(ListTag.class);
        } else {
            list = CustomNBT.listNBT(itemStack, CustomNBT.KEY_DENIZEN);
        }
        for (String string : list) {
            itemStack = CustomNBT.removeCustomNBT(itemStack, string, CustomNBT.KEY_DENIZEN);
        }
        item.setItemStack(itemStack);
    }
    if (mechanism.matches("nbt")) {
        Deprecations.itemNbt.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();
        for (String string : list) {
            String[] split = string.split("/", 2);
            itemStack = CustomNBT.addCustomNBT(itemStack, EscapeTagBase.unEscape(split[0]), EscapeTagBase.unEscape(split[1]), CustomNBT.KEY_DENIZEN);
        }
        item.setItemStack(itemStack);
    }
}
Also used : ItemStack(org.bukkit.inventory.ItemStack) ListTag(com.denizenscript.denizencore.objects.core.ListTag)

Example 39 with ListTag

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

the class ItemNBT method getNBTDataList.

public ListTag getNBTDataList() {
    ItemStack itemStack = item.getItemStack();
    List<String> nbtKeys = CustomNBT.listNBT(itemStack, CustomNBT.KEY_DENIZEN);
    if (nbtKeys != null && !nbtKeys.isEmpty()) {
        ListTag list = new ListTag();
        for (String key : nbtKeys) {
            list.add(EscapeTagBase.escape(key) + "/" + EscapeTagBase.escape(CustomNBT.getCustomNBT(itemStack, key, CustomNBT.KEY_DENIZEN)));
        }
        return list;
    }
    return null;
}
Also used : ItemStack(org.bukkit.inventory.ItemStack) ListTag(com.denizenscript.denizencore.objects.core.ListTag)

Example 40 with ListTag

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

the class EntityPotionEffects method registerTags.

public static void registerTags() {
    // <--[tag]
    // @attribute <EntityTag.list_effects>
    // @returns ListTag
    // @group attribute
    // @mechanism EntityTag.potion_effects
    // @deprecated use 'effects_data' instead
    // @description
    // Deprecated in favor of <@link tag EntityTag.effects_data>
    // -->
    PropertyParser.<EntityPotionEffects, ListTag>registerTag(ListTag.class, "list_effects", (attribute, object) -> {
        Deprecations.oldPotionEffects.warn(attribute.context);
        return object.getEffectsListTag();
    });
    // <--[tag]
    // @attribute <EntityTag.effects_data>
    // @returns ListTag(MapTag)
    // @group attribute
    // @mechanism EntityTag.potion_effects
    // @description
    // Returns the active potion effects on the entity, in the MapTag format of the mechanism.
    // -->
    PropertyParser.<EntityPotionEffects, ListTag>registerTag(ListTag.class, "effects_data", (attribute, object) -> {
        return object.getEffectsMapTag();
    });
    // <--[tag]
    // @attribute <EntityTag.has_effect[<effect>]>
    // @returns ElementTag(Boolean)
    // @group attributes
    // @mechanism EntityTag.potion_effects
    // @description
    // Returns whether the entity has a specified effect.
    // If no effect is specified, returns whether the entity has any effect.
    // The effect type must be from <@link url https://hub.spigotmc.org/javadocs/spigot/org/bukkit/potion/PotionEffectType.html>.
    // -->
    PropertyParser.<EntityPotionEffects, ElementTag>registerTag(ElementTag.class, "has_effect", (attribute, object) -> {
        boolean returnElement = false;
        if (attribute.hasParam()) {
            PotionEffectType effectType = PotionEffectType.getByName(attribute.getParam());
            if (effectType == null) {
                attribute.echoError("Invalid effect type specified: " + attribute.getParam());
                return null;
            }
            if (object.entity.isLivingEntity()) {
                returnElement = object.entity.getLivingEntity().hasPotionEffect(effectType);
            } else if (object.isArrow()) {
                returnElement = object.getArrow().hasCustomEffect(effectType);
            }
        } else if (!object.getEffectsList().isEmpty()) {
            returnElement = true;
        }
        return new ElementTag(returnElement);
    });
}
Also used : PotionEffectType(org.bukkit.potion.PotionEffectType) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) ListTag(com.denizenscript.denizencore.objects.core.ListTag)

Aggregations

ListTag (com.denizenscript.denizencore.objects.core.ListTag)122 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)71 MapTag (com.denizenscript.denizencore.objects.core.MapTag)21 ItemStack (org.bukkit.inventory.ItemStack)18 EntityTag (com.denizenscript.denizen.objects.EntityTag)16 ObjectTag (com.denizenscript.denizencore.objects.ObjectTag)14 List (java.util.List)14 ItemTag (com.denizenscript.denizen.objects.ItemTag)13 PlayerTag (com.denizenscript.denizen.objects.PlayerTag)13 Player (org.bukkit.entity.Player)13 DurationTag (com.denizenscript.denizencore.objects.core.DurationTag)12 LocationTag (com.denizenscript.denizen.objects.LocationTag)11 NPCTag (com.denizenscript.denizen.objects.NPCTag)9 InvalidArgumentsException (com.denizenscript.denizencore.exceptions.InvalidArgumentsException)9 ArrayList (java.util.ArrayList)9 ScriptTag (com.denizenscript.denizencore.objects.core.ScriptTag)8 MaterialTag (com.denizenscript.denizen.objects.MaterialTag)7 ScriptEntry (com.denizenscript.denizencore.scripts.ScriptEntry)7 NPC (net.citizensnpcs.api.npc.NPC)7 Entity (org.bukkit.entity.Entity)7