Solved Enchantment & Int Array - Can we get an enchantment to correspond with an int on the array?

Discussion in 'Spigot Plugin Development' started by iCodinqs, Apr 16, 2017.

  1. Allow me to elaborate on that -

    So an example of what I am trying to achieve here:
    Code (Text):
    new Enchantment[] {ENCHANTMENT.DIG_SPEED, ANOTHER ENCHANTMENT }
    new Int[] {3, 1}
    Basically, I want them to correspond so they produce this:
    Efficiency: 3
    Another Enchantment: 1

    Though when trying this, all of the enchants get set to the last int in the array (in this case: 1). Is there a way to put them so their corresponding with each other? EG Enchantment[1] and Int[1]. How would I do this?
     
  2. How about OOP?
     
  3. I am using OOP - Here are the class details:

    Trigger Method:
    Code (Text):
    Pickaxe(new Material[]{Material.DIAMOND_PICKAXE, Material.EMERALD, Material.STICK}, "┬žaEmerald Pickaxe", new Enchantment[] {Enchantment.DURABILITY, Enchantment.DIG_SPEED}, new int[] {4, 2});
    The method it calls:
    Code (Text):
    // Pickaxe Maker
        public void Pickaxe(Material[] Material, String itemName, Enchantment[] enchantments, int[] level) {

            ItemStack item = new ItemStack(Material[0]);
            ItemMeta itemMeta = item.getItemMeta();
            itemMeta.setDisplayName(itemName);
            for (Enchantment enchant: enchantments) {
                for (int lvl: level) {
                    itemMeta.addEnchant(enchant, lvl, true);
                }
            }
            item.setItemMeta(itemMeta);

            ShapedRecipe recipe = new ShapedRecipe(item);
            recipe.shape(new String[] {"AAA", " B ", " B "});
            recipe.setIngredient('A', Material[1]);
            recipe.setIngredient('B', Material[2]);
            Bukkit.addRecipe(recipe);

        }
    Should I not be using the for each loop?
     
  4. Senmori

    Senmori Retired Resource Staff
    Retired Patron

    • Agree Agree x 1