Search in sources :

Example 26 with ItemMeta

use of org.bukkit.inventory.meta.ItemMeta in project Bukkit by Bukkit.

the class ItemStack method deserialize.

/**
     * Required method for configuration serialization
     *
     * @param args map to deserialize
     * @return deserialized item stack
     * @see ConfigurationSerializable
     */
public static ItemStack deserialize(Map<String, Object> args) {
    Material type = Material.getMaterial((String) args.get("type"));
    short damage = 0;
    int amount = 1;
    if (args.containsKey("damage")) {
        damage = ((Number) args.get("damage")).shortValue();
    }
    if (args.containsKey("amount")) {
        amount = (Integer) args.get("amount");
    }
    ItemStack result = new ItemStack(type, amount, damage);
    if (args.containsKey("enchantments")) {
        // Backward compatiblity, @deprecated
        Object raw = args.get("enchantments");
        if (raw instanceof Map) {
            Map<?, ?> map = (Map<?, ?>) raw;
            for (Map.Entry<?, ?> entry : map.entrySet()) {
                Enchantment enchantment = Enchantment.getByName(entry.getKey().toString());
                if ((enchantment != null) && (entry.getValue() instanceof Integer)) {
                    result.addUnsafeEnchantment(enchantment, (Integer) entry.getValue());
                }
            }
        }
    } else if (args.containsKey("meta")) {
        // We cannot and will not have meta when enchantments (pre-ItemMeta) exist
        Object raw = args.get("meta");
        if (raw instanceof ItemMeta) {
            result.setItemMeta((ItemMeta) raw);
        }
    }
    return result;
}
Also used : Material(org.bukkit.Material) Enchantment(org.bukkit.enchantments.Enchantment) LinkedHashMap(java.util.LinkedHashMap) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Example 27 with ItemMeta

use of org.bukkit.inventory.meta.ItemMeta in project Denizen-For-Bukkit by DenizenScript.

the class HeadCommand method execute.

@SuppressWarnings("unchecked")
@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
    List<dEntity> entities = (List<dEntity>) scriptEntry.getObject("entities");
    Element skin = scriptEntry.getElement("skin");
    dMaterial material = scriptEntry.getdObject("material");
    // Report to dB
    dB.report(scriptEntry, getName(), aH.debugObj("entities", entities.toString()) + (skin != null ? skin.debug() : "") + (material != null ? material.debug() : ""));
    ItemStack item = null;
    // Create head item with chosen skin, or item/skin
    if (skin != null) {
        item = new ItemStack(Material.SKULL_ITEM, 1, (byte) 3);
        ItemMeta itemMeta = item.getItemMeta();
        ((SkullMeta) itemMeta).setOwner(skin.asString().replaceAll("[pP]@", ""));
        item.setItemMeta(itemMeta);
    } else if (material != null) {
        item = new ItemStack(material.getMaterial());
    }
    for (dEntity entity : entities) {
        if (entity.isCitizensNPC()) {
            if (!entity.getDenizenNPC().getCitizen().hasTrait(Equipment.class)) {
                entity.getDenizenNPC().getCitizen().addTrait(Equipment.class);
            }
            Equipment trait = entity.getDenizenNPC().getCitizen().getTrait(Equipment.class);
            trait.set(1, item);
        } else if (entity.isPlayer()) {
            entity.getPlayer().getInventory().setHelmet(item);
        } else {
            if (entity.isLivingEntity() && entity.getLivingEntity().getEquipment() != null) {
                entity.getLivingEntity().getEquipment().setHelmet(item);
            } else {
                dB.echoError(scriptEntry.getResidingQueue(), entity.identify() + " is not a living entity!");
            }
        }
    }
}
Also used : net.aufdemrand.denizen.objects.dMaterial(net.aufdemrand.denizen.objects.dMaterial) Equipment(net.citizensnpcs.api.trait.trait.Equipment) net.aufdemrand.denizen.objects.dEntity(net.aufdemrand.denizen.objects.dEntity) Element(net.aufdemrand.denizencore.objects.Element) List(java.util.List) net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList) SkullMeta(org.bukkit.inventory.meta.SkullMeta) ItemStack(org.bukkit.inventory.ItemStack) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Example 28 with ItemMeta

use of org.bukkit.inventory.meta.ItemMeta in project Denizen-For-Bukkit by DenizenScript.

the class ItemFirework method adjust.

