Closed TrueMB closed 2 years ago
It looks like your using it correctly. What isn't working? Does it just reset the ignored section to what is in the default config?
It does update everything.
But what I want to do now, is to ignore the sections "maxPossible" and "categorySettings". The config starts with two entries. F.e. 88 and 99. They contain different settings for the category. But if a user wants to add an another category, then this one shouldn't be deleted.
It would look like this
What currently happens is that the Category 1 gets deleted after an update.
Make sure you are on the latest version (2.0-SNAPSHOT). I added a test case in commit dd9c32fb9af59fe858f957d176c384b4632b94f9. Let me know if you are doing something different that the test case (testUpdateMethodToMakeSureIgnoredSectionsAreHandledCorrectly) doesn't account for. So far I cannot reproduce. Re-open the issue if I am incorrect about something.
I uploading here my configs for you. Both are normally .yml, but I renamed them since GitHub doesnt support yml.
configHowItShouldStay is after a user edit an should keep the changes in f.e. categorySettings. configAfterUpdate is after the Plugins runs an Update. It looks like the default config. (It does add new Values, but it should completly ignore the named section)
I tried using your exact your Snapshot, but it does the same thing. On my plugin I added your Code manually, so that I can do a small changes. https://github.com/TrueMB/RentIt/blob/07fbc4f00c0d6bf0646a7782718606e1523a8b14/src/me/truemb/rentit/utils/ConfigUpdater.java#L57 This allows me to update only the config, if I want to. (Just as background Information) The Code is the same tho.
In your test it looks like you are doing it, like I want it to be. But not for me.... D:
Here my main Method:
public UTF8YamlConfiguration manageFile() {
File configFile = this.getConfigFile();
if (!configFile.exists())
saveResource("config.yml", true);
if(this.config == null) {
//TO GET THE CONFIG VERSION
this.config = new UTF8YamlConfiguration(configFile);
//UPDATE
if(!this.config.isSet("ConfigVersion") || this.config.getInt("ConfigVersion") < configVersion) {
this.getLogger().info("Updating Config!");
try {
ConfigUpdater.update(this, "config.yml", configFile, "Options.categorySettings");
this.reloadConfig();
this.config = new UTF8YamlConfiguration(configFile);
} catch (IOException e) {
e.printStackTrace();
}
}
}
return this.config;
}
My test case works correctly which means it is in your code somewhere. There is a lot of code your messing with that you probably don't need to such as the YamlConfiguration class.
Okay I tried some more. Also removed my UTF8YamlConfiguration and now working with the default one.
It looks like the ConfigUpdater forgets the parent section after a list. Thats why he cant compare them anymore correctly.
This is definitely an error in this code. Would be awesome if you could look that up once more.
EDIT: Checking something real quick
EDIT2: It seems like your Updater doesnt handle the List correctly. After the Update it loses the format and is no longer a child of the Path. More like "- 'some list value'" gets set to an own path.
Elements of a list only have to start with the dash. They don't need to be indented, it is still valid yml. I'm not sure what you mean by it forgets the parent section after a list. Everything looks fine.
Trying using my art skills :D
Until "Options.commands.hotel.disabledSubCommands" everything works. Then Comes the list of the named Key. After that it doesnt use the parent Section anymore and it cant compare the ignoreSection Array.
This is how the fullkey should look after the list: "Options.commands.shop"
Like you can see in the config picture above.
This is also, where I am outputing the messages:
I looked at your code and your ConfigUpdater has old code. Use maven and use the latest version.
Like already said. I tried using Maven. I am using the new Version. Not on Github atm, since it doesnt work.
This seems like to work for me. Got a problem now with the comments. But no need to worry anymore
EDIT: My Problem was, every comment got send so often, like items in the ignore list. This fixed it for me:
I am using in my Config Sections, that the user can extend freely.
Is it possible to keep the new Values of a section or ignore the section since there will be nothing new? The ignore Section Option doesnt seem to work or I am doing something wrong.
How I am trying to update:
ConfigUpdater.update(this, "config.yml", configFile, "Options.maxPossible", "Options.categorySettings");
This are the two Section, that should not remove the values of the user: https://github.com/TrueMB/RentIt/blob/07fbc4f00c0d6bf0646a7782718606e1523a8b14/src/main/resources/config.yml#L62 https://github.com/TrueMB/RentIt/blob/07fbc4f00c0d6bf0646a7782718606e1523a8b14/src/main/resources/config.yml#L102