#Probleme with my yml files config generation.

1 messages · Page 1 of 1 (latest)

shy fox
#

maybe a poeple

#

for help me

prime kiln
#

The error isnt in that class

shy fox
#

ah ok

prime kiln
#

Can you send the ArenaManager class line 12

shy fox
#

Yeah

#

I can't screen

#

waint

#
public class ArenaManager {
    private List<Arena> arenas;

    public void addArena(Arena arena) {
        arenas.add(arena); //Line 12
    }
#

but why I haven't a default config

prime kiln
#

you didnt initialized arenas

#

create a constructor and initialize it

#

Your configs are likely fine

#

you just have this error

shy fox
#

I haven't in

prime kiln
#

get it running without errors first

#

and then see

shy fox
#
public void yamlArenaConfigSetup(String fileName) {
        File arenaFile = new File(arenasFile, fileName + ".yml");
        YamlConfiguration arenaConfig;
        Arena arena = new Arena(fileName);

        if (!arenaFile.exists()) {
            try {
                arenaFile.createNewFile();

                arenaConfig = YamlConfiguration.loadConfiguration(arenaFile);
                YamlConfiguration defaultArena = YamlConfiguration.loadConfiguration(this.getTextResource("arena.yml"));
                arenaConfig.setDefaults(defaultArena);

                arena.setIsSetup(false);

            } catch (IOException e) {
                e.printStackTrace();
            }

        } else {
            arenaConfig = YamlConfiguration.loadConfiguration(arenaFile);
            ConfigurationSection arenaSection = arenaConfig.getConfigurationSection("arena");

            for (String string : arenaConfig.getKeys(false)) {
                String worldMap = arenaConfig.getString(string + ".world");
                String loc1 = arenaConfig.getString(string + ".loc1");
                String loc2 = arenaConfig.getString(string + ".loc2");

                if (loc1 != null && loc2 != null && worldMap != null) {
                    BuildingZone buildingZone = new BuildingZone(parseStringLoc(loc1), parseStringLoc(loc2));
                    arena.addBuildingZone(buildingZone);
                    arena.setIsSetup(arenaConfig.getBoolean("enable"));

                } else {
                    arena.setIsSetup(false);
                }
            }
        }
        arenaManager.addArena(arena);
}
#

I initialise my variable why I need to initalise a another in the constructor ?

prime kiln
#

so when you add add on that list, it doesnt exist

#

hence the NPE you get

shy fox
#

OK

prime kiln
#

Constructors like this are useful as you can initialize variables right when you call new YourClass()

#

If i didnt initialized my HashMaps in my constructor, i would be in the same boat as you

shy fox
#

okok

#

I see now thx

shy fox
# prime kiln Constructors like this are useful as you can initialize variables right when you...

OK no error now BUT my default arena when I create don't take the basic config parents and key. that what's I want and it's my arena.yml file in ressources of the plugin:

arena:
  exemple:
    world: world
    loc1: 0.0,0.0,0.0
    loc2: 0.0,0.0,0.0
enable: false

So are u agree with that/

if (!arenaFile.exists()) {
          try {
                arenaFile.createNewFile();

                arenaConfig = YamlConfiguration.loadConfiguration(arenaFile);
                YamlConfiguration defaultArena = YamlConfiguration.loadConfiguration(this.getTextResource("arena.yml"));
                arenaConfig.addDefaults(defaultArena);
                arenaConfig.save(arenaFile);


            } catch (IOException e) {
                e.printStackTrace();
            }

        }
#

I have nothing in my file

prime kiln
#

If you want to save a config file from a config inside your jar

#

use YourMainPluginClass#saveResource("pathThatsInsideYourJar");

#

it skips all that file creating stuff

#

and you can just load it from File after creating

#

my yaml is different since im extending YamlConfiguring

But its the same concept

shy fox
#

Ok ok I see

prime kiln
#

Also tip you can do your config files like this:

#

and you can access things like so:

#

thats upto you if you want your config files like that

#

but may help make it a little easier to read

#

If you do it like that just make sure to copy my constructor