Search in sources :

Example 16 with MapTag

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

the class ItemRawNBT method adjust.

@Override
public void adjust(Mechanism mechanism) {
    // -->
    if (mechanism.matches("raw_nbt") && mechanism.requireObject(MapTag.class)) {
        MapTag input = mechanism.valueAsType(MapTag.class);
        setFullNBT(item, input, mechanism.context, true);
    }
}
Also used : MapTag(com.denizenscript.denizencore.objects.core.MapTag)

Example 17 with MapTag

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

the class ItemAttributeModifiers method adjust.

@Override
public void adjust(Mechanism mechanism) {
    // -->
    if (mechanism.matches("attribute_modifiers") && mechanism.requireObject(MapTag.class)) {
        Multimap<org.bukkit.attribute.Attribute, AttributeModifier> metaMap = LinkedHashMultimap.create();
        MapTag map = mechanism.valueAsType(MapTag.class);
        for (Map.Entry<StringHolder, ObjectTag> mapEntry : map.map.entrySet()) {
            org.bukkit.attribute.Attribute attr = org.bukkit.attribute.Attribute.valueOf(mapEntry.getKey().str.toUpperCase());
            for (ObjectTag listValue : CoreUtilities.objectToList(mapEntry.getValue(), mechanism.context)) {
                metaMap.put(attr, EntityAttributeModifiers.modiferForMap(attr, (MapTag) listValue));
            }
        }
        ItemMeta meta = item.getItemMeta();
        meta.setAttributeModifiers(metaMap);
        item.setItemMeta(meta);
    }
    // -->
    if (mechanism.matches("add_attribute_modifiers") && mechanism.requireObject(MapTag.class)) {
        ItemMeta meta = item.getItemMeta();
        MapTag input = mechanism.valueAsType(MapTag.class);
        for (Map.Entry<StringHolder, ObjectTag> subValue : input.map.entrySet()) {
            org.bukkit.attribute.Attribute attr = org.bukkit.attribute.Attribute.valueOf(subValue.getKey().str.toUpperCase());
            for (ObjectTag listValue : CoreUtilities.objectToList(subValue.getValue(), mechanism.context)) {
                meta.addAttributeModifier(attr, EntityAttributeModifiers.modiferForMap(attr, (MapTag) listValue));
            }
        }
        item.setItemMeta(meta);
    }
    // -->
    if (mechanism.matches("remove_attribute_modifiers") && mechanism.requireObject(ListTag.class)) {
        ItemMeta meta = item.getItemMeta();
        ArrayList<String> inputList = new ArrayList<>(mechanism.valueAsType(ListTag.class));
        for (String toRemove : new ArrayList<>(inputList)) {
            if (new ElementTag(toRemove).matchesEnum(org.bukkit.attribute.Attribute.class)) {
                inputList.remove(toRemove);
                org.bukkit.attribute.Attribute attr = org.bukkit.attribute.Attribute.valueOf(toRemove.toUpperCase());
                meta.removeAttributeModifier(attr);
            }
        }
        for (String toRemove : inputList) {
            UUID id = UUID.fromString(toRemove);
            Multimap<org.bukkit.attribute.Attribute, AttributeModifier> metaMap = meta.getAttributeModifiers();
            for (org.bukkit.attribute.Attribute attribute : metaMap.keys()) {
                for (AttributeModifier modifer : metaMap.get(attribute)) {
                    if (modifer.getUniqueId().equals(id)) {
                        meta.removeAttributeModifier(attribute, modifer);
                        break;
                    }
                }
            }
        }
        item.setItemMeta(meta);
    }
}
Also used : Attribute(com.denizenscript.denizencore.tags.Attribute) ArrayList(java.util.ArrayList) AttributeModifier(org.bukkit.attribute.AttributeModifier) ListTag(com.denizenscript.denizencore.objects.core.ListTag) MapTag(com.denizenscript.denizencore.objects.core.MapTag) StringHolder(com.denizenscript.denizencore.utilities.text.StringHolder) ObjectTag(com.denizenscript.denizencore.objects.ObjectTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) UUID(java.util.UUID) Map(java.util.Map) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Example 18 with MapTag

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

