Search in sources :

Example 1 with ItemData

use of com.elmakers.mine.bukkit.api.item.ItemData in project MagicPlugin by elBukkit.

the class MagicController method getItemKey.

@Override
public String getItemKey(ItemStack item) {
    if (item == null) {
        return "";
    }
    if (Wand.isUpgrade(item)) {
        return "upgrade:" + Wand.getWandTemplate(item);
    }
    if (Wand.isWand(item)) {
        return "wand:" + Wand.getWandTemplate(item);
    }
    if (Wand.isSpell(item)) {
        return "spell:" + Wand.getSpell(item);
    }
    if (Wand.isBrush(item)) {
        return "brush:" + Wand.getBrush(item);
    }
    ItemData mappedItem = getItem(item);
    if (mappedItem != null) {
        return mappedItem.getKey();
    }
    if (item.getType() == Material.SKULL_ITEM) {
        String url = InventoryUtils.getSkullURL(item);
        if (url != null && url.length() > 0) {
            return "skull_item:" + url;
        }
    }
    MaterialAndData material = new MaterialAndData(item);
    return material.getKey();
}
Also used : MaterialAndData(com.elmakers.mine.bukkit.block.MaterialAndData) ItemData(com.elmakers.mine.bukkit.api.item.ItemData)

Example 2 with ItemData

use of com.elmakers.mine.bukkit.api.item.ItemData in project MagicPlugin by elBukkit.

the class MagicController method createItem.

@Nullable
@Override
public ItemStack createItem(String magicItemKey, boolean brief) {
    ItemStack itemStack = null;
    if (magicItemKey == null) {
        return null;
    }
    // Check for amounts
    int amount = 1;
    if (magicItemKey.contains("@")) {
        String[] pieces = StringUtils.split(magicItemKey, '@');
        magicItemKey = pieces[0];
        try {
            amount = Integer.parseInt(pieces[1]);
        } catch (Exception ignored) {
        }
    }
    // Handle : or | as delimiter
    magicItemKey = magicItemKey.replace("|", ":");
    try {
        if (magicItemKey.contains("skull:") || magicItemKey.contains("skull_item:")) {
            magicItemKey = magicItemKey.replace("skull:", "skull_item:");
            MaterialAndData skullData = new MaterialAndData(magicItemKey);
            itemStack = skullData.getItemStack(amount);
        } else if (magicItemKey.contains("book:")) {
            String bookCategory = magicItemKey.substring(5);
            com.elmakers.mine.bukkit.api.spell.SpellCategory category = null;
            if (!bookCategory.isEmpty() && !bookCategory.equalsIgnoreCase("all")) {
                category = getCategory(bookCategory);
                if (category == null) {
                    return null;
                }
            }
            itemStack = getSpellBook(category, amount);
        } else if (skillPointItemsEnabled && magicItemKey.contains("sp:")) {
            String spAmount = magicItemKey.substring(3);
            itemStack = InventoryUtils.getURLSkull(skillPointIcon);
            ItemMeta meta = itemStack.getItemMeta();
            meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', messages.get("sp.name")).replace("$amount", spAmount));
            String spDescription = messages.get("sp.description");
            if (spDescription.length() > 0) {
                List<String> lore = new ArrayList<>();
                lore.add(ChatColor.translateAlternateColorCodes('&', spDescription));
                meta.setLore(lore);
            }
            itemStack.setItemMeta(meta);
            InventoryUtils.setMeta(itemStack, "sp", spAmount);
        } else if (magicItemKey.contains("spell:")) {
            String spellKey = magicItemKey.substring(6);
            itemStack = createSpellItem(spellKey, brief);
        } else if (magicItemKey.contains("wand:")) {
            String wandKey = magicItemKey.substring(5);
            com.elmakers.mine.bukkit.api.wand.Wand wand = createWand(wandKey);
            if (wand != null) {
                itemStack = wand.getItem();
            }
        } else if (magicItemKey.contains("upgrade:")) {
            String wandKey = magicItemKey.substring(8);
            com.elmakers.mine.bukkit.api.wand.Wand wand = createWand(wandKey);
            if (wand != null) {
                wand.makeUpgrade();
                itemStack = wand.getItem();
            }
        } else if (magicItemKey.contains("brush:")) {
            String brushKey = magicItemKey.substring(6);
            itemStack = createBrushItem(brushKey);
        } else if (magicItemKey.contains("item:")) {
            String itemKey = magicItemKey.substring(5);
            itemStack = createGenericItem(itemKey);
        } else if (items != null) {
            ItemData itemData = items.get(magicItemKey);
            if (itemData != null) {
                return itemData.getItemStack(amount);
            }
            MaterialAndData item = new MaterialAndData(magicItemKey);
            if (item.isValid()) {
                return item.getItemStack(amount);
            }
            com.elmakers.mine.bukkit.api.wand.Wand wand = createWand(magicItemKey);
            if (wand != null) {
                ItemStack wandItem = wand.getItem();
                if (wandItem != null) {
                    wandItem.setAmount(amount);
                }
                return wandItem;
            }
            // Spells may be using the | delimiter for levels
            // I am regretting overloading this delimiter!
            String spellKey = magicItemKey.replace(":", "|");
            itemStack = createSpellItem(spellKey, brief);
            if (itemStack != null) {
                itemStack.setAmount(amount);
                return itemStack;
            }
            itemStack = createBrushItem(magicItemKey);
            if (itemStack != null) {
                itemStack.setAmount(amount);
            }
        }
    } catch (Exception ex) {
        getLogger().log(Level.WARNING, "Error creating item: " + magicItemKey, ex);
    }
    return itemStack;
}
Also used : SpellCategory(com.elmakers.mine.bukkit.spell.SpellCategory) ArrayList(java.util.ArrayList) Wand(com.elmakers.mine.bukkit.wand.Wand) LostWand(com.elmakers.mine.bukkit.wand.LostWand) InvalidConfigurationException(org.bukkit.configuration.InvalidConfigurationException) IOException(java.io.IOException) ParseException(java.text.ParseException) MaterialAndData(com.elmakers.mine.bukkit.block.MaterialAndData) ItemStack(org.bukkit.inventory.ItemStack) ItemMeta(org.bukkit.inventory.meta.ItemMeta) ItemData(com.elmakers.mine.bukkit.api.item.ItemData) Nullable(javax.annotation.Nullable)

