Introduction First I want to say that never ever use BBCode with Google Chrome, at least on a Finnish keyboard layout. It enters an awesome arabian text mode that I don't want to use. Now to the tutorial, this is pretty much a copy-pasta tutorial, but I'll have some text in here too. Your config-class Code:java // Package Declarationpackage my.plugin.here.config; // Java Importsimport java.io.File;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;import java.io.InputStream;import java.util.EnumMap;import java.util.Map; // Bukkit Importsimport org.bukkit.Bukkit;import org.bukkit.configuration.InvalidConfigurationException;import org.bukkit.configuration.file.YamlConfiguration; /** * A class that handles all configuration files. * * @author iffa * @author Pandarr * @author Sammy * @author kitskub */public class MyConfig { // Variables private static Map<ConfigFile, YamlConfiguration> config = new EnumMap<ConfigFile, YamlConfiguration>(ConfigFile.class); private static Map<ConfigFile, File> configFile = new EnumMap<ConfigFile, File>(ConfigFile.class); private static Map<ConfigFile, Boolean> loaded = new EnumMap<ConfigFile, Boolean>(ConfigFile.class); /** * Gets the configuration file. * * @param configfile ConfigFile to get * * @return YamlConfiguration object */ public static YamlConfiguration getConfig(ConfigFile configfile) { if (loaded.get(configfile) == null || !loaded.get(configfile)) { loadConfig(configfile); } return config.get(configfile); } /** * Gets the configuration file. * * @param configfile ConfigFile to get * * @return Configuration file */ public static File getConfigFile(ConfigFile configfile) { return configFile.get(configfile); } /** * Checks if the configuration file is loaded. * * @param configfile ConfigFile to get * * @return True if configuraton file is loaded */ public static boolean getLoaded(ConfigFile configfile) { return loaded.get(configfile); } /** * Loads all configuration files. (can be used to save a total of 2 lines!) */ public static void loadConfigs() { for (ConfigFile configfile : ConfigFile.values()) { loadConfig(configfile); } } /** * Loads the configuration file from the .jar. * * @param configfile ConfigFile to load */ public static void loadConfig(ConfigFile configfile) { configFile.put(configfile, new File(Bukkit.getServer().getPluginManager().getPlugin("MyPlugin").getDataFolder(), configfile.getFile())); if (configFile.get(configfile).exists()) { config.put(configfile, new YamlConfiguration()); try { config.get(configfile).load(configFile.get(configfile)); } catch (FileNotFoundException ex) { //SpaceMessageHandler.print(Level.WARNING, ex.getMessage()); loaded.put(configfile, false); return; } catch (IOException ex) { //SpaceMessageHandler.print(Level.WARNING, ex.getMessage()); loaded.put(configfile, false); return; } catch (InvalidConfigurationException ex) { //SpaceMessageHandler.print(Level.WARNING, ex.getMessage()); loaded.put(configfile, false); return; } loaded.put(configfile, true); } else { try { Bukkit.getServer().getPluginManager().getPlugin("MyPlugin").getDataFolder().mkdir(); InputStream jarURL = MyConfig.class.getResourceAsStream("/" + configfile.getFile()); copyFile(jarURL, configFile.get(configfile)); config.put(configfile, new YamlConfiguration()); config.get(configfile).load(configFile.get(configfile)); loaded.put(configfile, true); //SpaceMessageHandler.print(Level.INFO, "Generated " + configfile.getFile() + " file"); } catch (Exception e) { //SpaceMessageHandler.print(Level.SEVERE, e.toString()); } } } /** * Copies a file to a new location. * * @param in InputStream * @param out File * * @throws Exception */ static private void copyFile(InputStream in, File out) throws Exception { InputStream fis = in; FileOutputStream fos = new FileOutputStream(out); try { byte[] buf = new byte[1024]; int i = 0; while ((i = fis.read(buf)) != -1) { fos.write(buf, 0, i); } } catch (Exception e) { throw e; } finally { if (fis != null) { fis.close(); } if (fos != null) { fos.close(); } } } /** * Constructor of MyConfig. */ private MyConfig() { } /** * All config files. */ public enum ConfigFile { // Enums CONFIG("config.yml"), SOMETHING("another.yml"), YADDAYADDA("rofl.yml"), CUPCAKES("cake.yml"); // Variables private String file; /** * Constructor of ConfigFile. * * @param file File name */ ConfigFile(String file) { this.file = file; } /** * Gets the file associated with the enum. * * @return File associated wiht the enum */ public String getFile() { return this.file; } }} As you can see, the ConfigFile-enum contains all configuration files of your plugin. This allows easy adding: Add the configuration file to your .jar (like you would normally do) Add the configuration file to the enum and include the name of the file See, it's that easy. Now if you want to handle them, it's going to take a little extra effort. If you make changes to your configuration files, you can just do Code:java try { MyConfig.getConfig(ConfigFile.CUPCAKES).save(MyConfig.getConfigFile(ConfigFile.CUPCAKES)); } catch (IOException ex) { Logger.getLogger(MyConfigHandler.class.getName()).log(Level.SEVERE, null, ex); } And to load all configs on startup, you can just call MyConfig.loadConfigs()! Your config handler-class Alright, so we have the class that handles creating and loading configuration files, but we need to make a class to handle these configuration files (methods to get values easily etc): Code:java // Package Declarationpackage my.plugin.here.config; // MyPlugin Importsimport my.plugin.here.config.MyConfig.ConfigFile; /** * Yadda yadda useful methods here. * * @author iffa */public class MyConfigHandler { /** * Gets 'some value' from cupcakes.yml. * * @return True if cupcakes are delicious */ public static boolean getSomeValue() { return MyConfig.getConfig(ConfigFile.CUPCAKES).getBoolean("are.cupcakes.delicious"); } // More methods here VV /** * Constructor of MyConfigHandler. */ private MyConfigHandler() { }} If you has problems, I'll try to helps. You're grammar errores are annoy though! [Mod edit (TnT)] Cleaned up language.
Excuse me if I am the most retarded person in the world, (I may just be tired) but where would I put Code:Java try { MyConfig.getConfig(ConfigFile.CUPCAKES).save(MyConfig.getConfigFile(ConfigFile.CUPCAKES));} catch (IOException ex) { Logger.getLogger(MyConfigHandler.class.getName()).log(Level.SEVERE, null, ex);}