Skip to content

Commit

Permalink
Merge branch 'master' into ver/1.20.2
Browse files Browse the repository at this point in the history
# Conflicts:
#	build.gradle.kts
#	src/main/java/com/github/mori01231/lifecore/LifeCore.kt
#	src/main/java/com/github/mori01231/lifecore/util/MapUtil.kt
  • Loading branch information
acrylic-style committed Nov 9, 2024
2 parents ebd7b5d + 2e2698b commit 3d46ad9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ plugins {
}

group = "net.azisaba"
version = "6.18.0+1.20.2"
version = "6.18.1+1.20.2"

java {
toolchain.languageVersion.set(JavaLanguageVersion.of(17))
Expand Down
11 changes: 7 additions & 4 deletions src/main/java/com/github/mori01231/lifecore/LifeCore.kt
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,13 @@ class LifeCore : JavaPlugin() {
if (Bukkit.getOnlinePlayers().isEmpty()) return@Runnable
Bukkit.getWorlds().forEach world@ { world ->
world.getEntitiesByClass(ItemFrame::class.java).forEach { itemFrame ->
Bukkit.getOnlinePlayers().forEach { player ->
MapUtil.checkMapView(itemFrame.item)?.let { itemFrame.setItem(it, false) }
MapUtil.initializeMapRenderer(player, itemFrame.item)
}
Bukkit.getScheduler().runTaskAsynchronously(this, Runnable {
val item = itemFrame.item
Bukkit.getOnlinePlayers().forEach { player ->
MapUtil.checkMapView(itemFrame.item)?.let { itemFrame.setItem(it, false) }
MapUtil.initializeMapRenderer(player, item)
}
})
}
}
}, 200, 200)
Expand Down
24 changes: 18 additions & 6 deletions src/main/java/com/github/mori01231/lifecore/util/MapUtil.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.mori01231.lifecore.util

import com.github.mori01231.lifecore.LifeCore
import com.github.mori01231.lifecore.map.SerializedMapCanvas
import com.github.mori01231.lifecore.map.SerializedMapDataRenderer
import kotlinx.serialization.encodeToString
Expand All @@ -19,6 +20,7 @@ import org.bukkit.inventory.meta.MapMeta
import org.bukkit.map.MapCanvas
import org.bukkit.map.MapRenderer
import org.bukkit.map.MapView
import org.bukkit.plugin.java.JavaPlugin

object MapUtil {
private fun convertCanvasToSerializable(canvas: MapCanvas) =
Expand Down Expand Up @@ -54,13 +56,21 @@ object MapUtil {
return null
}

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

fun initializeMapRenderer(player: Player, item: ItemStack) {
if (item.type != Material.FILLED_MAP) return
val meta = item.itemMeta as? MapMeta? ?: return
val mapView = meta.mapView ?: return
val hasRenderer = mapView.renderers.isNotEmpty()
if (hasRenderer && mapView.renderers[0] !is CraftMapRenderer) {
if (mapView is CraftMapView) mapView.render(player as CraftPlayer)
if (mapView is CraftMapView) {
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
}
val serializedMapData =
Expand All @@ -72,10 +82,12 @@ object MapUtil {
} catch (_: Exception) {
return
}
if (hasRenderer) {
mapView.removeRenderer(mapView.renderers[0])
}
mapView.addRenderer(SerializedMapDataRenderer(serializedMapData))
if (mapView is CraftMapView) mapView.render(player as CraftPlayer)
Bukkit.getScheduler().runTask(JavaPlugin.getPlugin(LifeCore::class.java), Runnable {
if (hasRenderer) {
mapView.removeRenderer(mapView.renderers[0])
}
mapView.addRenderer(SerializedMapDataRenderer(serializedMapData))
if (mapView is CraftMapView) mapView.render(player as CraftPlayer)
})
}
}

0 comments on commit 3d46ad9

Please sign in to comment.