Example 3 with ItemData

use of com.elmakers.mine.bukkit.api.item.ItemData in project MagicPlugin by elBukkit.

the class MagicRecipe method getMatchType.

@SuppressWarnings("deprecation")
public MatchType getMatchType(ItemStack[] matrix) {
    if (recipe == null || matrix.length < 9)
        return MatchType.NONE;
    boolean[] rows = new boolean[3];
    boolean[] columns = new boolean[3];
    for (int matrixRow = 0; matrixRow < 3; matrixRow++) {
        for (int matrixColumn = 0; matrixColumn < 3; matrixColumn++) {
            int i = matrixRow * 3 + matrixColumn;
            ItemStack ingredient = matrix[i];
            if (ingredient != null && ingredient.getType() != Material.AIR) {
                rows[matrixRow] = true;
                break;
            }
        }
    }
    for (int matrixColumn = 0; matrixColumn < 3; matrixColumn++) {
        for (int matrixRow = 0; matrixRow < 3; matrixRow++) {
            int i = matrixRow * 3 + matrixColumn;
            ItemStack ingredient = matrix[i];
            if (ingredient != null && ingredient.getType() != Material.AIR) {
                columns[matrixColumn] = true;
                break;
            }
        }
    }
    String[] shape = recipe.getShape();
    if (shape == null || shape.length < 1)
        return MatchType.NONE;
    int shapeRow = 0;
    for (int matrixRow = 0; matrixRow < 3; matrixRow++) {
        if (!rows[matrixRow])
            continue;
        int shapeColumn = 0;
        for (int matrixColumn = 0; matrixColumn < 3; matrixColumn++) {
            if (!columns[matrixColumn])
                continue;
            if (shapeRow >= shape.length)
                return MatchType.NONE;
            String row = shape[shapeRow];
            char charAt = ' ';
            if (shapeColumn >= row.length()) {
                return MatchType.NONE;
            }
            charAt = row.charAt(shapeColumn);
            ItemData item = ingredients.get(charAt);
            int i = matrixRow * 3 + matrixColumn;
            ItemStack ingredient = matrix[i];
            if (ingredient != null && ingredient.getType() == Material.AIR) {
                ingredient = null;
            }
            if (item == null && ingredient == null) {
                shapeColumn++;
                continue;
            }
            if (item == null && ingredient != null)
                return MatchType.NONE;
            if (ingredient == null && item != null)
                return MatchType.NONE;
            if (ingredient.getType() != item.getType()) {
                return MatchType.NONE;
            }
            if (ingredient.getDurability() != item.getMaterialData().getData()) {
                return MatchType.NONE;
            }
            ItemMeta meta = item.getItemMeta();
            if (meta != null) {
                ItemMeta ingredientMeta = ingredient.getItemMeta();
                if (ingredientMeta == null) {
                    return MatchType.PARTIAL;
                }
                if (meta.hasDisplayName() && (!ingredientMeta.hasDisplayName() || !meta.getDisplayName().equals(ingredientMeta.getDisplayName()))) {
                    return MatchType.PARTIAL;
                }
                if (meta.hasLore() && (!ingredientMeta.hasLore() || !meta.getLore().equals(ingredientMeta.getLore()))) {
                    return MatchType.PARTIAL;
                }
            }
            shapeColumn++;
        }
        shapeRow++;
    }
    return MatchType.MATCH;
}
Also used : ItemStack(org.bukkit.inventory.ItemStack) ItemMeta(org.bukkit.inventory.meta.ItemMeta) ItemData(com.elmakers.mine.bukkit.api.item.ItemData)

Example 4 with ItemData

