Help adding to config

Discussion in 'Plugin Development' started by Jackson12, Jul 10, 2015.

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

    Jackson12

    Hey, So this is my code

    Code:
    if(label.equalsIgnoreCase("addstaff") && player.hasPermission("staff.add")){
                if(args.length == 1){
                    if(Bukkit.getServer().getPlayer(args[0]) == null){
                        player.sendMessage(ChatColor.RED + "Please specify a player");
                    }else{
                        if((getConfig().get("Staff." + args[0]) == null)){
                            player.sendMessage(ChatColor.GOLD + "You have successfully added " + ChatColor.GREEN + args[0]);
                            getConfig().set("Staff." + args[0], getConfig().getInt("Staff." + args[0]));
                            saveConfig();
                        }
                    }
                }else{
                    player.sendMessage(ChatColor.RED + "Please specify a name");
                }
            }
    I can't figure out why it isn't adding the players name that i specify to the config, Thanks for any help.
     
  2. Offline

    benjfb1

    I have got your problem sorted:
    It is setting it to null because you are trying to set it to something that doesn't exist.
    Code:
    getConfig().set("Staff."+ args[0], getConfig().getInt("Staff."+ args[0]));
    you are checking if it is null before you run to code so getConfig().getInt("Staff."+ args[0])); would equal nothing

    EDIT: You would have to also reloadConfig() so it updates the config without you having to reload or restart the plugin or server
     
    Last edited: Jul 10, 2015
  3. Offline

    Jackson12

    @benjfb1 I don't see how i could fix it

    EDIT: I fixed it, I just did this
    Code:
    if((getConfig().get("Staff." + args[0]) != null)){
                            player.sendMessage(ChatColor.RED + "Player already listed");
                        }else{
                            player.sendMessage(ChatColor.GOLD + "You have successfully added " + ChatColor.GREEN + args[0]);
                            getConfig().set("Staff." + args[0], getConfig().getInt("Staff." + args[0]));
                            saveConfig();
                            reloadConfig();
                        }
                    }
     
    Last edited: Jul 10, 2015
  4. Offline

    benjfb1

    You are setting the path "Staff."+ args[0] to it's self. Can you please provide the code and a detailed description of what you want to do for further help so i can fix up your code.
     
  5. Offline

    Jackson12

    Thanks for your help, But i figured it out.
     
Thread Status:
Not open for further replies.

Share This Page