custom config not saving for boolean value?

Discussion in 'Spigot Discussion' started by ieatdiamond, Jul 15, 2018.

  1. code where it happens to be changed
    Code (Text):
            if (getUserConfig(player).getBoolean("weapon_smith.first_time") == true) {
                System.out.println(getUserConfig(player).getBoolean("weapon_smith.first_time"));
                player.sendMessage(
                        "Welcome traveler, I am the weapon smith. I serve to teach you about the way of the swords. For every"
                                + " assignment you complete you get a reward, that being the ability to wear a sword of a higher teir.");
                player.sendMessage("");
                player.sendMessage("Your first assignment is to kill " + plugin.plConfig.getInt("sword_upgrades.stone")
                        + " mobs with a wooden sword, come back when you have!");
                getUserConfig(player).set("weapon_smith.first_time", false);
                System.out.println(getUserConfig(player).getBoolean("weapon_smith.first_time"));
                save(player);
    my save method
    Code (Text):
        public void save(Player p) {
            try {
                getUserConfig(p).save(getPlayerFile(p));
                System.out.println("SAVED");
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    it works perfectly fine for the int objects in there but when it comes to this boolean it wont change.
     
  2. Is it a custom YML? You would need to save a customYML to register it after every write.
    Code (Java):
    private void saveCustomYml(FileConfiguration ymlConfig, File ymlFile)
         {
             try
             {
                 ymlConfig.save(ymlFile);
             }
             catch (IOException e)
             {
                 e.printStackTrace();
             }
         }
    Usage would be:
    Code (Java):
    try
            {
             
                for (File file : new File(plugin.getDataFolder() +  File.separator
                        + "players").listFiles())
                {
                 
                    FileConfiguration customConfig = YamlConfiguration.loadConfiguration(file);
                 
                    //some code
                 
                    saveCustomYml(customConfig, file);
                 
                }
             
            }
            catch(Exception e)
            {
                plugin.getLogger().info("There are no saved player databases!");
            }

    EDIT:

    Sorry, I didn't see that you did save the code, I'll go through it again and try to see the error
     
  3. Also do send what the client is getting is the message: " "? Also do use String.valueOf(). One more thing if you're checking booleans in an if the "==" is not needed, you are comparing true with true. You can put it without the "==" it will work the same.