Search in sources :

Example 6 with MCItemMeta

use of com.laytonsmith.abstraction.MCItemMeta in project CommandHelper by EngineHub.

the class BukkitMCItemFactory method asMetaFor.

@Override
public MCItemMeta asMetaFor(MCItemMeta meta, MCMaterial material) {
    ItemMeta bmeta = ((BukkitMCItemMeta) meta).asItemMeta();
    Material bmat = (Material) material.getHandle();
    return BukkitConvertor.BukkitGetCorrectMeta(f.asMetaFor(bmeta, bmat));
}
Also used : MCMaterial(com.laytonsmith.abstraction.blocks.MCMaterial) Material(org.bukkit.Material) ItemMeta(org.bukkit.inventory.meta.ItemMeta) MCItemMeta(com.laytonsmith.abstraction.MCItemMeta)

Example 7 with MCItemMeta

use of com.laytonsmith.abstraction.MCItemMeta in project CommandHelper by EngineHub.

the class InventoryManagement method IsMatch.

/**
 * Gets whether or not the two items are a match based on the given item array map.
 *
 * @param map The original item array map of what to compare
 * @param is The MCItemStack to compare all other items with, converted from the item array map
 * @param iis The current MCItemStack we're comparing
 * @param t
 * @return Whether or not the items are a match
 */
private static boolean IsMatch(CArray map, MCItemStack is, MCItemStack iis, Target t) {
    if (!is.getType().equals(iis.getType())) {
        return false;
    }
    if ((map == null || map.containsKey("data")) && is.getDurability() != iis.getDurability()) {
        return false;
    }
    if (map != null && map.containsKey("meta")) {
        Construct c = map.get("meta", t);
        if (c instanceof CNull) {
            if (iis.hasItemMeta()) {
                return false;
            }
        } else {
            if (!iis.hasItemMeta()) {
                return false;
            }
            CArray metamap = (CArray) c;
            MCItemMeta im = is.getItemMeta();
            MCItemMeta iim = iis.getItemMeta();
            if (metamap.containsKey("display")) {
                if (im.hasDisplayName()) {
                    if (!iim.hasDisplayName() || !im.getDisplayName().equals(iim.getDisplayName())) {
                        return false;
                    }
                } else if (iim.hasDisplayName()) {
                    return false;
                }
            }
            if (metamap.containsKey("lore") && im.hasLore() && !im.getLore().equals(iim.getLore())) {
                return false;
            }
            if (metamap.containsKey("enchants") && !im.getEnchants().equals(iim.getEnchants())) {
                return false;
            }
        }
    }
    return true;
}
Also used : CArray(com.laytonsmith.core.constructs.CArray) MCItemMeta(com.laytonsmith.abstraction.MCItemMeta) Construct(com.laytonsmith.core.constructs.Construct) CNull(com.laytonsmith.core.constructs.CNull)

Example 8 with MCItemMeta

use of com.laytonsmith.abstraction.MCItemMeta in project CommandHelper by EngineHub.

the class ObjectGenerator method itemMeta.

