I know how to create and use a config.yml in my Project, but can someone explain me how to make & use an external .yml, for example i want to create a kit.yml where I can change the tools or what else.
To make external YAML files, you can use the built-in FileConfiguration class in Bukkit. Just instantiate the object with the YamlConfiguration#loadConfiguration method. From there, you can access all of your stuff through the get and set methods. [Edit]: An example would something like this: Code (Java): File file = new File(getDataFolder(), "kits.yml"); FileConfiguration fileConfig = YamlConfiguration.loadConfiguration(file); // Get some information... boolean someBoolean = fileConfig.getBoolean("some.boolean.path"); // Set some information... fileConfig.set("some.set.path", "some.value");
And how can I make it that i have a File in my plugins folder? So that if I sell the Plugin to someone that he can change the entrys in my .yml file.
This is how you create the file in your directory if it does not exist: Code (Text): File dir = this.getDataFolder(); //Your plugin folder dir.mkdirs(); //Make sure your plugin folder exists File example = new File(this.getDataFolder() + "/example.yml"); //This is your external file YamlConfiguration config1 = YamlConfiguration.loadConfiguration(example); //Get the configuration of your external File YamlConfiguration config2 = YamlConfiguration.loadConfiguration(this.getResource("example.yml")); //This is optional, so you can predefine your config. You simply add it to your source as same as your plugin.yml if(!example.exists()) { //Check if your external file exists try { example.createNewFile(); //if not so, create a new one config1.save(example); //save the configuration of config1 or config2 to your new file } catch (IOException e) { System.out.println("[PluginName] couldn't create some files!"); //if something goes wrong this is what will be done then } } Additional Stuff: This is an example for adding files to your source. You can simply get their configuration by doing it as same as i did it with the "config2". Step 1: Right-Click "src" Step 2: Hit "new" Step 3: Click on "File" Step 4: Create your external File
Code (Text): File external = new File(Main.plugin.getDataFolder() + "/external.yml"); YamlConfiguration cfg= YamlConfiguration.loadConfiguration(external); cfg.get("path.to.object"))); //This is how to read
And how do i set data? If i write config.set("friend", "database"); Nothing happens, no error but no creating...
http://www.spigotmc.org/threads/reloading-a-configuration-file-successfully.48140/ - I just replied with my method of making external .yml files on here ;P