Solved Config problems...

Discussion in 'Plugin Development' started by Datdenkikniet, Dec 26, 2013.

Thread Status:
Not open for further replies.
  1. So, I am trying to make a minigame myself, and it involves serializing and deserializing to and from a config. The problem is, that I can't get the deserializing work. Could anyone explain to me what the best way to tackle it would be?
    For the serializing, I use this code:
    serializing to the config (open)

    Code:java
    1. public void saveArenas(CC config, ArrayList<Arena> arenas){
    2. CustomConfig c = new CustomConfig(plugin);
    3. for (Arena a: arenas){
    4. if (!c.getCustomConfig(config).contains("arenas")){
    5. c.getCustomConfig(config).addDefault("'arenas'", null);
    6. }
    7. if (!c.getCustomConfig(config).getStringList("arenas").contains(a.getName())){
    8. System.out.println("creating a new arena!");
    9. FileConfiguration cfg = c.getCustomConfig(config);
    10. cfg.addDefault("arenas."+ a.getName() +".corner1", LocationToString(a.getCorner1()));
    11. cfg.addDefault("arenas." + a.getName() + ".corner2", LocationToString(a.getCorner2()));
    12. cfg.addDefault("arenas." + a.getName() + ".lobbyCorner1", LocationToString(a.getLobbyCorner1()));
    13. cfg.addDefault("arenas." + a.getName() + ".lobbyCorner2", LocationToString(a.getLobbyCorner2()));
    14. int count1 = 0;
    15. for (Location loc: a.getTeam1Spawns()){
    16. count1 = count1 + 1;
    17. cfg.addDefault("arenas." + a.getName() + ".spawns1." + count1, LocationToString(loc));
    18. }
    19. int count =0;
    20. for (Location loc: a.getTeam2Spawns()){
    21. count = count + 1;
    22. cfg.addDefault("arenas." + a.getName() + ".spawns2." + count, LocationToString(loc));
    23. }
    24. cfg.options().copyDefaults(true);
    25. c.saveCustomConfig(config);
    26. return;
    27. }
    28. System.out.println("this arena already exists!");
    29. }
    30. c.saveCustomConfig(config);
    31. }

    and for the deserializing this is what I have so far:
    deserializing from the config (open)

    Code:java
    1. public void getArenasFromConfig(ArrayList<Arena> listToSaveArenasTo){
    2. CustomConfig c = new CustomConfig(plugin);
    3. FileConfiguration cfg = c.getCustomConfig(new CC("arenas"));
    4. int size = 0;
    5. System.out.println(cfg.getStringList("lol"));
    6. for (String s: cfg.getStringList("arenas")){
    7. size = size+1;
    8. System.out.println(s);
    9. Arena a = new Arena(s, null, null, null, null, null, null, null);
    10. listToSaveArenasTo.add(a);
    11. }
    12. }

    the main problem is that it can't find the StringList arenas for some reason.
    an example for the arenas.yml could be like this:
    example for the arenas.yml which I use (open)
    Code:
    arenas:
      lol:
        corner1: world, 4.0, 4.0, 4.0
        corner2: world, 4.0, 4.0, 4.0
        lobbyCorner1: world, 4.0, 4.0, 4.0
        lobbyCorner2: world, 4.0, 4.0, 4.0
        spawns1:
          '1': world, 4.0, 4.0, 4.0
          '2': world, 4.0, 4.0, 6.0
          '3': world, 4.0, 4.0, 1.0
          '4': world, 4.0, 4.0, 8.0
          '5': world, 4.0, 4.0, 13.0
          '6': world, 4.0, 4.0, 5.0
        spawns2:
          '1': world, 4.0, 4.0, 4.0
          '2': world, 4.0, 4.0, 6.0
          '3': world, 4.0, 4.0, 1.0
          '4': world, 4.0, 4.0, 8.0
          '5': world, 4.0, 4.0, 13.0
          '6': world, 4.0, 4.0, 5.0
    

    Thanks in advance
    Datdenkikniet
     
  2. Tell us where you are. We don't like handing out code.... We just push in the right direction
     
  3. Sgt_Tailor
    Oh yeah, almost forgot that :S (My bad, I'll add it in the original post)
     
  4. Sgt_Tailor nope, thats what bothers me the most....
     
  5. Offline

    maciekmm

    @Sgt_Tailor Because that's not a list? You must get ConfigurationSection and getKeys(false) in order to get arenas.
     
  6. maciekmm ah, how could I be so stupid :S
     
Thread Status:
Not open for further replies.

Share This Page