Saving Set to YAML file

Discussion in 'Spigot Plugin Development' started by DevRice, Jun 2, 2017.

  1. Hello again... I seem to continue to run into problems and I can't figure out how to solve them! This time, I have a Set that I am getting from a YAML file and then I'm trying to add something to it and then save it back to the file. I know, it's one of the most basic things but I can't seem to figure it out. I used it in another section in my plugin and it works fine, but it isn't working in this other section.

    Working:

    Code (Text):
    [...]
    Set<String> members = new HashSet<>(plugin.members.get(nameRef));
            if(!targetInvs.contains(nameRef)){
                members.add(target);
                inventoriesYML.saveMembers(inventoryName, members);
            }
            [...]

    Not Working:

    Code (Text):
    [...]
    Set<String> owners = new HashSet<>(plugin.owners.get(nameRef));
            if(!owners.contains(target)) {
                if (args[2].equalsIgnoreCase("owner")) {
                    owners.add(target);
                    inventoriesYML.saveOwners(inventoryName, owners);
                    return true;
                }
            }
            [...]
    saveMembers method:

    Code (Text):
    public void saveMembers(String name, Set<String> members){
            File datafolder = plugin.getDataFolder();
            File f = new File(datafolder, CONFIG_NAME);

            if ((conf == null) || (inventories == null))
                return;

            if (!helpers.saveSuccess(datafolder, f, CONFIG_NAME, conf))
                return;

            List<String> newMembers = new ArrayList<>(members);

            conf.set("inventories." + name + ".members", newMembers);

            try {
                getInventories().save(inventories);
            } catch (Exception e) {
                [...]
            }
        }
    saveOwners method:

    Code (Text):
    public void saveOwners(String name, Set<String> owners){
            File datafolder = plugin.getDataFolder();
            File f = new File(datafolder, CONFIG_NAME);

            if ((conf == null) || (inventories == null))
                return;

            if (!helpers.saveSuccess(datafolder, f, CONFIG_NAME, conf))
                return;

            List<String> newOwners = new ArrayList<>(owners);

            conf.set("inventories." + name + ".owners", newOwners);

            try {
                getInventories().save(inventories);
            } catch (Exception e) {
                [...]
            }
        }
    getInventories method:

    Code (Text):
    public FileConfiguration getInventories() {
            if (conf == null)
                reloadInventories();
            return conf;
        }

    Thank you for any help!
     
    #1 DevRice, Jun 2, 2017
    Last edited: Jun 2, 2017
  2. Can you show the method getInventories()#save()?
     
  3. I'll edit my original post to include that
     
  4. Anyone know how to resolve this?