https://github.com/itsdoot/kotfigurator
A Kotlin library for easily mapping configurate values to class fields.
https://github.com/itsdoot/kotfigurator
Last synced: over 1 year ago
JSON representation
A Kotlin library for easily mapping configurate values to class fields.
- Host: GitHub
- URL: https://github.com/itsdoot/kotfigurator
- Owner: ItsDoot
- License: mit
- Created: 2018-09-09T23:26:26.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-09-09T23:19:07.000Z (almost 8 years ago)
- Last Synced: 2025-02-02T20:52:49.576Z (over 1 year ago)
- Language: Kotlin
- Size: 65.4 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Kotfigurator
A Kotlin library for easily mapping [configurate](https://github.com/SpongePowered/configurate) values to class fields.
**NOTE:** Comments only work when the configuration format itself supports comments.
## Usage
#### Gradle
```groovy
repositories {
mavenCentral()
maven {
name = 'jitpack'
url = 'https://jitpack.io'
}
}
dependencies {
compile 'com.github.TheFrontier:Kotfigurator:1.0.0'
}
```
#### Maven
```xml
jitpack
https://jitpack.io
com.github.TheFrontier
Kotfigurator
1.0.0
```
## Example
#### Supported Data Types:
- `String`
- `Boolean`
- `Int`
- `Long`
- `Float`
- `Double`
- Any type with an associated TypeSerializer
- `List`s of the aforementioned types
- `Map`s of the aforementioned types
```kotlin
class MyPluginConfig(adapter: ConfigAdapter) {
val joinMessage: String by adapter.string(comment = "The broadcasted message when a player joins.") { "&e%player% has joined the game." }
val enabledModules: List by adapter.list(key = "enabled-modules") { listOf("module-1", "module-2") }
val blocks: BlocksSection by adapter.section(comment = "Blocks that require a permission to obtain") { BlocksSection(it) }
class BlocksSection(adapter: ConfigAdapter) {
val blockPermissions: Map by adapter.map(key = "blocks-with-permissions") {
mapOf("minecraft:grass" to "my.grass.permission",
"minecraft:bedrock" to "my.admin.permission")
}
}
}
fun initializeConfig() {
val loader: HoconConfigurationLoader = ... // Works with any configuration format supported by configurate.
val node = loader.load()
val myPluginConfig = MyPluginConfig(NodeConfigAdapter(node))
print(myPluginConfig.joinMessage)
for (module in myPluginConfig.enabledModules) {
// enable them
}
}
```