public Construct itemMeta(MCItemStack is, Target t) {
    if (!is.hasItemMeta()) {
        return CNull.NULL;
    } else {
        Construct display, lore;
        CArray ma = CArray.GetAssociativeArray(t);
        MCItemMeta meta = is.getItemMeta();
        if (meta.hasDisplayName()) {
            display = new CString(meta.getDisplayName(), t);
        } else {
            display = CNull.NULL;
        }
        if (meta.hasLore()) {
            lore = new CArray(t);
            for (String l : meta.getLore()) {
                ((CArray) lore).push(new CString(l, t), t);
            }
        } else {
            lore = CNull.NULL;
        }
        ma.set("display", display, t);
        ma.set("lore", lore, t);
        ma.set("enchants", enchants(meta.getEnchants(), t), t);
        ma.set("repair", new CInt(meta.getRepairCost(), t), t);
        // Version specific ItemMeta
        if (Static.getServer().getMinecraftVersion().gte(MCVersion.MC1_8)) {
            Set<MCItemFlag> itemFlags = meta.getItemFlags();
            CArray flagArray = new CArray(t);
            if (itemFlags.size() > 0) {
                for (MCItemFlag flag : itemFlags) {
                    flagArray.push(new CString(flag.name(), t), t);
                }
            }
            ma.set("flags", flagArray, t);
            if (Static.getServer().getMinecraftVersion().gte(MCVersion.MC1_11)) {
                ma.set("unbreakable", CBoolean.get(meta.isUnbreakable()), t);
            }
        }
        // Specific ItemMeta
        if (meta instanceof MCBlockStateMeta) {
            MCBlockState bs = ((MCBlockStateMeta) meta).getBlockState();
            if (bs instanceof MCShulkerBox) {
                MCShulkerBox mcsb = (MCShulkerBox) bs;
                MCInventory inv = mcsb.getInventory();
                CArray box = CArray.GetAssociativeArray(t);
                for (int i = 0; i < inv.getSize(); i++) {
                    Construct item = ObjectGenerator.GetGenerator().item(inv.getItem(i), t);
                    if (!(item instanceof CNull)) {
                        box.set(i, item, t);
                    }
                }
                ma.set("inventory", box, t);
            } else if (bs instanceof MCBanner) {
                MCBanner banner = (MCBanner) bs;
                CArray patterns = new CArray(t, banner.numberOfPatterns());
                for (MCPattern p : banner.getPatterns()) {
                    CArray pattern = CArray.GetAssociativeArray(t);
                    pattern.set("shape", new CString(p.getShape().toString(), t), t);
                    pattern.set("color", new CString(p.getColor().toString(), t), t);
                    patterns.push(pattern, t);
                }
                ma.set("patterns", patterns, t);
                MCDyeColor dyeColor = banner.getBaseColor();
                if (dyeColor != null) {
                    ma.set("basecolor", new CString(dyeColor.toString(), t), t);
                }
            } else if (bs instanceof MCCreatureSpawner) {
                MCCreatureSpawner mccs = (MCCreatureSpawner) bs;
                ma.set("spawntype", mccs.getSpawnedType().name());
            }
        } else if (meta instanceof MCFireworkEffectMeta) {
            MCFireworkEffectMeta mcfem = (MCFireworkEffectMeta) meta;
            MCFireworkEffect effect = mcfem.getEffect();
            if (effect == null) {
                ma.set("effect", CNull.NULL, t);
            } else {
                ma.set("effect", fireworkEffect(effect, t), t);
            }
        } else if (meta instanceof MCFireworkMeta) {
            MCFireworkMeta mcfm = (MCFireworkMeta) meta;
            CArray firework = CArray.GetAssociativeArray(t);
            firework.set("strength", new CInt(mcfm.getStrength(), t), t);
            CArray fe = new CArray(t);
            for (MCFireworkEffect effect : mcfm.getEffects()) {
                fe.push(fireworkEffect(effect, t), t);
            }
            firework.set("effects", fe, t);
            ma.set("firework", firework, t);
        } else if (meta instanceof MCLeatherArmorMeta) {
            CArray color = color(((MCLeatherArmorMeta) meta).getColor(), t);
            ma.set("color", color, t);
        } else if (meta instanceof MCBookMeta) {
            Construct title, author, pages;
            if (((MCBookMeta) meta).hasTitle()) {
                title = new CString(((MCBookMeta) meta).getTitle(), t);
            } else {
                title = CNull.NULL;
            }
            if (((MCBookMeta) meta).hasAuthor()) {
                author = new CString(((MCBookMeta) meta).getAuthor(), t);
            } else {
                author = CNull.NULL;
            }
            if (((MCBookMeta) meta).hasPages()) {
                pages = new CArray(t);
                for (String p : ((MCBookMeta) meta).getPages()) {
                    ((CArray) pages).push(new CString(p, t), t);
                }
            } else {
                pages = CNull.NULL;
            }
            ma.set("title", title, t);
            ma.set("author", author, t);
            ma.set("pages", pages, t);
        } else if (meta instanceof MCSkullMeta) {
            if (Static.getServer().getMinecraftVersion().gte(MCVersion.MC1_12_X)) {
                if (((MCSkullMeta) meta).hasOwner()) {
                    MCOfflinePlayer player = ((MCSkullMeta) meta).getOwningPlayer();
                    ma.set("owner", new CString(player.getName(), t), t);
                    ma.set("owneruuid", new CString(player.getUniqueID().toString(), t), t);
                } else {
                    ma.set("owner", CNull.NULL, t);
                    ma.set("owneruuid", CNull.NULL, t);
                }
            } else {
                if (((MCSkullMeta) meta).hasOwner()) {
                    ma.set("owner", new CString(((MCSkullMeta) meta).getOwner(), t), t);
                } else {
                    ma.set("owner", CNull.NULL, t);
                }
            }
        } else if (meta instanceof MCEnchantmentStorageMeta) {
            Construct stored;
            if (((MCEnchantmentStorageMeta) meta).hasStoredEnchants()) {
                stored = enchants(((MCEnchantmentStorageMeta) meta).getStoredEnchants(), t);
            } else {
                stored = CNull.NULL;
            }
            ma.set("stored", stored, t);
        } else if (meta instanceof MCPotionMeta) {
            MCPotionMeta potionmeta = (MCPotionMeta) meta;
            CArray effects = potions(potionmeta.getCustomEffects(), t);
            ma.set("potions", effects, t);
            if (Static.getServer().getMinecraftVersion().gte(MCVersion.MC1_9)) {
                MCPotionData potiondata = potionmeta.getBasePotionData();
                if (potiondata != null) {
                    ma.set("base", potionData(potiondata, t), t);
                }
            } else if (effects.size() > 0) {
                ma.set("main", ((CArray) effects.get(0, t)).get("id", t), t);
            }
        } else if (meta instanceof MCBannerMeta) {
            MCBannerMeta bannermeta = (MCBannerMeta) meta;
            CArray patterns = new CArray(t, bannermeta.numberOfPatterns());
            for (MCPattern p : bannermeta.getPatterns()) {
                CArray pattern = CArray.GetAssociativeArray(t);
                pattern.set("shape", new CString(p.getShape().toString(), t), t);
                pattern.set("color", new CString(p.getColor().toString(), t), t);
                patterns.push(pattern, t);
            }
            ma.set("patterns", patterns, t);
            MCDyeColor dyeColor = bannermeta.getBaseColor();
            if (dyeColor != null) {
                ma.set("basecolor", new CString(dyeColor.toString(), t), t);
            }
        } else if (meta instanceof MCSpawnEggMeta) {
            MCEntityType spawntype = ((MCSpawnEggMeta) meta).getSpawnedType();
            if (spawntype == null) {
                ma.set("spawntype", CNull.NULL, t);
            } else {
                ma.set("spawntype", new CString(spawntype.name(), t), t);
            }
        } else if (meta instanceof MCMapMeta && Static.getServer().getMinecraftVersion().gte(MCVersion.MC1_11)) {
            MCColor mapcolor = ((MCMapMeta) meta).getColor();
            Construct color;
            if (mapcolor == null) {
                color = CNull.NULL;
            } else {
                color = color(mapcolor, t);
            }
            ma.set("color", color, t);
        }
        return ma;
    }
}
Also used : MCBanner(com.laytonsmith.abstraction.blocks.MCBanner) MCEntityType(com.laytonsmith.abstraction.enums.MCEntityType) MCOfflinePlayer(com.laytonsmith.abstraction.MCOfflinePlayer) MCFireworkMeta(com.laytonsmith.abstraction.MCFireworkMeta) CArray(com.laytonsmith.core.constructs.CArray) MCLeatherArmorMeta(com.laytonsmith.abstraction.MCLeatherArmorMeta) MCSpawnEggMeta(com.laytonsmith.abstraction.MCSpawnEggMeta) CString(com.laytonsmith.core.constructs.CString) CString(com.laytonsmith.core.constructs.CString) MCPattern(com.laytonsmith.abstraction.MCPattern) MCFireworkEffect(com.laytonsmith.abstraction.MCFireworkEffect) MCPotionMeta(com.laytonsmith.abstraction.MCPotionMeta) MCMapMeta(com.laytonsmith.abstraction.MCMapMeta) MCColor(com.laytonsmith.abstraction.MCColor) MCItemFlag(com.laytonsmith.abstraction.enums.MCItemFlag) MCDyeColor(com.laytonsmith.abstraction.enums.MCDyeColor) MCBookMeta(com.laytonsmith.abstraction.MCBookMeta) MCBlockStateMeta(com.laytonsmith.abstraction.MCBlockStateMeta) MCFireworkEffectMeta(com.laytonsmith.abstraction.MCFireworkEffectMeta) MCBlockState(com.laytonsmith.abstraction.blocks.MCBlockState) MCBannerMeta(com.laytonsmith.abstraction.MCBannerMeta) MCInventory(com.laytonsmith.abstraction.MCInventory) MCSkullMeta(com.laytonsmith.abstraction.MCSkullMeta) MCItemMeta(com.laytonsmith.abstraction.MCItemMeta) MCPotionData(com.laytonsmith.abstraction.MCPotionData) MCEnchantmentStorageMeta(com.laytonsmith.abstraction.MCEnchantmentStorageMeta) CInt(com.laytonsmith.core.constructs.CInt) MCCreatureSpawner(com.laytonsmith.abstraction.MCCreatureSpawner) Construct(com.laytonsmith.core.constructs.Construct) MCShulkerBox(com.laytonsmith.abstraction.blocks.MCShulkerBox) CNull(com.laytonsmith.core.constructs.CNull)