use of com.elmakers.mine.bukkit.api.item.ItemData in project MagicPlugin by elBukkit.

the class MagicController method getWorth.

@Nullable
@Override
public Double getWorth(ItemStack item) {
    String spellKey = Wand.getSpell(item);
    if (spellKey != null) {
        SpellTemplate spell = getSpellTemplate(spellKey);
        if (spell != null) {
            return spell.getWorth();
        }
    }
    int amount = item.getAmount();
    item.setAmount(1);
    ItemData configuredItem = items.get(item);
    item.setAmount(amount);
    if (configuredItem == null) {
        return null;
    }
    return configuredItem.getWorth() * amount;
}
Also used : SpellTemplate(com.elmakers.mine.bukkit.api.spell.SpellTemplate) ItemData(com.elmakers.mine.bukkit.api.item.ItemData) Nullable(javax.annotation.Nullable)

Example 5 with ItemData

use of com.elmakers.mine.bukkit.api.item.ItemData in project MagicPlugin by elBukkit.

the class ArmorStandProjectileAction method prepare.

@Override
public void prepare(CastContext context, ConfigurationSection parameters) {
    super.prepare(context, parameters);
    armorStandMarker = parameters.getBoolean("armor_stand_marker", true);
    armorStandInvisible = parameters.getBoolean("armor_stand_invisible", true);
    armorStandGravity = parameters.getBoolean("armor_stand_gravity", false);
    showArmorStandArms = parameters.getBoolean("armor_stand_arms", true);
    showArmorStandBaseplate = parameters.getBoolean("armor_stand_baseplate", false);
    smallArmorStand = parameters.getBoolean("armor_stand_small", false);
    adjustHeadPitch = parameters.getBoolean("orient_head", false);
    adjustArmPitch = parameters.getBoolean("orient_right_arm", false);
    unbreakableItems = parameters.getBoolean("unbreakable_items", false);
    visibleDelayTicks = parameters.getInt("visible_delay_ticks", 1);
    MageController controller = context.getController();
    ItemData itemType = controller.getOrCreateItem(parameters.getString("right_arm_item"));
    if (itemType != null) {
        rightArmItem = itemType.getItemStack(1);
        if (rightArmItem != null && unbreakableItems) {
            InventoryUtils.makeUnbreakable(rightArmItem);
        }
    }
    itemType = controller.getOrCreateItem(parameters.getString("helmet_item"));
    if (itemType != null) {
        helmetItem = itemType.getItemStack(1);
        if (helmetItem != null && unbreakableItems) {
            InventoryUtils.makeUnbreakable(InventoryUtils.makeReal(helmetItem));
        }
    }
    itemType = controller.getOrCreateItem(parameters.getString("chestplate_item"));
    if (itemType != null) {
        chestplateItem = itemType.getItemStack(1);
        if (chestplateItem != null && unbreakableItems) {
            InventoryUtils.makeUnbreakable(InventoryUtils.makeReal(chestplateItem));
        }
    }
    itemType = controller.getOrCreateItem(parameters.getString("leggings_item"));
    if (itemType != null) {
        leggingsItem = itemType.getItemStack(1);
        if (leggingsItem != null && unbreakableItems) {
            InventoryUtils.makeUnbreakable(InventoryUtils.makeReal(leggingsItem));
        }
    }
    itemType = controller.getOrCreateItem(parameters.getString("boots_item"));
    if (itemType != null) {
        bootsItem = itemType.getItemStack(1);
        if (bootsItem != null && unbreakableItems) {
            InventoryUtils.makeUnbreakable(InventoryUtils.makeReal(bootsItem));
        }
    }
}
Also used : MageController(com.elmakers.mine.bukkit.api.magic.MageController) ItemData(com.elmakers.mine.bukkit.api.item.ItemData)

Aggregations

ItemData (com.elmakers.mine.bukkit.api.item.ItemData)10 MageController (com.elmakers.mine.bukkit.api.magic.MageController)4 MaterialAndData (com.elmakers.mine.bukkit.block.MaterialAndData)3 ItemStack (org.bukkit.inventory.ItemStack)3 File (java.io.File)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Nullable (javax.annotation.Nullable)2 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)2 YamlConfiguration (org.bukkit.configuration.file.YamlConfiguration)2 ItemMeta (org.bukkit.inventory.meta.ItemMeta)2 SpellTemplate (com.elmakers.mine.bukkit.api.spell.SpellTemplate)1 Wand (com.elmakers.mine.bukkit.api.wand.Wand)1 SpellCategory (com.elmakers.mine.bukkit.spell.SpellCategory)1 LostWand (com.elmakers.mine.bukkit.wand.LostWand)1 Wand (com.elmakers.mine.bukkit.wand.Wand)1 ParseException (java.text.ParseException)1 InvalidConfigurationException (org.bukkit.configuration.InvalidConfigurationException)1 Player (org.bukkit.entity.Player)1 ShapedRecipe (org.bukkit.inventory.ShapedRecipe)1