Improved MongoDB

This commit is contained in:
Auxilor
2022-05-25 20:21:50 +01:00
parent 07c0e72564
commit c2b8a80560
4 changed files with 12 additions and 7 deletions

View File

@@ -58,7 +58,11 @@ class EcoHandler : EcoSpigotPlugin(), Handler {
private var adventure: BukkitAudiences? = null
private val keyRegistry = EcoKeyRegistry()
private val playerProfileHandler = EcoProfileHandler(HandlerType.valueOf(this.configYml.getString("data-handler").uppercase()), this)
private val playerProfileHandler = EcoProfileHandler(
HandlerType.valueOf(
this.configYml.getString("data-handler").uppercase()
), this
)
@Suppress("RedundantNullableReturnType")
private val keyFactory: InternalNamespacedKeyFactory? =

View File

@@ -47,9 +47,9 @@ class MongoDataHandler(
val newData = profile.data.apply {
if (value == null) {
this.remove(key)
this.remove(key.toString())
} else {
this[key] = value
this[key.toString()] = value
}
}
@@ -74,7 +74,7 @@ class MongoDataHandler(
private suspend fun <T> doRead(uuid: UUID, key: PersistentDataKey<T>): T? {
val profile = collection.findOne(SerializableProfile::uuid eq uuid) ?: return key.defaultValue
return profile.data[key.key] as? T?
return profile.data[key.key.toString()] as? T?
}
private suspend fun getOrCreateDocument(uuid: UUID): SerializableProfile {
@@ -97,5 +97,6 @@ class MongoDataHandler(
private data class SerializableProfile(
@BsonId
val uuid: UUID,
val data: MutableMap<NamespacedKey, Any>
// Storing NamespacedKeys as strings for serialization
val data: MutableMap<String, Any>
)

View File

@@ -3,7 +3,7 @@
# by Auxilor
#
handler-type: yaml # Pick from yaml/mongo/mysql - MongoDB is recommended over MySQL for networks.
data-handler: yaml # Pick from yaml/mongo/mysql - MongoDB is recommended over MySQL for networks.
mongodb:
# The full MongoDB connection URL.