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

Open
wants to merge 24 commits into
base: dev/dev
Choose a base branch
from
Open

Conversation

DerEchtePilz
Copy link
Collaborator

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
Collaborator 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
Collaborator 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.

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