Extra Folder Wont Generate

Discussion in 'Plugin Development' started by Bobfan, Aug 10, 2012.

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

    Bobfan

    The extra folder that has the config won't generate even though it say it is. Here is my code:
    Code:
    package me.Bobfan.RPG;
     
    import java.io.File;
    import java.io.Writer;
    import java.util.logging.Logger;
     
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;
     
    @SuppressWarnings("unused")
    public class Start extends JavaPlugin {
     
        public final Logger logger = Logger.getLogger("Minecraft");
        PluginDescriptionFile pdfFile = getDescription();
       
        public void onEnable() {
           
            File file1 = new File(getDataFolder() + File.separator + "Permissions.yml");
            File file2 = new File(getDataFolder() + File.separator + "QuestLocater.yml");
            if (!file2.exists()) {
                this.getLogger().info("Generating Your Quests...");
            }
        }
    }
    
     
  2. Offline

    Deleted user


    Because your not doing it right..

    Code:
    File FILENAME = new File(getDataFolder(), "FILENAME.EXTENTION");
    
    So example to make a config..

    Code:
    File configFile = new File(getDataFolder(), "config.yml");
     
    if (!configFile.exists()) {
    configFile.getParentFile().mkdirs();
    copy(getResource("config.yml"), configFile);
    HcMain.log.info("[PluginName] 'config.yml' didn't exist. Created it.");
    }
    
    That will create a config.yml in the /plugins/yourpluginname

    Alternatively you can replace
    Code:
    getDataFolder()
    With the path to your file and it will make it anywhere you want within your server folder so for example you do
    Code:
    ./Plugins/NewFolder
    
     
  3. Offline

    cdncampbell

    You could try to specify only the path and file name in the constructor instead of passing it a string, you could also test for the file as well.

    Code:
    File file1 = new File(getDataFolder(), "Permissions.yml");
    With regards to the data folder, I test to see if it exists first and if not I then create it:

    Code:
    if(!this.getDataFolder().exists()){
        this.getDataFolder().mkdir();
        this.getLogger().log(Level.INFO, "Created Data Folder.");
    }
    
     
  4. Offline

    pzxc

    Use .mkdirs() instead of .mkdir(), then it creates any folders necessary in the path
     
Thread Status:
Not open for further replies.

Share This Page