Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework plugin config system #596

Merged
merged 26 commits into from
Oct 8, 2024
Merged

Rework plugin config system #596

merged 26 commits into from
Oct 8, 2024

Conversation

DerEchtePilz
Copy link
Member

Just an idea I had, can be merged if good and wanted, but can also be closed.
The advantage of this system is that updating the config is possible. New values can be added and user configs that already exist get the new values. Furthermore, this system would also allow removing values if they are no longer needed, if that ever happens.

@DerEchtePilz DerEchtePilz marked this pull request as draft August 21, 2024 12:42
@DerEchtePilz
Copy link
Member Author

Hmm, the general system works perfectly, however there are issues when dealing with the lists for the config options that are used to convert commands.

Converting this PR to a draft until fixed.

@willkroboth
Copy link
Collaborator

I wonder if there is a general library (maybe not even Minecraft specific) for updating and loading commented YAML configurations. That could help create a more generic system that would also work for CommandAPIVelocity, and it would be probably already be well tested and reliable.

@DerEchtePilz
Copy link
Member Author

Maybe Configurate could work, though I haven't used it before, only heard of it.
https://github.com/SpongePowered/Configurate

@DerEchtePilz DerEchtePilz marked this pull request as ready for review August 23, 2024 12:05
Copy link
Collaborator

@willkroboth willkroboth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be good to implement this system for Velocity as well before merging. With #517, the default Bukkit config will eventually need to be split Spigot/Paper for the hook-paper-reload option. Having a system now that can deal with the shared options between Bukkit/Velocity would be nice for implementing the Spigot/Paper split later.

Additionally, it would be nice to see some automated tests for the config updating logic. With the YamlConfiguration#loadFromString and YamlConfiguration#saveToString methods, I imagine these tests could look something like:

String currentString;
YamlConfiguration currentConfig = YamlConfiguration.loadFromString(currentString);

YamlConfiguration updatedConfig = ConfigGenerator.generateWithNewValues(currentConfig);
String updatedString = updatedConfig.saveToString();

assertEquals(expectedString, updatedString);

Tests could include making sure new config options are added, extra config options are removed, options set by the user are carried over, comments are updated separately from values, etc.

Putting both these ideas together, writing tests could be easier if ConfigGenerator was able to do more than just generate the default Bukkit config. Each test could pass in its own custom small set of config options, which would mean expectedString wouldn't need to hold the whole Bukkit config.yml every time.

Copy link
Contributor

@Strokkur424 Strokkur424 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't really looked too deep into how the code works, but it looks good. I just highlighted some inconsistency

Copy link
Collaborator

@willkroboth willkroboth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another miscellaneous thing I noticed while testing that didn't fit anywhere else. If I have a config that looks like this:

image

Once running the server the config gets updated to this:

image

This doesn't seem like a big deal since - Essentials: null seems to be interpreted the same, but I thought I'd bring it up.

Automated tests might've caught some of the things I brought up, and perhaps more that I missed.

@willkroboth willkroboth requested a review from JorelAli October 6, 2024 20:10
Copy link
Collaborator

@willkroboth willkroboth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Functionality seems good, so just some comments on code logic and organization.

I still think it would be good to get some unit tests to make sure all code paths and edge cases are verified.

@DerEchtePilz DerEchtePilz merged commit 0739a4f into dev/dev Oct 8, 2024
5 checks passed
Copy link
Collaborator

@willkroboth willkroboth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suprise merge lol, didn't realize we needed to merge this soon.

None of these are big issues, but I would have preferred a third opinion on a few conversations: #596 (comment), #596 (comment), #596 (comment), and unit tests. When I have my own idea of how I would implement a system, its hard for me to tell if these are real concerns or just silly me problems :P.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants