This is probably the easiest way to create a custom .yml file First, Create 2 variables in the main class that extends JavaPlugin Code:java File newConfig;FileConfiguartion newConfigz; After you have done that, add this in onEnable Code:java newConfig = new File(getDataFolder(), "newconfig.yml"); // set the file locationnewConfigz = YamlConfiguration.loadConfiguration(newConfig); // this will give you all the functions such as .getInt, getString ect.. You're almost done, create a new void called saveNewConfig(), for example. Code:java public void saveNewConfig(){ } Now inside that void, you add Code:java newConfigz.save(newConfig); and surround it with try/catch. Now call the saveNewConfig() method in your onEnable and you're done! Example class: Code:java public class Main extends JavaPlugin { File newConfig;FileConfiguration newConfigz; public void onEnable(){ newConfig = new File(getDataFolder(), "newconfig.yml");newConfigz = YamlConfiguration.loadConfiguration(newConfig);saveNewConfig();} public void saveNewConfig(){try{newConfigz.save(newConfig); }catch(Exception e){e.printStackTrace();}} public void onDisable(){ } } Imports used: Code: import java.io.File; import java.io.IOException; import java.util.List; import org.bukkit.Bukkit; import org.bukkit.configuration.file.FileConfiguration; Also, to do stuff with the config, call newConfigz EDIT by Moderator: merged posts, please use the edit button instead of double posting.
Which imports do we take? Also how do we make the stats.yml file generate from the file in the src?(Such as the config)
Assult What would I do when trying to create a file, inside of a folder, inside of the DataFolder? Code: String playername = player.getName().toString(); File name = new File(plugin.getDataFolder() + File.separator + "UserData", playername); This is what I'm using currently, however I get hit with a NullPointerException when casting the file. I have got the code set up for when it searches if it exists, if not it creates it, but it never reaches this part, just seems to assume there's nothing there? I do in fact have a UserData folder that's created in a separate class file, I assume that as I'm new to dealing with multiple folders/files, I'm simply missing something fairly obvious.
You can also just use my util (http://forums.bukkit.org/threads/util-easy-custom-config-creation.187348/)
Datdenkikniet Alright, so I tried this out in a separate class file, to keep things tidy, but I run in to some issues with "config", and "saveResource". It appears that config is never casted in your code, so what am I missing? as changing it to getConfig() doesn't work. No idea what to think of saveResource.
valon750 I'm sorry, I will add the instructions for seperate classes tomorrow thank you for pointing It out
Datdenkikniet Tomorrow?! But.. but I actually have the motivation to code noooow! Ah well, it'll let me focus on some other aspects of the plugins Keep me posted! Thank you!
Great tutorial! But.... You can save the config to a custom folder inside the server folder by doing this: Code:java file= new File("TestFolder/newconfig.yml");config= YamlConfiguration.loadConfiguration(file); This will make a folder in the same directory that the plugins folder & bukkit.jar are in!