For loop wont execute

Discussion in 'Plugin Development' started by ItsComits, Dec 20, 2017.

Thread Status:
Not open for further replies.
  1. Offline

    ItsComits

    Hello, I have been trying to figure out why the for loop won't execute. The for loop executes the first time but not the next. Here is my code:
    Code:
            String[] strings = configLine.split(",");
            String[] materialAndData = strings[1].split(":");
            String[] enchants = strings[4].split(" ");
    
            is = new ItemStack(Material.valueOf(materialAndData[0]), Integer.parseInt(strings[2]),
                    (short) Integer.parseInt(materialAndData[1]));
            ItemMeta im = is.getItemMeta();
            im.setDisplayName(strings[3].replaceAll("&", "ยง"));
           
            System.out.println("Enchants (" + enchants.length + "): " + enchants);
            for (int i1 = 0; i < enchants.length; i++) {
                String[] nameAndLevel = enchants[i1].split(":");
                System.out.println("Adding enchantment");
                im.addEnchant(Enchantment.getByName(nameAndLevel[0]), Integer.parseInt(nameAndLevel[1]), true);
            }
            is.setItemMeta(im);
            return is;
        }
    Also the debug:
    Code:
    [20:17:14 INFO]: Enchants (1): [Ljava.lang.String;@1e3fa0ac
    [20:17:14 INFO]: Adding enchantment
    [20:17:14 INFO]: Enchants (1): [Ljava.lang.String;@242e97be
    [20:17:14 INFO]: Enchants (1): [Ljava.lang.String;@11097871
    [20:17:14 INFO]: Enchants (1): [Ljava.lang.String;@4805ec46
    bump

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Dec 21, 2017
  2. Offline

    AdamDev

    @ItsComits
    Look back at your for loop code it says "int i1 = 0;" and then it says " i < enchants.length;". Try changing the "i" to "i1" and that should work
     
Thread Status:
Not open for further replies.

Share This Page