diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/EcoPetsPlugin.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/EcoPetsPlugin.kt index e163b3f..4ac9ba6 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/EcoPetsPlugin.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/EcoPetsPlugin.kt @@ -40,7 +40,10 @@ class EcoPetsPlugin : LibReforgePlugin() { override fun handleReloadAdditional() { this.scheduler.runTimer(1, 1) { - petDisplay.tickAll() + petDisplay.tickSync() + } + this.scheduler.runAsyncTimer(1, 1) { + petDisplay.tickAsync() } } diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/pets/PetDisplay.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/pets/PetDisplay.kt index fa9a5ec..cc8fe84 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/pets/PetDisplay.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/pets/PetDisplay.kt @@ -15,25 +15,30 @@ import org.bukkit.inventory.EquipmentSlot import java.util.* import kotlin.math.PI import kotlin.math.abs -import kotlin.math.sin -class PetDisplay( +internal class PetDisplay( private val plugin: EcoPlugin ) : Listener { private var tick = 0 - private val trackedEntities = mutableMapOf() + private val trackedEntities = Collections.synchronizedMap(mutableMapOf()) - fun tickAll() { + fun tickSync() { for (player in Bukkit.getOnlinePlayers()) { - tickPlayer(player) + getOrNew(player) } tick++ } + fun tickAsync() { + for (player in Bukkit.getOnlinePlayers()) { + tickPlayer(player) + } + } + private fun tickPlayer(player: Player) { - val stand = getOrNew(player) ?: return + val stand = trackedEntities[player.uniqueId] ?: return val pet = player.activePet if (pet != null) {