diff --git a/bukkit/src/main/kotlin/com/aiyostudio/esync/internal/module/entity/EnderChestEntity.kt b/bukkit/src/main/kotlin/com/aiyostudio/esync/internal/module/entity/EnderChestEntity.kt index 9435158..6078fdc 100644 --- a/bukkit/src/main/kotlin/com/aiyostudio/esync/internal/module/entity/EnderChestEntity.kt +++ b/bukkit/src/main/kotlin/com/aiyostudio/esync/internal/module/entity/EnderChestEntity.kt @@ -1,17 +1,23 @@ package com.aiyostudio.esync.internal.module.entity import com.aiyostudio.esync.common.module.IEntity +import com.aiyostudio.esync.internal.plugin.EfficientSyncBukkit import org.bukkit.entity.Player import org.bukkit.inventory.ItemStack +import java.util.logging.Level class EnderChestEntity : IEntity { val items = mutableMapOf() override fun apply(player: Any): Boolean { - if (player is Player) { - player.enderChest.clear() - items.forEach { (slot, item) -> player.enderChest.setItem(slot, item) } - return true + try { + if (player is Player) { + player.enderChest.clear() + items.forEach { (slot, item) -> player.enderChest.setItem(slot, item) } + return true + } + } catch (e: Exception) { + EfficientSyncBukkit.instance.logger.log(Level.WARNING, e) { "Failed to apply 'ender-chest' data for ${(player as Player).uniqueId}" } } return false } diff --git a/bukkit/src/main/kotlin/com/aiyostudio/esync/internal/module/entity/PlayerInventoryEntity.kt b/bukkit/src/main/kotlin/com/aiyostudio/esync/internal/module/entity/PlayerInventoryEntity.kt index 5c77ba7..f7db743 100644 --- a/bukkit/src/main/kotlin/com/aiyostudio/esync/internal/module/entity/PlayerInventoryEntity.kt +++ b/bukkit/src/main/kotlin/com/aiyostudio/esync/internal/module/entity/PlayerInventoryEntity.kt @@ -1,17 +1,23 @@ package com.aiyostudio.esync.internal.module.entity import com.aiyostudio.esync.common.module.IEntity +import com.aiyostudio.esync.internal.plugin.EfficientSyncBukkit import org.bukkit.entity.Player import org.bukkit.inventory.ItemStack +import java.util.logging.Level class PlayerInventoryEntity : IEntity { val inventory = mutableMapOf() override fun apply(player: Any): Boolean { - if (player is Player) { - player.inventory.clear() - inventory.forEach { (slot, item) -> player.inventory.setItem(slot, item) } - return true + try { + if (player is Player) { + player.inventory.clear() + inventory.forEach { (slot, item) -> player.inventory.setItem(slot, item) } + return true + } + } catch (e: Exception) { + EfficientSyncBukkit.instance.logger.log(Level.WARNING, e) { "Failed to apply 'inventory' data for ${(player as Player).uniqueId}" } } return false } diff --git a/bukkit/src/main/kotlin/com/aiyostudio/esync/internal/module/entity/PlayerStatusEntity.kt b/bukkit/src/main/kotlin/com/aiyostudio/esync/internal/module/entity/PlayerStatusEntity.kt index 5be82da..51ff1a1 100644 --- a/bukkit/src/main/kotlin/com/aiyostudio/esync/internal/module/entity/PlayerStatusEntity.kt +++ b/bukkit/src/main/kotlin/com/aiyostudio/esync/internal/module/entity/PlayerStatusEntity.kt @@ -1,9 +1,11 @@ package com.aiyostudio.esync.internal.module.entity import com.aiyostudio.esync.common.module.IEntity +import com.aiyostudio.esync.internal.plugin.EfficientSyncBukkit import org.bukkit.attribute.Attribute import org.bukkit.entity.Player import org.bukkit.potion.PotionEffect +import java.util.logging.Level class PlayerStatusEntity : IEntity { val potions = mutableListOf() @@ -11,11 +13,15 @@ class PlayerStatusEntity : IEntity { var maxHealth = 20.0 override fun apply(player: Any): Boolean { - if (player is Player) { - player.getAttribute(Attribute.GENERIC_MAX_HEALTH).baseValue = maxHealth - player.health = health - potions.forEach { player.addPotionEffect(it) } - return true + try { + if (player is Player) { + player.getAttribute(Attribute.GENERIC_MAX_HEALTH).baseValue = maxHealth + player.health = health + potions.forEach { player.addPotionEffect(it) } + return true + } + } catch (e: Exception) { + EfficientSyncBukkit.instance.logger.log(Level.WARNING, e) { "Failed to apply 'player-status' data for ${(player as Player).uniqueId}" } } return false } diff --git a/bukkit/src/main/kotlin/com/aiyostudio/esync/internal/module/impl/InventoryModuleImpl.kt b/bukkit/src/main/kotlin/com/aiyostudio/esync/internal/module/impl/InventoryModuleImpl.kt index b3ad12e..350ba65 100644 --- a/bukkit/src/main/kotlin/com/aiyostudio/esync/internal/module/impl/InventoryModuleImpl.kt +++ b/bukkit/src/main/kotlin/com/aiyostudio/esync/internal/module/impl/InventoryModuleImpl.kt @@ -68,7 +68,7 @@ class InventoryModuleImpl( val slot = byteBuf.readInt() val length = byteBuf.readInt() val bytes = ByteArray(length) - byteBuf.readBytes(length) + byteBuf.readBytes(bytes) val item = SerializerUtil.deserializerItem(bytes) entity.inventory[slot] = item } diff --git a/bukkit/src/main/kotlin/com/aiyostudio/esync/internal/module/impl/PlayerStatusModuleImpl.kt b/bukkit/src/main/kotlin/com/aiyostudio/esync/internal/module/impl/PlayerStatusModuleImpl.kt index 8f56234..ed0fbe5 100644 --- a/bukkit/src/main/kotlin/com/aiyostudio/esync/internal/module/impl/PlayerStatusModuleImpl.kt +++ b/bukkit/src/main/kotlin/com/aiyostudio/esync/internal/module/impl/PlayerStatusModuleImpl.kt @@ -74,9 +74,8 @@ class PlayerStatusModuleImpl( val str = String(byteArray, Charsets.UTF_8) val yaml = YamlConfiguration() yaml.loadFromString(str) - val map = yaml.getConfigurationSection("potion").getValues(false) - val option = ConfigurationSerialization.deserializeObject(map, PotionEffect::class.java) as PotionEffect - result.potions.add(option) + val potion = yaml.get("potion") as PotionEffect + result.potions.add(potion) } return result } diff --git a/bukkit/src/main/kotlin/com/aiyostudio/esync/internal/transaction/SyncTransaction.kt b/bukkit/src/main/kotlin/com/aiyostudio/esync/internal/transaction/SyncTransaction.kt index 7bf2c93..7db1ddc 100644 --- a/bukkit/src/main/kotlin/com/aiyostudio/esync/internal/transaction/SyncTransaction.kt +++ b/bukkit/src/main/kotlin/com/aiyostudio/esync/internal/transaction/SyncTransaction.kt @@ -64,8 +64,12 @@ class SyncTransaction( val repository = RepositoryHandler.repository ?: return this.modules.forEach { repository.updateState(uuid, it, SyncState.LOCKED) - val module = ModuleHandler.findByKey(it)!! - module.apply(player.uniqueId) + Bukkit.getScheduler().runTask(EfficientSyncBukkit.instance) { + val module = ModuleHandler.findByKey(it)!! + if (module.apply(player.uniqueId)) { + CacheHandler.playerCaches[player.uniqueId]!!.load(module.uniqueKey) + } + } } } } diff --git a/common/src/main/kotlin/com/aiyostudio/esync/common/repository/impl/MysqlRepositoryImpl.kt b/common/src/main/kotlin/com/aiyostudio/esync/common/repository/impl/MysqlRepositoryImpl.kt index 318596b..172b792 100644 --- a/common/src/main/kotlin/com/aiyostudio/esync/common/repository/impl/MysqlRepositoryImpl.kt +++ b/common/src/main/kotlin/com/aiyostudio/esync/common/repository/impl/MysqlRepositoryImpl.kt @@ -146,6 +146,12 @@ class MysqlRepositoryImpl( } private fun connect(block: (connect: Connection) -> Unit) { - with(DriverManager.getConnection(url, user, password)) { block(this) } + with(DriverManager.getConnection(url, user, password)) { + try { + block(this) + } finally { + this.close() + } + } } } \ No newline at end of file