File tree Expand file tree Collapse file tree
src/main/kotlin/net.quiltservertools.ledger.databases Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ Add the following to the bottom of your Ledger config file:
1414
1515``` toml
1616[database_extensions ]
17- h2 = true
17+ database = " H2 "
1818```
1919
2020## MySQL
@@ -23,7 +23,7 @@ Add the following to the bottom of your Ledger config file:
2323
2424``` toml
2525[database_extensions ]
26- mysql = true
26+ database = " MYSQL "
2727url = " "
2828username = " "
2929password = " "
Original file line number Diff line number Diff line change @@ -3,8 +3,7 @@ package net.quiltservertools.ledger.databases
33import com.github.quiltservertools.libs.com.uchuhimo.konf.ConfigSpec
44
55object DatabaseExtensionSpec : ConfigSpec(" database_extensions" ) {
6- val h2 by optional(false , " h2" )
7- val mySql by optional(false , " mysql" )
6+ val database by optional(Databases .SQLITE , " database" )
87 val userName by optional(" root" , " username" )
98 val password by optional(" " , " password" )
109 val url by optional(" localhost" , " url" )
Original file line number Diff line number Diff line change 1+ package net.quiltservertools.ledger.databases
2+
3+ enum class Databases {
4+ SQLITE ,
5+ MYSQL ,
6+ H2
7+ }
Original file line number Diff line number Diff line change @@ -13,12 +13,12 @@ class LedgerDatabaseExtension : DatabaseExtension {
1313 override fun getConfigSpecs (): List <ConfigSpec > = listOf (DatabaseExtensionSpec )
1414
1515 override fun getDatabase (server : MinecraftServer ): Database {
16- if (Ledger .config[DatabaseExtensionSpec .h2] ) {
16+ if (Ledger .config[DatabaseExtensionSpec .database] == Databases . H2 ) {
1717 return Database .connect(
1818 url = " jdbc:h2:${server.getSavePath(WorldSavePath .ROOT ).resolve(" ledger.h2" ).toFile()} ;MODE=MySQL" ,
1919 driver = " org.h2.Driver"
2020 )
21- } else if (Ledger .config[DatabaseExtensionSpec .mySql] ) {
21+ } else if (Ledger .config[DatabaseExtensionSpec .database] == Databases . MYSQL ) {
2222 return Database .connect(
2323 url = " jdbc:mysql://${Ledger .config[DatabaseExtensionSpec .url]} ?rewriteBatchedStatements=true" ,
2424 driver = " com.mysql.cj.jdbc.Driver" ,
@@ -30,9 +30,9 @@ class LedgerDatabaseExtension : DatabaseExtension {
3030 }
3131
3232 override fun getIdentifier (): Identifier {
33- if (Ledger .config.contains( DatabaseExtensionSpec .h2) && Ledger .config[ DatabaseExtensionSpec .h2] ) {
33+ if (Ledger .config[ DatabaseExtensionSpec .database] == Databases . H2 ) {
3434 return h2Identifier
35- } else if (Ledger .config.contains( DatabaseExtensionSpec .mySql) && Ledger .config[ DatabaseExtensionSpec .mySql] ) {
35+ } else if (Ledger .config[ DatabaseExtensionSpec .database] == Databases . MYSQL ) {
3636 return mySqlIdentifier
3737
3838 }
You can’t perform that action at this time.
0 commit comments