@Override
public void adjust(Mechanism mechanism) {
    if (mechanism.matches("firework")) {
        dList fireworks = mechanism.getValue().asType(dList.class);
        ItemMeta meta = item.getItemStack().getItemMeta();
        for (String effect : fireworks) {
            String[] data = effect.split(",");
            if (data.length == 9) {
                FireworkEffect.Builder builder = FireworkEffect.builder();
                builder.trail(new Element(data[0]).asBoolean());
                builder.flicker(new Element(data[1]).asBoolean());
                if (new Element(data[2]).matchesEnum(FireworkEffect.Type.values())) {
                    builder.with(FireworkEffect.Type.valueOf(data[2].toUpperCase()));
                } else {
                    dB.echoError("Invalid firework type '" + data[2] + "'");
                }
                builder.withColor(Color.fromRGB(new Element(data[3]).asInt(), new Element(data[4]).asInt(), new Element(data[5]).asInt()));
                builder.withFade(Color.fromRGB(new Element(data[6]).asInt(), new Element(data[7]).asInt(), new Element(data[8]).asInt()));
                FireworkEffect built = builder.build();
                if (meta instanceof FireworkMeta) {
                    ((FireworkMeta) meta).addEffect(built);
                } else {
                    ((FireworkEffectMeta) meta).setEffect(built);
                }
            } else if (data.length == 1) {
                if (meta instanceof FireworkMeta) {
                    ((FireworkMeta) meta).setPower(new Element(data[0]).asInt());
                } else {
                    dB.echoError("Cannot set the power of a firework effect!");
                }
            } else {
                dB.echoError("Invalid firework data '" + effect + "'");
            }
        }
        item.getItemStack().setItemMeta(meta);
    }
}
Also used : net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList) Element(net.aufdemrand.denizencore.objects.Element) FireworkMeta(org.bukkit.inventory.meta.FireworkMeta) FireworkEffectMeta(org.bukkit.inventory.meta.FireworkEffectMeta) FireworkEffect(org.bukkit.FireworkEffect) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Example 29 with ItemMeta

use of org.bukkit.inventory.meta.ItemMeta in project Denizen-For-Bukkit by DenizenScript.

the class ItemFlags method adjust.

@Override
public void adjust(Mechanism mechanism) {
    if (mechanism.matches("flags")) {
        ItemMeta meta = item.getItemStack().getItemMeta();
        meta.removeItemFlags(ItemFlag.values());
        dList new_flags = mechanism.getValue().asType(dList.class);
        for (String str : new_flags) {
            meta.addItemFlags(ItemFlag.valueOf(str.toUpperCase()));
        }
        item.getItemStack().setItemMeta(meta);
    }
}
Also used : net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Example 30 with ItemMeta

use of org.bukkit.inventory.meta.ItemMeta in project Denizen-For-Bukkit by DenizenScript.

the class ItemUnbreakable method adjust.

public void adjust(Mechanism mechanism) {
    // -->
    if (mechanism.matches("unbreakable") && mechanism.requireBoolean()) {
        ItemStack itemStack = item.getItemStack().clone();
        ItemMeta meta = itemStack.getItemMeta();
        meta.spigot().setUnbreakable(mechanism.getValue().asBoolean());
        itemStack.setItemMeta(meta);
        item.setItemStack(itemStack);
    }
}
Also used : ItemStack(org.bukkit.inventory.ItemStack) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Aggregations

ItemMeta (org.bukkit.inventory.meta.ItemMeta)47 ItemStack (org.bukkit.inventory.ItemStack)17 ArrayList (java.util.ArrayList)5 Enchantment (org.bukkit.enchantments.Enchantment)5 net.aufdemrand.denizencore.objects.dList (net.aufdemrand.denizencore.objects.dList)4 BookMeta (org.bukkit.inventory.meta.BookMeta)3 FireworkEffectMeta (org.bukkit.inventory.meta.FireworkEffectMeta)3 SkullMeta (org.bukkit.inventory.meta.SkullMeta)3 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 StringTag (net.aufdemrand.denizen.nms.util.jnbt.StringTag)2 Element (net.aufdemrand.denizencore.objects.Element)2 FireworkEffect (org.bukkit.FireworkEffect)2 Material (org.bukkit.Material)2 Banner (org.bukkit.block.Banner)2 BannerMeta (org.bukkit.inventory.meta.BannerMeta)2 BlockStateMeta (org.bukkit.inventory.meta.BlockStateMeta)2 EnchantmentStorageMeta (org.bukkit.inventory.meta.EnchantmentStorageMeta)2 LeatherArmorMeta (org.bukkit.inventory.meta.LeatherArmorMeta)2 RewardType (au.com.mineauz.minigames.minigame.reward.RewardType)1