Config yml configuration help

Discussion in 'Plugin Development' started by ddeckys, May 26, 2012.

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

    ddeckys

    Here is the main class for my plugin:
    http://pastie.org/3974844

    Here is the error I'm getting:
    http://pastie.org/3974850

    I know it's referring to the line:
    this.saveConfig();

    But I can't figure out what I'm doing wrong.

    Setting the configuration options seems to be working, it's just saving the config.

    Bump

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 26, 2016
  2. Offline

    Coryf88

    Hmm, strange problem you're having, the JavaPlugin class variable "configFile" isn't being initialized. How are you loading the plugin?
     
  3. Offline

    ddeckys

    What do you mean?

    and when I change:
    public FileConfiguration config;

    to:
    public FileConfiguration config = getConfig();

    I just get an null file error on startup. I AM including a config.yml in my plugin Jar and it has worked for me before.
     
  4. Offline

    Sagacious_Zed Bukkit Docs

    That makes sense because getConfig cannot resolve the config file until the plugin is initialized, usually before it is enabled.
     
  5. Offline

    ddeckys

    I still get a Null point error when resolving it after the plugin has been enabled, like in onEnable() and an onCommand(). What do I need to do to fix this.
     
  6. Offline

    BobbyD441

    Its not getConfig() but
    Code:
    public FileConfiguration config = new YamlConfiguration();
    
     
  7. Offline

    ddeckys

  8. Offline

    BobbyD441

    try this:
    Code:
    File file = new File(this.getDataFolder(), "config.yml");
    public FileConfiguration config = new YamlConfiguration();
    
    public void setTagSpawn(Location loc){
        config = this.getConfig();
        config.set("x", loc.getX());
        config.set("y", loc.getY());
        config.set("z", loc.getZ());
        config.set("World", loc.getWorld().getName());
        config.save(file);
    }
    
     
  9. Offline

    ddeckys

    Didn't work, here is the error I get: http://pastie.org/3978943

    But it looks like the line the error is pointing to is:
    Code:
    config = this.getConfig();
    
     
  10. Offline

    Sagacious_Zed Bukkit Docs

    I just thought of something, get rid of all fields of type FileConfiguration and naned config. then see what happens. Line 57 from the pastie in the op

    EDIT: like this.
     
  11. Offline

    ddeckys

    You need to define config otherwise you will get compiling errors.
     
  12. Offline

    BobbyD441

    derp =/

    The save action must be inside a try{} =)
    try this:
    Code:
    File file = new File(this.getDataFolder(), "config.yml");
    public FileConfiguration config = new YamlConfiguration();
     
    public void setTagSpawn(Location loc){
      try{
        config = this.getConfig();
        config.set("x", loc.getX());
        config.set("y", loc.getY());
        config.set("z", loc.getZ());
        config.set("World", loc.getWorld().getName());
        config.save(file);
      catch(Exception e){
        e.printStackTrace();
      }
     }
     
  13. Offline

    Sagacious_Zed Bukkit Docs

    Then let the changes ripple out.
    Like this, http://pastie.org/pastes/3979008

    EDIT: missed a few, also don't have the other classes.
     
  14. Offline

    ddeckys

    I try that and I get a brand new HUGE error:
    http://pastie.org/3979077

    Want me to send a zip with all the source files in it?
     
  15. Offline

    Sagacious_Zed Bukkit Docs

    Actually its the same error.
     
  16. Offline

    BobbyD441

    ddeckys
    Looks like the file doesn't exist.. is it even there?
     
  17. Offline

    Sagacious_Zed Bukkit Docs

    null and non-existing are two different states.
     
  18. Offline

    BobbyD441

    Sagacious_Zed
    i know, but if:
    Code:
    file = new File(getDataFolder(), "config.yml");
    doesn't exist it returns null, so in this case its the same..

    make a default config.yml in the same folder as your plugin.yml and add something like this
    Code:
    if(!file.exists())
            {                                 
                file.getParentFile().mkdirs();
                try
                {
                    this.saveDefaultConfig();
                }
                catch (Exception e)
                {
                    e.printStackTrace();
                }
     
  19. Offline

    Sagacious_Zed Bukkit Docs

    BobbyD441
    No, that is now how constructors work. What can happen is getDataFolder returning null if the plugin is not initialized.
     
  20. Offline

    ddeckys

    [quote uid=90675798 name="BobbyD441" post=1137921]ddeckys
    Looks like the file doesn't exist.. is it even there?[/quote]

    The file IS there, I will send you a ZIP with the whole source

    [quote uid=90675798 name="BobbyD441" post=1137921]ddeckys
    Looks like the file doesn't exist.. is it even there?[/quote]

    Here is the source:
    <Edit by Moderator: Redacted mediafire url>

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Nov 10, 2016
  21. Offline

    BobbyD441

    ddeckys
    Hmm... Where did you get the error?
     
  22. Offline

    Coryf88

    Thanks for posting the full source, made it easier to see exactly what was occurring. The problem is all of your classes is extending your main class.
     
  23. Offline

    ddeckys

    Why is that a problem? Aren't they supposed to extend it so I can use them?
     
  24. Offline

    Sagacious_Zed Bukkit Docs

    No, inheritance is not the right answer. You have to pass a reference instead.
     
Thread Status:
Not open for further replies.

Share This Page