Custom config not saving and getting from default.

Discussion in 'Plugin Development' started by dan14941, Apr 13, 2014.

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

    dan14941

    Im trying to make a custom config but its not working the file gets created but it wont load from default here is the code i used from my main class:
    Code:
    @Override
        public void onEnable()
        {
            String name = "[Companies]";
           
            logger.info(name + " loading...");
            logger.info(name + " Creating configs!");
           
            cData = new File(getDataFolder(), "company-data.yml");
            newCData = YamlConfiguration.loadConfiguration(cData);
            newCData.options().copyDefaults(true);
            saveCConfig();
           
            pData = new File(getDataFolder(), "player-data.yml");
            newPData = YamlConfiguration.loadConfiguration(pData);
            newPData.options().copyDefaults(true);
            savePConfig();
        }
     
    public void saveCConfig()
        {
            try
            {
                newCData.save(cData);
            }
            catch (Exception e)
            {
                e.printStackTrace();
            }
        }
        public void savePConfig()
        {
            try
            {
                newPData.save(pData);
            }
            catch (Exception e)
            {
                e.printStackTrace();
            }
        }
    then when i try add stuff it dosent work here is my code from my other class:
    Code:
    else if(args[0].equalsIgnoreCase("create") && player.hasPermission("companies.create"))
                {
                    if(args.length == 1)
                    {
                        player.sendMessage(prefix + ChatColor.RED + "/company create <company name>");
                    }
                    else if(args.length > 2)
                    {
                        player.sendMessage(prefix + ChatColor.RED + "/company create <company name>");
                    }
                    else if(args.length == 2)
                    {
                        if(plugin.newPData.getBoolean(player.getName() + ".company.in-company", true))
                        {
                            player.sendMessage(prefix + ChatColor.RED + "You are already in a company!");
                        }
                        else
                        {
                            plugin.newPData.set(player.getName() + "company.in-company", true);
                            plugin.newPData.set(player.getName() + "company.company", args[1]);
                            plugin.savePConfig();
                           
                            plugin.newCData.set("company." + args[1] + ".boss", player.getName());
                            plugin.saveCConfig();
                            player.sendMessage(prefix + ChatColor.GOLD + "You created the company: " + args[1]);
                        }
                    }
                }
    Please help

    bump i realy need help!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  2. Offline

    dan14941

    i would realy like to release a version of my plugin already plz i need help
     
  3. dan14941 "Doesn't work" in what way? It'll be much easier if you tell use exactly what wrong, that way we don't have to look at your code and guess all the things that could be "not working" :)
     
  4. Offline

    dan14941

    its not saving to default and its not loading things from the file AdamQpzm
     
Thread Status:
Not open for further replies.

Share This Page