Skip to content

feat: add YmlConfigWrapper for managing YAML configuration files#169

Merged
twisti-dev merged 13 commits into
version/1.21.10from
feat/add-yml-config-wrapper
Dec 10, 2025
Merged

feat: add YmlConfigWrapper for managing YAML configuration files#169
twisti-dev merged 13 commits into
version/1.21.10from
feat/add-yml-config-wrapper

Conversation

@TheBjoRedCraft

Copy link
Copy Markdown
Contributor

This pull request introduces a new utility for managing YAML-based configuration files and bumps the plugin version. The main addition is the YmlConfigWrapper class, which simplifies loading, editing, and saving configuration objects using a Sponge-based manager. There's also a helper extension for easy instantiation, and the plugin version is incremented to reflect the new functionality.

Configuration management improvements:

  • Added the YmlConfigWrapper class for type-safe and convenient management of YAML configuration files, including automatic loading, editing, and saving via SpongeConfigManager. (surf-api-core/surf-api-core-api/src/main/kotlin/dev/slne/surf/surfapi/core/api/config/YmlConfigWrapper.kt)
  • Introduced the SurfConfigApi.createYmlConfig inline extension function for easy creation of YmlConfigWrapper instances. (surf-api-core/surf-api-core-api/src/main/kotlin/dev/slne/surf/surfapi/core/api/config/YmlConfigWrapper.kt)

Versioning:

  • Updated plugin version from 1.6.4 to 1.6.5 to reflect new features. (surf-api-gradle-plugin/build.gradle.kts)

@TheBjoRedCraft TheBjoRedCraft self-assigned this Dec 6, 2025
Copilot AI review requested due to automatic review settings December 6, 2025 20:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces a convenient wrapper class for managing YAML-based configuration files using the existing Sponge configuration infrastructure. The YmlConfigWrapper provides a simplified, type-safe API for loading, editing, and saving configuration objects, along with an extension function for easy instantiation.

Key changes:

  • Added YmlConfigWrapper<T> class providing a high-level API for YAML config management with built-in reload and edit capabilities
  • Introduced SurfConfigApi.createYmlConfig() extension function as a convenient factory method using reified generics
  • Bumped plugin version from 1.6.4 to 1.6.5

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
surf-api-core/surf-api-core-api/src/main/kotlin/dev/slne/surf/surfapi/core/api/config/YmlConfigWrapper.kt Introduces the new YmlConfigWrapper class and createYmlConfig extension function for simplified YAML configuration management
surf-api-gradle-plugin/build.gradle.kts Updates plugin version from 1.6.4 to 1.6.5 to reflect the new configuration wrapper feature

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

TheBjoRedCraft and others added 4 commits December 6, 2025 21:26
…surfapi/core/api/config/YmlConfigWrapper.kt

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…surfapi/core/api/config/YmlConfigWrapper.kt

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@twisti-dev twisti-dev requested a review from Copilot December 10, 2025 14:18

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +33 to +34
override val manager =
surfConfigApi.createSpongeJsonConfigManager(configClass, configFolder, fileName)

Copilot AI Dec 10, 2025

Copy link

Choose a reason for hiding this comment

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

Property initialization order issue: manager is initialized before subclass properties. The manager property initialization accesses configFolder and fileName, which are abstract properties that won't be initialized until after the superclass constructor completes. This will cause a runtime error.

Consider making manager a lazy property or use a different initialization pattern:

override val manager by lazy {
    surfConfigApi.createSpongeJsonConfigManager(configClass, configFolder, fileName)
}
Suggested change
override val manager =
surfConfigApi.createSpongeJsonConfigManager(configClass, configFolder, fileName)
override val manager by lazy {
surfConfigApi.createSpongeJsonConfigManager(configClass, configFolder, fileName)
}

Copilot uses AI. Check for mistakes.
Comment on lines +88 to +93
inline fun edit(save: Boolean = true, block: C.() -> Unit) {
config.block()
if (save) {
save()
}
}

Copilot AI Dec 10, 2025

Copy link

Choose a reason for hiding this comment

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

The edit method lacks synchronization, which could lead to race conditions if multiple threads modify the configuration concurrently. Consider adding synchronization to ensure thread-safe access:

@Synchronized
inline fun edit(save: Boolean = true, block: C.() -> Unit) {
    config.block()
    if (save) {
        save()
    }
}

Note: This should align with thread-safety patterns used elsewhere in SpongeConfigManager (e.g., in save() and reloadFromFile()).

Copilot uses AI. Check for mistakes.
Comment on lines +33 to +34
override val manager =
surfConfigApi.createSpongeYmlConfigManager(configClass, configFolder, fileName)

Copilot AI Dec 10, 2025

Copy link

Choose a reason for hiding this comment

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

Property initialization order issue: manager is initialized before subclass properties. The manager property initialization accesses configFolder and fileName, which are abstract properties that won't be initialized until after the superclass constructor completes. This will cause a runtime error.

Consider making manager a lazy property or use a different initialization pattern:

override val manager by lazy {
    surfConfigApi.createSpongeYmlConfigManager(configClass, configFolder, fileName)
}
Suggested change
override val manager =
surfConfigApi.createSpongeYmlConfigManager(configClass, configFolder, fileName)
override val manager by lazy {
surfConfigApi.createSpongeYmlConfigManager(configClass, configFolder, fileName)
}

Copilot uses AI. Check for mistakes.
…example

- Updated `SpongeYmlConfigClass` and `SpongeJsonConfigClass` constructors to accept `configFolder` and `fileName` as parameters.
- Adjusted `SpongeConfigClass` to make `configFolder` and `fileName` non-abstract.
- Added new `ModernTestConfig` class with example usage and randomization functionality.
@twisti-dev twisti-dev merged commit 6e09127 into version/1.21.10 Dec 10, 2025
4 checks passed
@twisti-dev twisti-dev deleted the feat/add-yml-config-wrapper branch December 10, 2025 14:44
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.

3 participants