Solved How to make a list in .yml file?

Discussion in 'Spigot Plugin Development' started by DracoCookie23, Jun 19, 2021.

  1. I wan't something like this:

    Code (YAML):
    name:
          moneyNeeded
    : Value
          rankName
    : name
    i have tried this:
    Code (Java):
    f.setValue(name + "moneyNeeded", Value);
    f is a variable for FileBuilder. Here is FileBuilder:

    Code (Java):
    package dutil;

    import org.bukkit.configuration.ConfigurationSection;
    import org.bukkit.configuration.file.YamlConfiguration;

    import java.io.File;
    import java.io.IOException;
    import java.util.List;
    import java.util.Set;

    public class FileBuilder {
        private final File f;
        private final YamlConfiguration c;

        public FileBuilder(String FilePath, String FileName){
            this.f = new File(FilePath, FileName);
            if(!f.exists()){
                try {
                    f.createNewFile();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            this.c = YamlConfiguration.loadConfiguration(this.f);
        }

        public FileBuilder setValue(String ValuePath, Object Value){
            c.set(ValuePath, Value);

            return this;
        }

        public int getInt(String ValuePath){
            return c.getInt(ValuePath);
        }

        public String getString(String ValuePath){
            return c.getString(ValuePath);
        }

        public Boolean getBoolean(String ValuePath){
            return c.getBoolean(ValuePath);
        }

        public List<String> getStringList(String ValuePath){
            return c.getStringList(ValuePath);
        }

        public Set<String> getKeys(boolean deep){
            return c.getKeys(deep);
        }

        public Boolean exist(){
            return f.exists();
        }

        public Double getDouble(String ValuePath){
            return c.getDouble(ValuePath);
        }

        public ConfigurationSection getConfiguration(String Section){
            return c.getConfigurationSection(Section);
        }

        public Long getLong(String ValuePath){
            return c.getLong(ValuePath);
        }

        public FileBuilder save(){
            try {
                this.c.save(this.f);
            } catch (IOException e) {
            }
            return this;
        }
    }
     
    It doesn't work with the method i used
    If someone could help, please let me know!
     
  2. Code (Java):
    f.setValue(name + ".moneyNeeded", Value);
    or


    Code (Java):
    ConfigurationSection section = f.getConfiguration(name);
    section.set("moneyNeeded", Value);
     
    • Agree Agree x 1
  3. thanks it works!