Reloading the config (from a different class)

Discussion in 'Plugin Development' started by MistPhizzle, Oct 7, 2012.

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

    MistPhizzle

    For the better part of my morning, I have been trying to make a command that reloads a config. I am well aware of the reloadConfig() method, however it isn't quite doing what I want it to do.

    The command works, it sends a message saying the Config has been reloaded, but nothing is happening to the config itself. I still have to use a /reload for the config changes to take effect. I am absolutely terrible at explaining things, so here is my code, maybe someone out there can help me out.

    The Whole Project: http://github.com/MistPhizzle/MobEffects

    Main Class: https://github.com/MistPhizzle/MobEffects/blob/master/src/com/etriacraft/MobEffects/MobEffects.java

    My Command: https://github.com/MistPhizzle/MobE.../etriacraft/MobEffects/MobEffectsCommand.java

    and lastly, my config: https://github.com/MistPhizzle/MobEffects/blob/master/src/com/etriacraft/MobEffects/Config.java

    I put things in separate classes to keep myself / the project organized. The config in the main class didn't come off as a good idea to me (seeing as it is around 2500 lines long)
     
  2. Offline

    newboyhun

    On config reload all time gets the default values,because you always set it at Config.java from line 1917

    Set the default values only if config file doesn't exist.
     
  3. Offline

    MistPhizzle

    I don't quite understand what you're saying. On line 1917, I begin to set the defaults.

    How would I go about making this ONLY set the defaults if the config file doesn't exist? I'm relatively new to programming, this is my first project of this scale. Thank you for your help :)
     
  4. Offline

    newboyhun

    Code:
    boolean bool=new File(getDataFolder().toString()+"/config.yml").exists();
            if (!bool) {
                log.info(prefix+" Config not found,generating....");
                // YOUR DEFAULTS
                saveConfig();
                reloadConfig();
            }
     
  5. Offline

    MistPhizzle

    I added that code around lines 1917 forward.

    When I added the boolean bool = new... etc, it says "create method getDataFolder()"

    and at the end of all of my config.sets, I added saveConfig(); and reloadConfig();

    It is telling me to create methods there as well.
     
  6. Offline

    newboyhun

    You made this too complicated =S

    When you start the server,the config file gets 'copied' to your data folder,copy that config.yml to your source.

    And insted of adding the defaults,use this line: plugin.getConfig().options().copyDefaults(true);

    For the plugin variable do the same like at MobEffectsCommand
     
  7. Offline

    Sagacious_Zed Bukkit Docs

    Don't call saveConfig() and reloadConfig() on the line following. It only causes unnecessary disk reading and parsing, thus slowing done the server.
     
  8. Offline

    IcyRelic

    From a different class from your main class?

    i use

    Code:
        (YourMainClass) plugin;
        public (YourCurrentClass)((YourMainClass)instance) {
     
            plugin = instance;
     
            }
    and then

    Code:
    plugin.reloadConfig();
     
  9. Offline

    devilquak

    If you use saveConfig(); and then reloadConfig(); right after, that's your problem. It's literally just saving the current version and reloading that, not saving the version you edited yourself and reloading that. Only use reloadConfig(); when you want to reload, and only use saveConfig(); if you're, say, editing it from within the plugin or shutting down/reloading the server or plugin.
     
  10. whit the methode he have designed the config.java, reloadConfig does nothing because he handled the workings of the config by himself. as the result of this, he must manually load the cofig whit config.load and config.save
     
  11. Offline

    MistPhizzle

    I tried everything above, nothing quite works the way I want it to. How exactly would I do this? I put the command on the back burner until I can figure it out though.
     
  12. Offline

    IcyRelic

    what do you want then my way i gave u reloads the config from another class
     
Thread Status:
Not open for further replies.

Share This Page