diff --git a/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/data/EcoPlayerProfile.kt b/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/data/EcoPlayerProfile.kt index ce4bd9c7..b62308b2 100644 --- a/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/data/EcoPlayerProfile.kt +++ b/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/data/EcoPlayerProfile.kt @@ -14,4 +14,20 @@ class EcoPlayerProfile( @Suppress("UNCHECKED_CAST") return this.data[key] as T? ?: key.defaultValue } + + override fun equals(other: Any?): Boolean { + if (other !is EcoPlayerProfile) { + return false + } + + return this.data == other.data + } + + override fun hashCode(): Int { + return data.hashCode() + } + + override fun toString(): String { + return "EcoPlayerProfile{$data}" + } } \ No newline at end of file diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/spigot/data/DataListener.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/spigot/data/DataListener.kt index efb11155..a262cfd6 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/spigot/data/DataListener.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/spigot/data/DataListener.kt @@ -1,6 +1,7 @@ package com.willfp.eco.spigot.data import com.willfp.eco.core.Eco +import com.willfp.eco.core.data.PlayerProfile import com.willfp.eco.util.PlayerUtils import org.bukkit.event.EventHandler import org.bukkit.event.Listener @@ -12,6 +13,7 @@ class DataListener : Listener { @EventHandler fun onLeave(event: PlayerQuitEvent) { PlayerUtils.updateSavedDisplayName(event.player) + Eco.getHandler().ecoPlugin.logger.info("Profile before leave: ${PlayerProfile.load(event.player)}") Eco.getHandler().playerProfileHandler.savePlayerBlocking(event.player.uniqueId) Eco.getHandler().playerProfileHandler.unloadPlayer(event.player.uniqueId) Eco.getHandler().ecoPlugin.logger.info("Player ${event.player.name} Quit (Saving)") @@ -26,6 +28,7 @@ class DataListener : Listener { @EventHandler fun onLogin(event: PlayerLoginEvent) { Eco.getHandler().playerProfileHandler.unloadPlayer(event.player.uniqueId) - Eco.getHandler().ecoPlugin.logger.info("Player ${event.player.name} Logged In (Saving)") + Eco.getHandler().ecoPlugin.logger.info("Player ${event.player.name} Logged In (Unloaded Profile)") + Eco.getHandler().ecoPlugin.logger.info("Profile after join: ${PlayerProfile.load(event.player)}") } } diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/spigot/data/storage/MySQLDataHandler.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/spigot/data/storage/MySQLDataHandler.kt index 5fcac528..62204ae0 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/spigot/data/storage/MySQLDataHandler.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/spigot/data/storage/MySQLDataHandler.kt @@ -12,6 +12,7 @@ import org.jetbrains.exposed.dao.id.UUIDTable import org.jetbrains.exposed.sql.* import org.jetbrains.exposed.sql.transactions.transaction import java.util.* +import java.util.concurrent.Callable import java.util.concurrent.Executors @Suppress("UNCHECKED_CAST") @@ -65,7 +66,7 @@ class MySQLDataHandler( private fun writeAsserted(uuid: UUID, key: NamespacedKey, value: T, async: Boolean = true) { val column: Column = getColumn(key.toString()) as Column - fun executeTransaction() { + val future = executor.submit { transaction { Players.update({ Players.id eq uuid }) { it[column] = value @@ -73,10 +74,8 @@ class MySQLDataHandler( } } - if (async) { - executor.execute { executeTransaction() } - } else { - executeTransaction() + if (!async) { + future.get() } } @@ -109,12 +108,14 @@ class MySQLDataHandler( } override fun read(uuid: UUID, key: NamespacedKey): T? { - var value: T? = null - transaction { - val player = getPlayer(uuid) - value = player[getColumn(key.toString())] as T? - } - return value + return executor.submit(Callable { + var value: T? = null + transaction { + val player = getPlayer(uuid) + value = player[getColumn(key.toString())] as T? + } + return@Callable value + }).get() } object Players : UUIDTable("eco_players")