diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/EcoProfile.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/EcoProfile.kt index ef47db56..00761b20 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/EcoProfile.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/EcoProfile.kt @@ -16,9 +16,7 @@ abstract class EcoProfile( override fun write(key: PersistentDataKey, value: T) { this.data[key] = value - val changedKeys = CHANGE_MAP[uuid] ?: mutableSetOf() - changedKeys.add(key) - CHANGE_MAP[uuid] = changedKeys + CHANGE_MAP.add(uuid) } override fun read(key: PersistentDataKey): T { @@ -44,7 +42,7 @@ abstract class EcoProfile( } companion object { - val CHANGE_MAP: MutableMap>> = ConcurrentHashMap() + val CHANGE_MAP: MutableSet = ConcurrentHashMap.newKeySet() } } diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/ProfileHandler.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/ProfileHandler.kt index f1130e80..dceced25 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/ProfileHandler.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/ProfileHandler.kt @@ -22,7 +22,7 @@ class ProfileHandler( private val type: HandlerType, private val plugin: EcoSpigotPlugin ) { - private val loaded = mutableMapOf() + val loaded = mutableMapOf() val handler: DataHandler = when (type) { HandlerType.YAML -> YamlDataHandler(plugin, this) diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/ProfileSaver.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/ProfileSaver.kt index 43b66f92..ff9583be 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/ProfileSaver.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/ProfileSaver.kt @@ -12,10 +12,20 @@ class ProfileSaver( val interval = plugin.configYml.getInt("save-interval").toLong() plugin.scheduler.runTimer(20, interval) { - for ((uuid, set) in EcoProfile.CHANGE_MAP) { - handler.saveKeysFor(uuid, set) + val iterator = EcoProfile.CHANGE_MAP.iterator() + + while (iterator.hasNext()) { + val uuid = iterator.next() + iterator.remove() + + val profile = handler.loaded[uuid] ?: continue + + if (profile !is EcoProfile) { + continue + } + + handler.saveKeysFor(uuid, profile.data.keys) } - EcoProfile.CHANGE_MAP.clear() } } }