Yaml Configuration by Template

Discussion in 'Plugin Development' started by augustas656, Sep 19, 2014.

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

    augustas656

    Hello everyone,

    I've recently created a Config class that extends YamlConfiguration and uses methods from FileConfiguration to save and load the configuration. I also have a method to saveDefault, this checks if there is a config in the plugin's data folder and if there isn't it copies the default version of the config from the plugin's resources to the data folder. This is basically plugin's getConfig() method and it's methods to save, load, saveDefault etc. You can create instances of Config, and each instance of Config is responsible for a single YML config, I extended YamlConfiguration because it's much easier as this places the methods in MemorySection, which are like getString(), so I don't need to get the config first.

    Now that I've explained what is my Config class and how it works, I want to make a Userdata class that you also create instances of. However, instead of having each userdata.yml for each player in my plugin's resources and then needing to copy it if one player's doesn't exist, I made a template for a default userdata for a single player.

    I don't fully understand how all of my code works exactly, but I know it does, and I know most of the parts of it. My reload method used to load modified configs from the data folder first uses the load method from FileConfiguration and then creates a InputStreamReader with arguements plugin.getResource(name), "UTF8", Then if the Reader isn't null then I use the setDefaults method with arguement YamlConfiguration.loadConfiguration(stream), stream being the InputStreamReader.

    I don't exactly know what this code does, but when InputStreamReader is being created the arguement plugin.getResource(name) makes me assume it loads the name.yml from the plugin's resources. Now I don't want to do that, because I only have a template, and it is copied only when a new player's one is being created if it doesn't exist in the userdata folder. I don't exactly know what to do here, anybody got any leads or ideas to help me out? Or atleast some tutorial links?

    Regards
    augustas656
     
Thread Status:
Not open for further replies.

Share This Page