Key registration changes

This commit is contained in:
Auxilor
2022-02-16 17:38:07 +00:00
parent ad3cb3a620
commit 7b6c8d68a8
2 changed files with 31 additions and 10 deletions

View File

@@ -41,7 +41,7 @@ class MySQLDataHandler(
handler,
UUIDTable("eco_players"),
plugin,
plugin.dataYml.getStrings("known-player-keys")
plugin.dataYml.getStrings("categorized-keys.player")
.mapNotNull { NamespacedKeyUtils.fromStringOrNull(it) }
)
@@ -49,7 +49,7 @@ class MySQLDataHandler(
handler,
UUIDTable("eco_server"),
plugin,
plugin.dataYml.getStrings("known-server-keys")
plugin.dataYml.getStrings("categorized-keys.server")
.mapNotNull { NamespacedKeyUtils.fromStringOrNull(it) }
)
@@ -86,11 +86,11 @@ class MySQLDataHandler(
override fun save() {
plugin.dataYml.set(
"known-player-keys",
"categorized-keys.player",
playerHandler.registeredKeys.map { it.toString() }
)
plugin.dataYml.set(
"known-server-keys",
"categorized-keys.server",
serverHandler.registeredKeys.map { it.toString() }
)
plugin.dataYml.save()
@@ -106,7 +106,7 @@ class MySQLDataHandler(
private class ImplementedMySQLHandler(
private val handler: EcoProfileHandler,
private val table: UUIDTable,
plugin: EcoPlugin,
private val plugin: EcoPlugin,
private val knownKeys: Collection<NamespacedKey>
) {
private val columns = mutableMapOf<String, Column<*>>()
@@ -144,8 +144,20 @@ private class ImplementedMySQLHandler(
}
fun runPostInit() {
for (key in knownKeys) {
ensureKeyRegistration(key)
plugin.logger.info("Loading known keys: $knownKeys")
val persistentKeys = knownKeys
.mapNotNull { Eco.getHandler().keyRegistry.getKeyFrom(it) }
transaction {
for (key in persistentKeys) {
registerColumn(key, table)
}
SchemaUtils.createMissingTablesAndColumns(table, withLogs = false)
for (key in persistentKeys) {
registeredKeys.add(key.key)
}
}
}
@@ -156,11 +168,17 @@ private class ImplementedMySQLHandler(
val persistentKey = Eco.getHandler().keyRegistry.getKeyFrom(key) ?: return
if (table.columns.any { it.name == key.toString() }) {
registeredKeys.add(key)
return
}
transaction {
registerColumn(persistentKey, table)
SchemaUtils.createMissingTablesAndColumns(table, withLogs = false)
registeredKeys.add(key)
}
registeredKeys.add(key)
}
fun <T> write(uuid: UUID, key: NamespacedKey, value: T) {
@@ -215,6 +233,8 @@ private class ImplementedMySQLHandler(
return@Callable value
}
ensureKeyRegistration(key) // DON'T DELETE THIS LINE! I know it's covered in getColumn, but I need to do it here as well.
return if (Eco.getHandler().ecoPlugin.configYml.getBool("mysql.async-reads")) {
executor.submit(doRead).get()
} else {

View File

@@ -1,4 +1,5 @@
# For internal storage use only, do not modify.
known-player-keys: []
known-server-keys: []
categorized-keys:
player: []
server: []