Repository navigation
v2.0.0
⚡ Features
- Zero Runtime Overhead: All configuration loaders are generated at build-time (KSP).
- Type-Safe: Fully typed configuration using Kotlin data classes.
- Wide Type Support: Supports primitives, collections, Bukkit types, and more out of the box.
- Rich Features: Built-in support for comments and custom serializers.
- Default Values: Support for default values using Kotlin default values (e.g.,
val count: Int = 0).
📦 Installation
Add the following dependencies to your build.gradle.kts
plugins {
kotlin("jvm") version "2.2.21"
id("com.google.devtools.ksp") version "2.3.2"
}
repositories {
mavenCentral()
}
dependencies {
implementation("dev.s7a:ktConfig:2.0.0")
ksp("dev.s7a:ktConfig-ksp:2.0.0")
}📝 Quick Example
Add the @KtConfig annotation to your data class
@KtConfig
data class ServerConfig(
val serverName: String,
val maxPlayers: Int
)The loader class will be defined, allowing you to perform loading and saving operations.
override fun onEnable() {
val file = plugin.dataFolder.resolve("config.yml")
val config = ServerConfigLoader.load(file)
// config.serverName : "My Server"
// config.maxPlayers : 100
}serverName: "My Server"
maxPlayers: 100The loader class provides the following methods:
load(File): TloadFromString(String): Tsave(T, File)saveToString(T): String
🚀 Usage
ktConfig provides various annotations to customize configuration behavior:
@KtConfig: Marks a class as a configuration class. Required for code generation.@Comment: Adds comments to configuration headers or properties.@PathName: Customizes the YAML path name for a property.@UseSerializer: Specifies a custom serializer for a property.
📦 Supported Types
ktConfig supports the following types:
Primitives
BooleanByteShortIntLongFloatDoubleCharStringUByteUShortUIntULongBigIntegerBigDecimal
Collections
ListSetMapArrayDequeArrayBooleanArrayByteArrayCharArrayShortArrayIntArrayLongArrayFloatArrayDoubleArrayUByteArrayUShortArrayUIntArrayULongArray
Others
org.bukkit.configuration.serialization.ConfigurationSerializable: ItemStack, Location, ...java.util.UUIDjava.time.Instantjava.time.LocalTimejava.time.LocalDatejava.time.LocalDateTimejava.time.Yearjava.time.YearMonthjava.time.OffsetTimejava.time.OffsetDateTimejava.time.ZonedDateTimejava.time.Durationjava.time.Period- Enum classes
- Inline value classes
Formatted Types
ktConfig provides several formatted types for easier string-based serialization:
FormattedBlock: Represents org.bukkit.Block (World, X, Y, Z)FormattedBlockVector: Represents org.bukkit.util.BlockVector (X, Y, Z)FormattedColor: Represents org.bukkit.Color (#AARRGGBB,#RRGGBB,AARRGGBB,RRGGBB)FormattedLocation: Represents org.bukkit.Location (World, X, Y, Z,World, X, Y, Z, Yaw, Pitch)FormattedVector: Represents org.bukkit.Vector (X, Y, Z)FormattedWorld: Represents org.bukkit.World by its name (WorldName)
These types are automatically serialized to and from their string representations.