the class ItemAttributeModifiers method getAttributeModifiers.

public MapTag getAttributeModifiers() {
    ItemMeta meta = item.getItemMeta();
    if (meta == null) {
        return null;
    }
    MapTag map = new MapTag();
    Multimap<org.bukkit.attribute.Attribute, AttributeModifier> metaMap = meta.getAttributeModifiers();
    if (metaMap == null) {
        return map;
    }
    for (org.bukkit.attribute.Attribute attribute : metaMap.keys()) {
        Collection<AttributeModifier> modifiers = metaMap.get(attribute);
        if (modifiers.isEmpty()) {
            continue;
        }
        ListTag subList = new ListTag();
        for (AttributeModifier modifier : modifiers) {
            subList.addObject(EntityAttributeModifiers.mapify(modifier));
        }
        map.putObject(attribute.name(), subList);
    }
    return map;
}
Also used : Attribute(com.denizenscript.denizencore.tags.Attribute) AttributeModifier(org.bukkit.attribute.AttributeModifier) ListTag(com.denizenscript.denizencore.objects.core.ListTag) ItemMeta(org.bukkit.inventory.meta.ItemMeta) MapTag(com.denizenscript.denizencore.objects.core.MapTag)

Example 19 with MapTag

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

the class ItemBaseColor method setBaseColor.

private void setBaseColor(DyeColor color, TagContext context) {
    if (color == null && item.getBukkitMaterial() == Material.SHIELD) {
        ItemRawNBT property = ItemRawNBT.getFrom(item);
        MapTag nbt = property.getFullNBTMap();
        nbt.putObject("BlockEntityTag", null);
        property.setFullNBT(item, nbt, context, false);
        return;
    }
    ItemMeta itemMeta = item.getItemMeta();
    if (itemMeta instanceof BlockStateMeta) {
        Banner banner = (Banner) ((BlockStateMeta) itemMeta).getBlockState();
        banner.setBaseColor(color);
        banner.update();
        ((BlockStateMeta) itemMeta).setBlockState(banner);
    } else {
        ((BannerMeta) itemMeta).setBaseColor(color);
    }
    item.setItemMeta(itemMeta);
}
Also used : BlockStateMeta(org.bukkit.inventory.meta.BlockStateMeta) BannerMeta(org.bukkit.inventory.meta.BannerMeta) Banner(org.bukkit.block.Banner) MapTag(com.denizenscript.denizencore.objects.core.MapTag) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Example 20 with MapTag

use of com.denizenscript.denizencore.objects.core.MapTag 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)

Aggregations

MapTag (com.denizenscript.denizencore.objects.core.MapTag)46 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)30 ListTag (com.denizenscript.denizencore.objects.core.ListTag)23 ObjectTag (com.denizenscript.denizencore.objects.ObjectTag)22 ItemTag (com.denizenscript.denizen.objects.ItemTag)9 StringHolder (com.denizenscript.denizencore.utilities.text.StringHolder)8 ArrayList (java.util.ArrayList)5 Map (java.util.Map)5 ItemStack (org.bukkit.inventory.ItemStack)5 ColorTag (com.denizenscript.denizen.objects.ColorTag)4 DurationTag (com.denizenscript.denizencore.objects.core.DurationTag)3 Attributable (org.bukkit.attribute.Attributable)3 Attribute (org.bukkit.attribute.Attribute)3 AttributeInstance (org.bukkit.attribute.AttributeInstance)3 AttributeModifier (org.bukkit.attribute.AttributeModifier)3 ItemMeta (org.bukkit.inventory.meta.ItemMeta)3 FlaggableObject (com.denizenscript.denizencore.flags.FlaggableObject)2 Attribute (com.denizenscript.denizencore.tags.Attribute)2 ArmorStandMeta (com.destroystokyo.paper.inventory.meta.ArmorStandMeta)2 UUID (java.util.UUID)2