Skip to content

Commit

Permalink
fix lag prevention generating new lags
Browse files Browse the repository at this point in the history
  • Loading branch information
acrylic-style committed Nov 9, 2024
1 parent 2e2698b commit eb0e589
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/main/java/com/github/mori01231/lifecore/util/MapUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import org.bukkit.map.MapCanvas
import org.bukkit.map.MapRenderer
import org.bukkit.map.MapView
import org.bukkit.plugin.java.JavaPlugin
import java.util.Collections

object MapUtil {
private fun convertCanvasToSerializable(canvas: MapCanvas) =
Expand All @@ -45,7 +46,7 @@ object MapUtil {
fun MapView.getCanvases() =
CraftMapView::class.java.getDeclaredField("canvases").apply { isAccessible = true }[this] as Map<MapRenderer, Map<CraftPlayer, CraftMapCanvas>>

private val renderedMapViews = mutableListOf<Pair<Player, CraftMapView>>()
private val renderedMapViews = Collections.synchronizedList(mutableListOf<Pair<Player, CraftMapView>>())

fun initializeMapRenderer(player: Player, item: ItemStack) {
if (item.type != Material.FILLED_MAP) return
Expand All @@ -54,10 +55,10 @@ object MapUtil {
val hasRenderer = mapView.renderers.isNotEmpty()
if (hasRenderer && mapView.renderers[0] !is CraftMapRenderer) {
if (mapView is CraftMapView) {
if (renderedMapViews.contains(player to mapView)) return
renderedMapViews.add(player to mapView)
Bukkit.getScheduler().runTask(JavaPlugin.getPlugin(LifeCore::class.java), Runnable {
if (renderedMapViews.contains(player to mapView)) return@Runnable
mapView.render(player as CraftPlayer)
renderedMapViews.add(player to mapView)
})
}
return
Expand Down

0 comments on commit eb0e589

Please sign in to comment.