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 11plugins  {
2-     id ' org.jetbrains.kotlin.jvm' ' 1.8.21 ' 
2+     id ' org.jetbrains.kotlin.jvm' ' 1.9.22 ' 
33    id ' kr.entree.spigradle' ' 2.4.3' 
4-     id ' org.jetbrains.kotlin.plugin.serialization' ' 1.8.21 ' 
4+     id ' org.jetbrains.kotlin.plugin.serialization' ' 1.9.22 ' 
55    id ' com.github.johnrengelman.shadow' ' 8.1.1' 
66    id ' maven-publish' 
77    id ' signing' 
88}
99
1010group =  ' io.typst' 
11- version =  ' 1.0 .0' 
11+ version =  ' 1.1 .0' 
1212
1313repositories  {
1414    mavenCentral()
1515}
1616
1717dependencies  {
1818    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 ' 
2121    testImplementation ' org.jetbrains.kotlin:kotlin-test' 
2222}
2323
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