cast string to enchant

Discussion in 'Plugin Development' started by Jeff.Halbert, Jun 24, 2012.

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

    Jeff.Halbert

    how can I cast Enchantment onto the String value of the name? also, how can I run a check to see if that item is safe to have that enchantment?
     
  2. Offline

    Njol

  3. Offline

    ItsHarry

    Learn to use the API.

    Enchantment.getName()
     
  4. Offline

    Jeff.Halbert

    alright, i worded that wrong. how can i cast to Enchantment FROM a string? and check if it's a safe enchant for the item?
     
  5. Offline

    Darq

    Enchantment.getByName();
    Enchantment.canEnchantItem();
    Still didn't look at the API docs, huh? Cool.

     
  6. Offline

    Jeff.Halbert

    i guess I just don't get it, cause the docs isn't making anything click no matter how many times i read em.... maybe this will help, here's my code.... and my errors...
    Code:
        public static void giveKit(KitKat plugin, Player player, String kitName) {
            List<String> itemList = plugin.getConfig().getStringList("kits." + kitName + ".items");
            ListIterator<String> it = itemList.listIterator();
            if (it.hasNext()) {
                while (it.hasNext()) {
                    String[] item = it.next().split(" ");
                    int id = Integer.parseInt(item[0]);
                    short meta = (short) Integer.parseInt(item[1]);
                    int amount = Integer.parseInt(item[2]);
                    ItemStack stack = new ItemStack(id, amount, meta);
                    if (!item[3].contains("none")) {
                        int level = Integer.parseInt(item[4]);
                        Enchantment enchant = Enchantment.getByName(item[3].toUpperCase());
                        stack.addEnchantment(enchant, level);
                    }
                    player.getInventory().addItem(stack);
                }
            }
        }
    Code:
    kits:
        tools:
            items:
            - 269 0 1 SILK_TOUCH 4
            - 270 0 1 none 0
            - 271 0 1 none 0
            - 290 0 1 none 0
            cooldown: 1200
    [​IMG]
     
  7. Offline

    Darq

    Well your error there is completely unrelated to what you were asking. You're getting that because you're trying to access an index in an array that doesn't exist.
     
Thread Status:
Not open for further replies.

Share This Page