getConfig().set wrongly sets config string

Discussion in 'Plugin Development' started by stimoze, Jul 13, 2016.

Thread Status:
Not open for further replies.
  1. So, i was updating my plugin HealingItem (I was adding configurable Health regeneration), everything worked, but wrongly...

    So i have this code what is actually working, but not in my case

    Code part
    Code:
            if (cmd.getName().equalsIgnoreCase("sethealth") && player.hasPermission("itemheal.set"))
            {
                if (args.length == 0)
                {
                    player.sendMessage(prefix + " " + "§ePlease specify a number from 1 to 20, typing bigger numbers than 20 it still heals you by 20 HP");
                }
                else if (args[0].equalsIgnoreCase("0"))
                {
                    player.sendMessage(prefix + " " + "§eYou disabled the healing of the item");
                }
                else if (args.length > 1)
                {
                    player.sendMessage(prefix + " " + "§cThis command can't handle 2 or more arguments");
                }
                else
                {
                    getConfig().set("healamount", args);
                    saveConfig();
                    reloadConfig();
                    player.sendMessage(prefix + " " + "§aHeal amount has been set to §b" + args[0] + "§a!");
                }  
            }
    It sets my healamount config string, but it looks like this:
    Code:
    healamount:
    - '5'
    It should be like this:
    Code:
    healamount: 5
    What should i use?
     
  2. Offline

    tylersyme

    getConfig().set("healamount", args);

    Take a look at the bolded text and you should be able to see your typo
     
    Sethburster likes this.
  3. Offline

    Sethburster

    Lol you beat me by 2 seconds.
     
    tylersyme likes this.
  4. Offline

    tylersyme

    Haha, nice :D
     
  5. I don't see any problems.
     
  6. @stimoze
    You are setting the entire array in there instead of an entry of it.
     
  7. Offline

    Hyper_

    Use the array accessor syntax, which is array[index];
    Remember that arrays are zero-indexed, meaning the first element's index would be zero, not one.
     
Thread Status:
Not open for further replies.

Share This Page