Config for a plugin

Discussion in 'Plugin Development' started by crazicrafter1, Jan 5, 2016.

Thread Status:
Not open for further replies.
  1. Offline

    crazicrafter1

    I've been recently learning on how to program using Java, and keep stumbling on the problem of not knowing how to make a config be made. If I already have a pre-made config to put in the .jar file, what is the code to copy it into the server plugins folder, with the plugins source folder?
    What I have so far:

    Code:
    package crazicrafter1.configproject;
    
    import java.io.File;
    
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class ConfigSetUp extends JavaPlugin {
    
        @Override
        public void onEnable() {
    
            //checks if config exists
            if (!getDataFolder().exists()) {
                getDataFolder().mkdirs();
    
                //copys over config to plugins folder
            this.getConfig().options().copyDefaults(true);
    
            //Dont know whether this works below:
            File file = new File(getDataFolder(), "config.yml");
            if (!file.exists()) {
                getLogger().info("Config.yml not found, creating it!");
                saveDefaultConfig();
            } else {
                getLogger().info("Config.yml found, loading!");
            }
          
            }
        }
       
        @Override
        public void onDisable() {
                 
        }
    }
    I've looked through many sources, but cant find any help
     
  2. Offline

    mythbusterma

    @crazicrafter1

    JavaPlugin#saveDefaultConfig() will save the default if the file does not already exist. Also, I would recommend not starting Java with Bukkit, do other Java programs before you try Bukkit. This will be far more beneficial in the long run, as it is absolutely invaluable to understand exactly what is part of Bukkit and what is part of Java, especially if you ever program again.
     
  3. Offline

    mine-care

    Read the docs where you can find all you need to know about the Configuration API
     
Thread Status:
Not open for further replies.

Share This Page