Staggered player profile loading to load when needed
This commit is contained in:
@@ -1,13 +1,15 @@
|
||||
package com.willfp.eco.internal.data
|
||||
package com.willfp.eco.internal.spigot.data
|
||||
|
||||
import com.willfp.eco.core.data.PlayerProfile
|
||||
import com.willfp.eco.core.data.keys.PersistentDataKey
|
||||
import com.willfp.eco.internal.spigot.data.storage.DataHandler
|
||||
import java.util.UUID
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
|
||||
class EcoPlayerProfile(
|
||||
val data: MutableMap<PersistentDataKey<*>, Any>,
|
||||
val uuid: UUID
|
||||
val uuid: UUID,
|
||||
private val handler: DataHandler
|
||||
) : PlayerProfile {
|
||||
override fun <T : Any> write(key: PersistentDataKey<T>, value: T) {
|
||||
this.data[key] = value
|
||||
@@ -19,7 +21,12 @@ class EcoPlayerProfile(
|
||||
|
||||
override fun <T : Any> read(key: PersistentDataKey<T>): T {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
return this.data[key] as T? ?: key.defaultValue
|
||||
if (this.data.containsKey(key)) {
|
||||
return this.data[key] as T
|
||||
}
|
||||
|
||||
this.data[key] = handler.read(uuid, key.key) ?: key.defaultValue
|
||||
return read(key)
|
||||
}
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
@@ -3,7 +3,6 @@ package com.willfp.eco.internal.spigot.data
|
||||
import com.willfp.eco.core.data.PlayerProfile
|
||||
import com.willfp.eco.core.data.PlayerProfileHandler
|
||||
import com.willfp.eco.core.data.keys.PersistentDataKey
|
||||
import com.willfp.eco.internal.data.EcoPlayerProfile
|
||||
import com.willfp.eco.internal.spigot.data.storage.DataHandler
|
||||
import java.util.UUID
|
||||
|
||||
@@ -20,11 +19,7 @@ class EcoPlayerProfileHandler(
|
||||
|
||||
val data = mutableMapOf<PersistentDataKey<*>, Any>()
|
||||
|
||||
for (key in PersistentDataKey.values()) {
|
||||
data[key] = handler.read(uuid, key.key) ?: key.defaultValue
|
||||
}
|
||||
|
||||
val profile = EcoPlayerProfile(data, uuid)
|
||||
val profile = EcoPlayerProfile(data, uuid, handler)
|
||||
loaded[uuid] = profile
|
||||
return profile
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.willfp.eco.internal.spigot.data.storage
|
||||
|
||||
import com.willfp.eco.core.Eco
|
||||
import com.willfp.eco.core.EcoPlugin
|
||||
import com.willfp.eco.internal.data.EcoPlayerProfile
|
||||
import com.willfp.eco.internal.spigot.data.EcoPlayerProfile
|
||||
|
||||
class ProfileSaver(plugin: EcoPlugin) {
|
||||
init {
|
||||
|
||||
Reference in New Issue
Block a user