Improved pet tick performance

This commit is contained in:
Auxilor
2022-06-18 11:53:34 +01:00
parent 428df89ed1
commit 6dcfd4ccaa
2 changed files with 15 additions and 7 deletions

View File

@@ -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()
}
}

View File

@@ -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<UUID, ArmorStand>()
private val trackedEntities = Collections.synchronizedMap(mutableMapOf<UUID, ArmorStand>())
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) {