Aggregations

MCItemMeta (com.laytonsmith.abstraction.MCItemMeta)8 MCItemStack (com.laytonsmith.abstraction.MCItemStack)4 CArray (com.laytonsmith.core.constructs.CArray)4 CNull (com.laytonsmith.core.constructs.CNull)4 Construct (com.laytonsmith.core.constructs.Construct)4 MCMaterial (com.laytonsmith.abstraction.blocks.MCMaterial)3 CString (com.laytonsmith.core.constructs.CString)3 ItemMeta (org.bukkit.inventory.meta.ItemMeta)3 MCBannerMeta (com.laytonsmith.abstraction.MCBannerMeta)2 MCBlockStateMeta (com.laytonsmith.abstraction.MCBlockStateMeta)2 MCBookMeta (com.laytonsmith.abstraction.MCBookMeta)2 MCCreatureSpawner (com.laytonsmith.abstraction.MCCreatureSpawner)2 MCEnchantment (com.laytonsmith.abstraction.MCEnchantment)2 MCEnchantmentStorageMeta (com.laytonsmith.abstraction.MCEnchantmentStorageMeta)2 MCFireworkEffectMeta (com.laytonsmith.abstraction.MCFireworkEffectMeta)2 MCFireworkMeta (com.laytonsmith.abstraction.MCFireworkMeta)2 MCInventory (com.laytonsmith.abstraction.MCInventory)2 MCLeatherArmorMeta (com.laytonsmith.abstraction.MCLeatherArmorMeta)2 MCMapMeta (com.laytonsmith.abstraction.MCMapMeta)2 MCPotionMeta (com.laytonsmith.abstraction.MCPotionMeta)2