Solved MemorySection.get error trying to load item from custom config

Discussion in 'Plugin Development' started by Superior_Slime, Jan 10, 2015.

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

    Superior_Slime

    SOLVED: I replaced the loading method with:
    Code:
    if (localeFile == null) {
                    File localeFile = new File(this.getDataFolder(), "locale.yml");
                }
                locale = YamlConfiguration.loadConfiguration(localeFile);
            
                // Look for defaults in the jar
                Reader localeStream = new InputStreamReader(this.getResource("locale.yml"));
                if (localeStream != null) {
                    YamlConfiguration loc = YamlConfiguration.loadConfiguration(localeStream);
                    locale.setDefaults(loc);
                }
    This one has been bugging me for quite a while. I have searched all over, and cannot seem to find a solution. Sorry if there is a simple solution and I'm just an idiot.

    I have a custom YAML file "locale.yml" where different languages and strings are stored. When the plugin is loaded without the locale file in place, it and the other files are created, but when a command gets a locale string, there is an internal error. Note that this is fixed upon a reload with the file still there.

    The code for loading the file is as follows:


    Code:
      if (!localeFile.exists()) {
                this.saveResource("locale.yml", false);
                InputStream locStream = this.getResource("locale.yml");
                if(locStream != null){
                    locale.setDefaults(locale);
                }
            }
    I understand that "locale.setDefaults(locale);" causes infinite recursion, but I cannot think of any other solutions. I have tried to remove that, removing the error but instead returning "null" (since there is no file to load from. this is **NOT** fixed by a server reload).

    Stack trace (this is repeated):

    Code:
    at org.bukkit.configuration.MemorySection.get(MemorySection.java:198) ...
    and

    Code:
    at org.bukkit.configuration.MemorySection.getDefault(MemorySection.java:705) ...
    Thanks in advance and again sorry if I'm being an idiot.
     
    Last edited: Jan 10, 2015
    Experminator and Rocoty like this.
  2. Offline

    Rocoty

Thread Status:
Not open for further replies.

Share This Page