Config Issue

Discussion in 'Plugin Development' started by iiHeroo, Sep 15, 2013.

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

    iiHeroo

    ok, I know there's a few way's to get a config, but I need to do it so you can edit the config to your extent. Someone told me to do something like this, but I didn't understand it much, and he said he didn't have time, and had to go, and to ask you guys, well here's the code he told me

    Code:java
    1. @Override
    2. public void onEnable() {
    3. something = this;
    4.  
    5. config = YamlConfiguration.loadConfiguration(new File("something", "config.yml"));


    And, what I'm mainly asking is, would this work, if not, what would where server owner's can edit the config.yml to their extent.
     
  2. Offline

    Compressions

    iiHeroo You can use Bukkit's native config system:
    Code:
    config = getConfig();
    But the way you are doing it for a separate config:
    Code:
    config = YamlConfiguration.loadConfiguration(new File(getDataFolder(), "file.yml"));
     
  3. Offline

    iiHeroo


    And would I do like

    Code:
    saveDefaultConfig();
    under it ?
     
  4. Offline

    Compressions

    iiHeroo If you want comments to be saved for the config, yes, you would do that.
     
  5. Offline

    iiHeroo


    And would the config still be editable for server owners ?
     
  6. Offline

    Compressions

  7. Offline

    chasechocolate

    iiHeroo yes, creating a custom .yml file will make it function like a config.yml file.
     
  8. Offline

    uyuyuy99

    iiHeroo Yes. The whole point of a config is to be editable by server owners.
     
  9. Offline

    iiHeroo


    okay thanks, xD, I just wanted to make sure, I didn't want to find out in the end and not it being able to work.


    uh, I know it's solved and all, but uh, I return with an error, should it be a variable, the error is the "config" http://gyazo.com/563c5ed7037674d12307d89caac9e6b0

    Code:
    @Override
        public void onEnable(){
            config = getConfig();
            saveDefaultConfig();
           
            
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
  10. Offline

    uyuyuy99

    iiHeroo Er, well, you need to define the variable.
    Code:java
    1. Configuration config;
    2.  
    3. @Override
    4. public void onEnable(){
    5. config = getConfig();
    6. saveDefaultConfig();
     
  11. Offline

    Compressions

    iiHeroo
    Code:
    FileConfiguration config;
     
  12. Offline

    iiHeroo


    Yeah, I know, I got that. Thanks for all of you're help, Bukkit has a great community :)


    okay, uh, just percussion, I have a warning for "config" on line 12, the warning is:

    - Write occurrence of 'config'
    - The value of serverinfoplus.config is not used

    CODE:

    Code:java
    1. package org.horrgs.me;
    2.  
    3. import java.util.logging.Logger;
    4.  
    5. import org.bukkit.ChatColor;
    6. import org.bukkit.configuration.file.FileConfiguration;
    7. import org.bukkit.plugin.java.JavaPlugin;
    8.  
    9. public class serverinfoplus extends JavaPlugin{
    10.  
    11. public final Logger logger = Logger.getLogger("Minecraft");
    12. private FileConfiguration config;
    13. public static serverinfoplus plugin;
    14. public static String colorize(String str) {
    15. return ChatColor.translateAlternateColorCodes('&', str);
    16. }
    17.  
    18.  
    19. @Override
    20. public void onEnable(){
    21. config = getConfig();
    22. saveDefaultConfig();
    23.  
    24.  
    25. }
    26. }
    27.  
    28.  


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
  13. Offline

    iiHeroo

    bump....
     
  14. iiHeroo
    The warning is self-explanatory; The value of serverinfoplus.config is not used
    You're not using it anywhere.
     
  15. Offline

    iiHeroo


    I know, but like, how do I get it to get the config.yml ? Obviously I put

    config = getConfig();

    but, it returns with that error.
     
  16. iiHeroo
    Warning, not an error. To get rid of it, just use the variable somewhere. If you're not using it, then why do you even have it in the first place? Listen to the warnings, man! They know what's up.
     
  17. Offline

    iiHeroo

    xD, WARNING, but like, they said above, use

    Config = getConfig(); to get the config.yml, then I imported using YamlConfiguration, then it returned with a warning, and I don't know how to fix it xD.

    Assist
     
  18. iiHeroo
    You don't need it, it's just to speed things up by 3 letters and 2 symbols. If you want to keep it, then keep it, it's only a warning telling you that it hasn't been used yet.
     
  19. Offline

    iiHeroo


    okay thanks !
     
Thread Status:
Not open for further replies.

Share This Page