Solved Problems creating custom config file

Discussion in 'Plugin Development' started by robertlit, Aug 6, 2019.

  1. Offline

    robertlit

    Hello, I am having some problems creating a custom config file, I already have one that is being created properly on the same plugin, so I just copied and pasted, and changed the names.
    Code:
    private void createInvitesConfig() {
            invitesConfigFile = new File(getDataFolder(), "invites.yml");
            if (!invitesConfigFile.exists()) {
                invitesConfigFile.getParentFile().mkdirs();
                saveResource("invites.yml", false);
             }
    
            invitesConfig= new YamlConfiguration();
            try {
                invitesConfig.load(invitesConfigFile);
            } catch (IOException | InvalidConfigurationException e) {
                e.printStackTrace();
            }
        }
    (I have used the method in the "on enable")

    Thanks in advance.
     
  2. Offline

    CraftCreeper6

    @robertlit
    Use
    invitesConfig = YamlConfiguration.loadConfiguration(invitesConfigFile);

    What's the issue anyway?
     
    robertlit likes this.
  3. Offline

    robertlit

    It says the method loadConfiguration(File) is undefined for the type FileConfiguration

    @CraftCreeper6
     
  4. Online

    Machine Maker

    @robertlit Please mark this thread as Solved if your issue has been resolved.
     
  5. Offline

    robertlit

  6. Offline

    CraftCreeper6

    @robertlit
    Considering it extends FileConfiguration and the method loadConfiguration does take a file in, I find that hard to believe.

    post your code please.
     
  7. Offline

    robertlit

    Code:
    private void createInvitesConfig() {
            invitesConfigFile = new File(getDataFolder(), "invites.yml");
            if (!invitesConfigFile.exists()) {
                invitesConfigFile.getParentFile().mkdirs();
                saveResource("invites.yml", false);
             }
    
            invitesConfig= new YamlConfiguration();
            try {
                invitesConfig.loadConfiguration(invitesConfigFile); //Error over here
            } catch (IOException | InvalidConfigurationException e) {
                e.printStackTrace();
            }
        }
    @CraftCreeper6
     
  8. Online

    Machine Maker

    oh yeah, its
    Code:java
    1. invitesConfig = YamlConfiguration.loadConfiguration(invitesConfigFile);


    its a static method rather than a method on the object.
     
  9. Offline

    robertlit

    @Machine Maker is this what you meant?
    Code:
    private void createInvitesConfig() {
            invitesConfigFile = new File(getDataFolder(), "invites.yml");
            if (!invitesConfigFile.exists()) {
                invitesConfigFile.getParentFile().mkdirs();
                saveResource("invites.yml", false); // Says ERROR in this line
             }
    
            invitesConfig = YamlConfiguration.loadConfiguration(invitesConfigFile);
            try {
                invitesConfig.load(invitesConfigFile);
            } catch (IOException | InvalidConfigurationException e) {
                e.printStackTrace();
            }
        }
    It's not working..
     
  10. Offline

    CraftCreeper6

    @robertlit
    You can get rid of the try catch now.

    Can I see the saveResource method?
     
  11. Offline

    robertlit

    What do you mean see the saveResource method? It is built into bukkit..

    @CraftCreeper6

    Here is the code again:
    Code:
    private void createInvitesConfig() {
            invitesConfigFile = new File(getDataFolder(), "invites.yml");
            if (!invitesConfigFile.exists()) {
                invitesConfigFile.getParentFile().mkdirs();
                saveResource("invites.yml", false);
             }
    
            invitesConfig = new YamlConfiguration();
            try {
                invitesConfig.load(invitesConfigFile);
            } catch (IOException | InvalidConfigurationException e) {
                e.printStackTrace();
            }
        }
     
    Last edited: Aug 20, 2019 at 10:23 AM
  12. Offline

    CraftCreeper6

    @robertlit
    Never used that function in my life.

    What's the error that it gives?
     
  13. Offline

    robertlit

    Here is the error: (It is very weird because it works for the first file I created)
     

    Attached Files:

  14. Offline

    CraftCreeper6

    @robertlit
    Could it be that you're not providing the getDataPath(), or that you don't have a default configuration inside of the plugin itself.
     
  15. Offline

    robertlit

    Uhh so newbie mistake I didn't have the invites.yml in my project.. Thanks @CraftCreeper6.
     
    CraftCreeper6 likes this.

Share This Page