Problem with yml file.

Discussion in 'Spigot Plugin Development' started by HoloGraphix-, May 29, 2015.

  1. Hi guys,

    I have a problem with my YML file, I want to retreive information, but I'm not doing it in the right way..

    Code (Text):
    fishing:
      fishcaught:
        1:10
        2:25
        3:50
        4:100
        5:200
        6:400
        7:800
        8:1500
        9:2500
        10:5000
    I thought I could get the code by doing this:
    Code (Text):
    Integer test = plugin.stats.getInt("fishing.fishcaught.5");
    But that didn't work.. Does anyone know how I can get one of those integers? Also I think that I didn't format it right..
     
  2. Have you tried to write a space between the key and the value?. I mean:

    Code (Text):
    fishing:
      fishcaught:
        1: 10
        2: 25
        3: 50
        4: 100
        5: 200
        6: 400
        7: 800
        8: 1500
        9: 2500
        10: 5000
    Maybe that's the error, I'm not sure. But it will be ok that you post the exception that you're getting
     
  3. I don't know if you have done this somewhere else but I would do it like so:
    Code (Text):

    //make the variables for your YAML configuration and your .yml file
    private static File fileName;
    private YamlConfiguration yamlConfig;

    //set your file to the .yml file
    fileName= new File(getDataFolder(), "fileName.yml");

    //make sure that file exists and if so load the YamlConfiguration into yamlConfig
    if(fileName.exists()){
            yamlConfig = YamlConfiguration.loadConfiguration(configFile);
       
            //now to do what you wanted to do and grab the number
            int temp = yamlConfig.getInt("fishing.fishcaught.5");
    }
     
    Edit* this is assuming that you are creating a yml file to hold this other than your normal config.yml
    also i wrote this outside of anywhere i can actually test for errors, sorry if u copy and paste and u run into issues.
     
  4. The getting something out of the config is working fine, it's just that array of integers..
     
  5. Found out what it was!

    Code (Text):
    fishing:
      fishcaught:
        '1': 10
        '2': 25
        '3': 50
        '4': 100
        '5': 200
        '6': 400
        '7': 800
        '8': 1500
        '9': 2500
        '10': 5000