Config.yml Generating Incorrectly

Discussion in 'Plugin Development' started by RoboticPlayer, Aug 27, 2015.

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

    RoboticPlayer

    I am trying to update my NoRain plugin to allow it to be configurable with time and things, but my config.yml isn't generating properly in the plugin folder. Here is my onEnable:
    Code:
    World w = Bukkit.getServer().getWorlds().get(0);
            if (w.isThundering() == true) {
                w.setThundering(false);
                w.setStorm(false);
            }
            log.info("[NoRain] by RoboticPlayer has been enabled!");
            Bukkit.getServer().getPluginManager().registerEvents(this, this);
    
            saveConfig();
            reloadConfig();
            getConfig().options().copyDefaults(true);
    
            timeset = getConfig().getBoolean("timeset");
            time = getConfig().getString("time");
    My config.yml that I put in my java code:
    Code:
    # If you have any questions, comments, or concerns, please contact me on
    # Spigot @RoboticPlayer! I will try to answer everything.
    
    # If this value is set to true, it will keep the time at either day or night. Set it to false to disable.
    
    timeset: false
    
    # Set this value to "day" (no quotes) for it to always be day time, and "night" for it to always be night time. Only
    # works if timeset is true.
    
    time: day
    And the config.yml that comes out in the NoRain folder:
    Code:
    # If you have any questions, comments, or concerns, please contact me on
    # Spigot @RoboticPlayer! I will try to answer everything.
    #
    # If this value is set to true, it will keep the time at either day or night. Set it to false to disable.
    
    So it's just not generating any of the options for the config, which is kinda what I need... If I could get some help, that would be great, thanks!
     
  2. Offline

    Rufus5

    Try putting save and reload after you copy defaults.
     
  3. Just use saveDefaultConfig();
    And:
    Code:
    if (boolean == true)
    can be simplified to just:
    Code:
    if (boolean)
    And don't log when your plugin enables/disables. Bukkit already does this for every plugin
     
  4. Offline

    RoboticPlayer

    @Rufus5
    It changed it, but it's not exactly what I wanted. I changed it from
    Code:
    saveConfig();
    reloadConfig();
    getConfig().options().copyDefaults(true);
    to
    Code:
    reloadConfig();
    getConfig().options().copyDefaults(true);
    reloadConfig();
    saveConfig();
    Now my config.yml (when printed) looks like this:
    Code:
    # If you have any questions, comments, or concerns, please contact me on
    # Spigot @RoboticPlayer! I will try to answer everything.
    #
    # If this value is set to true, it will keep the time at either day or night. Set it to false to disable.
    timeset: false
    time: day
    
     
  5. Try saveResource("config.yml"). But I think JavaPlugin's built in saveConfig() method messes up the comments..
     
  6. Offline

    RoboticPlayer

    @FisheyLP saveResource must contain a string & a boolean, would the boolean value be true to save it?
     
  7. the boolean is if it should overwrite the file. Set it to false if you don't want to reset your config each time the plugin enables :p

    EDIT: Looked at the source code and saveDefaultConfig() doesn't call anything other than saveResource("config.yml", false); ...
     
  8. Offline

    RoboticPlayer

    @FisheyLP I tried saveDefaultConfig() and it had the same result. A little bit off-topic, but how do I create a command to reload the config? Like I have the command for it (/norain reload) and in it I have it do:
    Code:
    saveConfig();
    reloadConfig();
    //Message
    But all it does is when I execute the command, it just overrides it, setting it back to what it was at the time of the last server reload. Any help with that?
     
  9. reloadConfig() overrides everything to make it how it is in the file you created inside your project.
    If it doesn't work properly you could try to delete the config file and then save it
     
  10. Offline

    RoboticPlayer

    What I want to do is create a command that will reload the config file without having to reload the entire server. Is this possible?
     
  11. Yes: reloadConfig(); in the command
     
  12. Offline

    RoboticPlayer

    @FisheyLP
    I already put that in the command, and it overrides it.
    Then you said
     
    Last edited: Aug 27, 2015
Thread Status:
Not open for further replies.

Share This Page