Repository navigation
Kotlin extensions
Denis Istratov edited this page Jul 29, 2023
·
20 revisions
For class
@Serializable
data class Test(val id: Int, val name: String)import me.redtea.carcadex.kotlin.extensions.*
val json = Json { prettyPrint = true }
val repo = repo<String, Test>(File("data")) {
save {
json.encodeToString(it)
}
load {
json.decodeFromString(it)
}
}import me.redtea.carcadex.kotlin.extensions.*
val json = Json { prettyPrint = true }
val repo = repo<String, Test>(File("data/test")) {
save = json::encodeToString
load = json::decodeFromString
filenameExtension = "json" //no reqiured, default - empty string
}import me.redtea.carcadex.kotlin.extensions.*
val plugin: Plugin = this
val json = Json { prettyPrint = true }
val repo = repo<String, Test>("tests", plugin) {
save = json::encodeToString
load = json::decodeFromString
fileExt = "json" //not requires
}
//or
val testRepo = repo<String, Test>(plugin) { ... } //foldername it will be delivered automatically by the name of the class of value
import me.redtea.carcadex.kotlin.extensions.*
val schema: SchemaStrategy<String, Test> = ..
val repo = repo<String, Test> {
schemaStrategy = schema
//also you can use all optional functions of RepoBuilder
concurrent()
}Also you can use simple set syntax
val repo = ...
repo["Key"] = Value("Key", ...)messages {
legacy = false //will legacy format be used? not requires, default - false
this.plugin = this //your plugin, requires
//Chose one:
fileName = "messages.yml" //name of messages file, not requires, default - messages.yml
file = File("messages") //messages file, not requires, default - File(plugin.dataFolder, fileName)
verifier = FileMessageVerifier(..) //messages verifier, not requires, it has default verifier if set plugin and fileName
}fun CommandSender.send(message: Message) //sends message to player
fun matchMaterial(material: String): Material //get material from string