#Probleme with my yml files config generation.
1 messages · Page 1 of 1 (latest)
The error isnt in that class
ah ok
Can you send the ArenaManager class line 12
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
you didnt initialized arenas
create a constructor and initialize it
Your configs are likely fine
you just have this error
it's not my config is the Arena default yml
I haven't in
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 ?
Your initializing ArenaManager but not the ArrayList inside ArenaManager
so when you add add on that list, it doesnt exist
hence the NPE you get
OK
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
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
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
Ok ok I see