Solved Error with config list

Discussion in 'Spigot Plugin Development' started by erikgamer07, Feb 12, 2020.

  1. Hello! I have an error when I try to get all the objects of a list in a config. I have this code:
    Code (Java):
                        for(String generator : configc.getStringList("Generators.list")) {

                            Location loc = Main.getInstance().stringToLocation(world, configc.getString("Generators.list." + generator + ".loc"));
                            String type = configc.getString("Generators.list." + generator + ".type");
                            int level = configc.getInt("Generators.list." + generator + ".level");
                            Sign sign = (Sign) world.getBlockAt(Main.getInstance().stringToLocation(world, configc.getString("Generators.list." + generator + ".sign"))).getState();

                            gm.getGenerators().add(new Generator(loc, type, level, gm, sign));

                        }
    The config is:
    Code (YAML):
    Generators:
      list
    :
        hola
    :
          loc
    : 5050.0 12.0 -29.0 0.0 0.0
          type
    : iron
          level
    : 1
          sign
    : 5050.0 13.0 -29.0 0.0 0.0
        holab
    :
          loc
    : 5043.0 12.0 -18.0 0.0 0.0
          type
    : iron
          level
    : 2
          sign
    : 5043.0 13.0 -18.0 0.0 0.0
        holac
    :
          loc
    : 5033.0 15.0 -30.0 0.0 0.0
          type
    : gold
          level
    : 1
          sign
    : 5033.0 16.0 -30.0 0.0 0.0
        holad
    :
          loc
    : 5041.0 12.0 -38.0 0.0 0.0
          type
    : diamond
          level
    : 3
          sign
    : 5041.0 13.0 -38.0 0.0 0.0
        holae
    :
          loc
    : 5040.0 12.0 -24.0 0.0 0.0
          type
    : iron
          level
    : 0
          sign
    : 5040.0 13.0 -24.0 0.0 0.0
    There are 5 objects in the config, and I tried with debug messages and the code don't arrives to that for()
    Why I have this problem, and how can I fix it? Thanks!
     
  2. SteelPhoenix

    Moderator

    configc.getStringList("Generators.list")
    It's a section, not a list.
     
  3. I don't understand.
     
  4. You try to get stringlist of section, that is not a list of strings.


    Code (YAML):
    //StringList
    list
    :
    - "bla"
    - "bla bla"
     
    you mast get Set of keys and values and work with that (or something like that, i doesn`t well work with YAML, sorry)
     
  5. Looks well, in a couple of minutes I try It.
     
  6. Thanks! Solved.