Repository navigation
Migrate old configs to newest version automatically - #7
Conversation
…0 configs) Agent-Logs-Url: https://github.com/PixelMindMC/PixelChatGuardian/sessions/c926d3ab-a619-48c5-9ae1-12df63aa4995 Co-authored-by: ToothyDev <55001472+ToothyDev@users.noreply.github.com>
|
@copilot So does this only apply for upgraded configs from 1.2.0 -> current? If so, do you think this is the best way to tackle this seemingly architectural problem, or should the way this stuff is handled change altogether? Or should there simply be a disclaimer in the changelog of 1.3.0 to make sure the config is changed or made to regenerate, and then changed appropriately? Pick what you think is best here and go ahead. |
Agent-Logs-Url: https://github.com/PixelMindMC/PixelChatGuardian/sessions/94732aa5-7c3d-44c3-a32d-4931a61108d8 Co-authored-by: ToothyDev <55001472+ToothyDev@users.noreply.github.com>
The Went with proper config migration instead (commit
The |
ToothyDev
left a comment
There was a problem hiding this comment.
Also add this as a changelog entry for 1.3.0 since this is a noteworthy addition
Agent-Logs-Url: https://github.com/PixelMindMC/PixelChatGuardian/sessions/64635998-1821-43d3-9c4f-87238abef58c Co-authored-by: ToothyDev <55001472+ToothyDev@users.noreply.github.com>
Added in
|
# Conflicts: # CHANGELOG.md
…on-range each block Agent-Logs-Url: https://github.com/PixelMindMC/PixelChatGuardian/sessions/137205cc-75f9-4883-930b-50396246491d Co-authored-by: ToothyDev <55001472+ToothyDev@users.noreply.github.com>
|
@copilot Split the entire migration logic into a seperate helper class, and in there, split the different version migrations into their own methods so it remains readable over time, and the main plugin file doesn't get cluttered |
…ethods Agent-Logs-Url: https://github.com/PixelMindMC/PixelChatGuardian/sessions/fd7d07e7-cd66-4b79-ae44-dd09114eca4f Co-authored-by: ToothyDev <55001472+ToothyDev@users.noreply.github.com>
Done in
Future migrations just need a new |
The 1.2.0→current refactor changed the notify config key from the flat
chatguard.notify-userto the nestedchatguard.notify.user. SincesaveDefaultConfig()never overwrites an existing file, upgraded installs retained the old key. Bukkit'sgetBoolean()returnsfalsefor missing keys, silently suppressing all player notifications. Console logs were unaffected because that code path is unconditional.Changes
ConfigHelper: AddedgetBoolean(path, defaultValue)overload delegating to Bukkit'sFileConfiguration.getBoolean(path, def).ConfigMigrationHelper(newutilsclass): Contains all config migration logic, keepingPixelChat.javauncluttered and making future migrations easy to add:migrate()— public entry point; reads the stored configversionkey and skips all work if it already matches the running plugin version. Dispatches to per-version methods for any steps that apply to the detected version range.migrateTo1_3_0()— private method handling the 1.2.0 → 1.3.0 changes: moveschatguard.notify-user(flat) tochatguard.notify.user(nested), preserving an explicitfalse; addschatguard.notify.admins: truewhen absent.isConfigVersionOlderThan()— private semver comparison helper; treatsnull/empty as older than any target and trailing.0segments as equal (e.g."1.3"=="1.3.0")."Configuration migrated to the <version> format."(version read dynamically from the plugin descriptor) when any change is made.PixelChat: Startup migration reduced to a single call:new ConfigMigrationHelper(this).migrate().CHANGELOG.md: Added a 1.3.0 entry noting automatic config migration for upgraded installs.This approach correctly handles users who had explicitly set
notify-user: falsein their 1.2.0 config, skips all migration work on already up-to-date installs, and establishes a clean, scalable pattern for future config restructuring — new migrations only require adding amigrateTo_X_Y_Z()method and a corresponding version guard inmigrate().