SettingsManager instructions

Aug 26, 2016
SettingsManager instructions
  • Hey guys, a lot of people are still creating default config.yml files, but I personally dont like.... Just 1 file, so thats why I am making a tutorial on default SettingsManager files, now first I am gonna explain what a SettingsManager is:

    What is a SettingsManager:
    A SettingsManager allows you to create custom files, and custom folders, like "/plugins/PluginName/CustomFolder/CustomFile.yml", now you can of course also do just custom files without the custom folders.

    How to make a SettingsManager:
    I am gonna copy/paste a new class that I am using for a SettingsManager:
    Code (Text):
    package YourPackage;

    import java.io.File;
    import java.io.IOException;

    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.configuration.file.YamlConfiguration;

    public class YourClass {
        static FileConfiguration YourFile;
        static File pdfile;

        public static void setup() {
            pdfile = new File("plugins/YourPlugin/", "YourFile.yml");

            if (!pdfile.exists()) {
                try {
                    pdfile.createNewFile();
                } catch (IOException e) {
                }
            }

            YourFile = YamlConfiguration.loadConfiguration(pdfile);
        }

        public static FileConfiguration get() {
            return YourFile;
        }

        public static void save() {
            try {
                YourFile.save(pdfile);
            } catch (IOException e) {
                Bukkit.getServer().getLogger().severe(ChatColor.RED + "Could not save yourfile.yml!");
            }
        }

        public static void reload() {
            YourFile = YamlConfiguration.loadConfiguration(pdfile);
        }

    }
    And if you wanna create/reload/save/get a file, you do the following in the onEnable() method:
    Code (Text):

    YourClass.setup();
    YourClass.get().addDefault("Default", "Default");
    YourClass.get().options().copyDefaults(true);
    YourClass.save();
     
    Thats how you create your settings manager, isnt so hard is it?


    Thanks for reading this page, and good luck making your plugin with custom files.

    - JustMaffie (Bukkit Plugin Developer)
  • Loading...
  • Loading...