Problems reading config.yml

Discussion in 'Plugin Development' started by Euphi_, Oct 11, 2011.

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

    Euphi_

    I'm still pretty new to this, i've gone to countless forums and cannot find an answer so i am finally posting for help.

    I want to read my config.yml and store each property as it's own array. here's my config

    Code:
    Teams:
      - 'Yellow'
      - 'Red'
      - 'Blue'
    
    Yellow:
      - 'player1'
      - 'player2'
    
    Red:
      - 'player3'
    
    Blue:
      - 'player4'
    now i am using getProperty() to read from config, but that only returns as an object and I cannot cast it as an array, or even as a string to split into an array.

    so how do i call configTeams = getProperty("Teams") and have configTeams[1] = Red?

    This is my snippet of code that is reading the config

    Code:
                 Configuration config = getConfiguration();
                 config.load();
                 Object configTeams = config.getProperty("Teams");
    
                 System.out.println("Teams are " + configTeams);

    I have also tried casting via

    Code:
    String[] array = objectToString(configTeams);
    
    String[] objectToString(Object pleasework){
              return pleasework;
    }
    but that gives me the same error as normal casting
     
  2. Offline

    nisovin

    You would use getStringList() in the old configuration classes, and getList() in the new ones.
     
  3. Offline

    Euphi_

    Awesome thank you.

    This is what i ended up with

    Code:
    List<String> test = null;
    
                 List<String> configTeams = config.getStringList("Teams", test);
     
                 Iterator<String> list=configTeams.iterator();
                while(list.hasNext())
                {
                  String value=(String)list.next();
                  System.out.println("Team :"+value);
                }
    the only thing i still dont understand is this

    List<String> test = null;
    List<String> configTeams = config.getStringList("Teams", test);

    it works fine, i just dont understand what the second argument in getStringList is used for, still works if I just set it to null. If it has a purpose i need to use could you let me know? otherwise thanks for the help :D
     
Thread Status:
Not open for further replies.

Share This Page