Key registration changes
This commit is contained in:
@@ -41,7 +41,7 @@ class MySQLDataHandler(
|
|||||||
handler,
|
handler,
|
||||||
UUIDTable("eco_players"),
|
UUIDTable("eco_players"),
|
||||||
plugin,
|
plugin,
|
||||||
plugin.dataYml.getStrings("known-player-keys")
|
plugin.dataYml.getStrings("categorized-keys.player")
|
||||||
.mapNotNull { NamespacedKeyUtils.fromStringOrNull(it) }
|
.mapNotNull { NamespacedKeyUtils.fromStringOrNull(it) }
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -49,7 +49,7 @@ class MySQLDataHandler(
|
|||||||
handler,
|
handler,
|
||||||
UUIDTable("eco_server"),
|
UUIDTable("eco_server"),
|
||||||
plugin,
|
plugin,
|
||||||
plugin.dataYml.getStrings("known-server-keys")
|
plugin.dataYml.getStrings("categorized-keys.server")
|
||||||
.mapNotNull { NamespacedKeyUtils.fromStringOrNull(it) }
|
.mapNotNull { NamespacedKeyUtils.fromStringOrNull(it) }
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -86,11 +86,11 @@ class MySQLDataHandler(
|
|||||||
|
|
||||||
override fun save() {
|
override fun save() {
|
||||||
plugin.dataYml.set(
|
plugin.dataYml.set(
|
||||||
"known-player-keys",
|
"categorized-keys.player",
|
||||||
playerHandler.registeredKeys.map { it.toString() }
|
playerHandler.registeredKeys.map { it.toString() }
|
||||||
)
|
)
|
||||||
plugin.dataYml.set(
|
plugin.dataYml.set(
|
||||||
"known-server-keys",
|
"categorized-keys.server",
|
||||||
serverHandler.registeredKeys.map { it.toString() }
|
serverHandler.registeredKeys.map { it.toString() }
|
||||||
)
|
)
|
||||||
plugin.dataYml.save()
|
plugin.dataYml.save()
|
||||||
@@ -106,7 +106,7 @@ class MySQLDataHandler(
|
|||||||
private class ImplementedMySQLHandler(
|
private class ImplementedMySQLHandler(
|
||||||
private val handler: EcoProfileHandler,
|
private val handler: EcoProfileHandler,
|
||||||
private val table: UUIDTable,
|
private val table: UUIDTable,
|
||||||
plugin: EcoPlugin,
|
private val plugin: EcoPlugin,
|
||||||
private val knownKeys: Collection<NamespacedKey>
|
private val knownKeys: Collection<NamespacedKey>
|
||||||
) {
|
) {
|
||||||
private val columns = mutableMapOf<String, Column<*>>()
|
private val columns = mutableMapOf<String, Column<*>>()
|
||||||
@@ -144,8 +144,20 @@ private class ImplementedMySQLHandler(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun runPostInit() {
|
fun runPostInit() {
|
||||||
for (key in knownKeys) {
|
plugin.logger.info("Loading known keys: $knownKeys")
|
||||||
ensureKeyRegistration(key)
|
|
||||||
|
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
|
val persistentKey = Eco.getHandler().keyRegistry.getKeyFrom(key) ?: return
|
||||||
|
|
||||||
|
if (table.columns.any { it.name == key.toString() }) {
|
||||||
|
registeredKeys.add(key)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
transaction {
|
transaction {
|
||||||
registerColumn(persistentKey, table)
|
registerColumn(persistentKey, table)
|
||||||
SchemaUtils.createMissingTablesAndColumns(table, withLogs = false)
|
SchemaUtils.createMissingTablesAndColumns(table, withLogs = false)
|
||||||
registeredKeys.add(key)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
registeredKeys.add(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun <T> write(uuid: UUID, key: NamespacedKey, value: T) {
|
fun <T> write(uuid: UUID, key: NamespacedKey, value: T) {
|
||||||
@@ -215,6 +233,8 @@ private class ImplementedMySQLHandler(
|
|||||||
return@Callable value
|
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")) {
|
return if (Eco.getHandler().ecoPlugin.configYml.getBool("mysql.async-reads")) {
|
||||||
executor.submit(doRead).get()
|
executor.submit(doRead).get()
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
# For internal storage use only, do not modify.
|
# For internal storage use only, do not modify.
|
||||||
|
|
||||||
known-player-keys: []
|
categorized-keys:
|
||||||
known-server-keys: []
|
player: []
|
||||||
|
server: []
|
||||||
|
|||||||
Reference in New Issue
Block a user