i've been working on bukkit/spigot plugin uses separate configuration files, research done , many tests of other peoples' answers, have not found solution wants work me. have tried minecraft 1 player per config , adapted needs didn't work. here's have:
private final string name; private fileconfiguration config = null; private final plugin plugin; public files(plugin plugin, string name) { this.name = name; this.plugin = plugin; config = yamlconfiguration.loadconfiguration(new file(name)); } public void create() { cfile = new file(plugin.getdatafolder() + file.separator + path, name + ".yml"); if (!plugin.getdatafolder().exists()) plugin.getdatafolder().mkdir(); if (!cfile.exists()) { try { cfile.createnewfile(); } catch (ioexception ex) { ex.printstacktrace(); } } config = yamlconfiguration.loadconfiguration(cfile); } ... set, get, etc methods
if try instantiate with
files f = new files(plugin, "config");
i end errors when trying get/set/etc or end no errors nor results. able give me hand this? appreciated.
let's start @ beginning:
config = yamlconfiguration.loadconfiguration(new file(name));
this tries load configuration without extension bukkit main folder - not plugin folder. if want create configuration later on, should leave config
null value.
cfile = new file(plugin.getdatafolder() + file.separator + path, name + ".yml"); if (!plugin.getdatafolder().exists()) plugin.getdatafolder().mkdir();
you have created file datafolder additional folder path
variable. didn't have created folder inside datafolder. suggest:
file cfgfolder = new file(plugin.getdatafolder(), path); cfgfolder.mkdirs(); cfile = new file(cfgfolder, name + ".yml");
your missing results caused not saving configuration disk:
config.save(cfile);
Comments
Post a Comment