Hi recently I have create a util that allows you to easily load and save your config to a class How it works: The util will read all the fields in a class provided and fill them with config values (defaults to value if path isn't found in config) Example: Code:java public class MyPlugin extends JavaPlugin{ public void onEnable() { ConfigUtil.saveDefaultConfig(new File(getDataFolder(),"config.yml")); ConfigUtil.load(MyConfig.class, getConfig()) getLogger().info(MyConfig.testBoolean); //prints out config value for testBoolean or defaults to true } public void onDisable() { ConfigUtil.save(MyConfig.class, getConfig()) saveConfig() }}public class MyConfig{ //must have default value //must be static public static boolean testBoolean = true; public static int testInt = 0; public static MemorySection = new YamlConfiguration()} Util Class: Code:java //can also be found at [url]http://pastebin.com/2m4B7La0[/url]public class ConfigUtil { public static void load(Class<?> configClass, ConfigurationSection config) { for(Field f : configClass.getDeclaredFields()) { try { f.set(null, config.get(f.getName(),f.get(null))); } catch (IllegalArgumentException e) { continue; } catch (IllegalAccessException e) { continue; } } } public static void save(Class<?> configClass, ConfigurationSection config) { for(Field f : configClass.getDeclaredFields()) { try { config.set(f.getName(), f.get(null)); } catch (IllegalArgumentException e) { continue; } catch (IllegalAccessException e) { continue; } } } public static void saveDefaultConfig(Class<?> configClass, File file) { if(file.exists()) return; FileConfiguration config = new YamlConfiguration(); load(configClass,config); try { config.save(file); } catch (IOException e) { e.printStackTrace(); } }}
2016mfransen Uh, can you at least explain how to use it? I just see a bunch of complicated code and have no idea where to start ..