File tree Expand file tree Collapse file tree 3 files changed +33
-6
lines changed
src/main/kotlin/io/typst/bukkit/kotlin/serialization Expand file tree Collapse file tree 3 files changed +33
-6
lines changed Original file line number Diff line number Diff line change 1
1
plugins {
2
- id ' org.jetbrains.kotlin.jvm' version ' 1.8.21 '
2
+ id ' org.jetbrains.kotlin.jvm' version ' 1.9.22 '
3
3
id ' kr.entree.spigradle' version ' 2.4.3'
4
- id ' org.jetbrains.kotlin.plugin.serialization' version ' 1.8.21 '
4
+ id ' org.jetbrains.kotlin.plugin.serialization' version ' 1.9.22 '
5
5
id ' com.github.johnrengelman.shadow' version ' 8.1.1'
6
6
id ' maven-publish'
7
7
id ' signing'
8
8
}
9
9
10
10
group = ' io.typst'
11
- version = ' 1.0 .0'
11
+ version = ' 1.1 .0'
12
12
13
13
repositories {
14
14
mavenCentral()
15
15
}
16
16
17
17
dependencies {
18
18
compileOnly spigot(' 1.16.5' )
19
- implementation ' org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.1 '
20
- testImplementation ' org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.1 '
19
+ implementation ' org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.3 '
20
+ testImplementation ' org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.3 '
21
21
testImplementation ' org.jetbrains.kotlin:kotlin-test'
22
22
}
23
23
Original file line number Diff line number Diff line change
1
+ package io.typst.bukkit.kotlin.serialization
2
+
3
+ import kotlinx.serialization.encodeToString
4
+ import kotlinx.serialization.json.Json
5
+ import org.bukkit.plugin.java.JavaPlugin
6
+ import java.io.File
7
+
8
+ val JavaPlugin .configJsonFile: File get() = File (dataFolder, " config.json" )
9
+
10
+ val bukkitPluginJson: Json by lazy {
11
+ Json {
12
+ encodeDefaults = true
13
+ prettyPrint = true
14
+ }
15
+ }
16
+
17
+ inline fun <reified A > JavaPlugin.readConfigOrCreate (): A {
18
+ val configFile = configJsonFile
19
+ if (configFile.isFile) {
20
+ return bukkitPluginJson.decodeFromString<A >(configJsonFile.readText())
21
+ } else {
22
+ configFile.parentFile.mkdirs()
23
+ val defaultValue = bukkitPluginJson.decodeFromString<A >(" {}" )
24
+ configFile.writeText(bukkitPluginJson.encodeToString<A >(defaultValue))
25
+ return defaultValue
26
+ }
27
+ }
You can’t perform that action at this time.
0 commit comments