Skip to content

v2.0.0

Choose a tag to compare

@sya-ri sya-ri released this 05 Jan 00:39
4b5ad3d

⚡ 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: 100

The loader class provides the following methods:

  • load(File): T
  • loadFromString(String): T
  • save(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

  • Boolean
  • Byte
  • Short
  • Int
  • Long
  • Float
  • Double
  • Char
  • String
  • UByte
  • UShort
  • UInt
  • ULong
  • BigInteger
  • BigDecimal

Collections

  • List
  • Set
  • Map
  • ArrayDeque
  • Array
  • BooleanArray
  • ByteArray
  • CharArray
  • ShortArray
  • IntArray
  • LongArray
  • FloatArray
  • DoubleArray
  • UByteArray
  • UShortArray
  • UIntArray
  • ULongArray

Others

  • org.bukkit.configuration.serialization.ConfigurationSerializable : ItemStack, Location, ...
  • java.util.UUID
  • java.time.Instant
  • java.time.LocalTime
  • java.time.LocalDate
  • java.time.LocalDateTime
  • java.time.Year
  • java.time.YearMonth
  • java.time.OffsetTime
  • java.time.OffsetDateTime
  • java.time.ZonedDateTime
  • java.time.Duration
  • java.time.Period
  • Enum classes
  • Inline value classes

Formatted Types

ktConfig provides several formatted types for easier string-based serialization:

These types are automatically serialized to and from their string representations.