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

[Suggestion] Add a way to specify a default path. #2

Open
TheDeafCreeper opened this issue Nov 16, 2024 · 0 comments
Open

[Suggestion] Add a way to specify a default path. #2

TheDeafCreeper opened this issue Nov 16, 2024 · 0 comments

Comments

@TheDeafCreeper
Copy link

For projects where you'll want everything stored in the same folder, but not root folder (like MC servers) it would be nice to be able to tell DynamicYAML to put everything in a specific folder (like "./plugins/PLUGIN") instead of needing to do @Config("./plugin/PLUGIN/config.yaml") every time.

Potential implementation I was thinking of is adding a default path value to DynamicYAML that is prepend to the path specified in @Config

Example Minecraft implementation (in Kotlin because I feel like it):

package com.thedeafcreeper.example_plugin

import org.bukkit.plugin.java.JavaPlugin

class ExamplePlugin : JavaPlugin() {
    override fun onEnable() {
        DynamicYAML.defaultPath = dataFolder.path // resolves to SERVERFOLDER/plugins/ExamplePlugin iirc
        // In Java this would be DynamicYAML.setDefaultPath("")

        val config = DefaultConfig().load()
        // Loads from SERVERFOLDER/plugins/ExamplePlugin/config.yaml instead of SERVERFOLDER/config.yaml
        logger.info(config.test)
    }

    override fun onDisable() {
        // Plugin shutdown logic
    }
}
package com.thedeafcreeper.example_plugin

import group.aelysium.declarative_yaml.DeclarativeYAML
import group.aelysium.declarative_yaml.annotations.Config
import group.aelysium.declarative_yaml.annotations.Node

@Config("config.yaml")
class DefaultConfig {
    fun load(): DefaultConfig = DeclarativeYAML.load(DefaultConfig::class.java)

    @Node
    val test: String = "Test String"
}
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

No branches or pull requests

1 participant