diff --git a/module/module-nms-util-legacy/src/main/kotlin/taboolib/module/nms/NMSMap.kt b/module/module-nms-util-legacy/src/main/kotlin/taboolib/module/nms/NMSMap.kt index 69d84aea6..d7dbac42b 100644 --- a/module/module-nms-util-legacy/src/main/kotlin/taboolib/module/nms/NMSMap.kt +++ b/module/module-nms-util-legacy/src/main/kotlin/taboolib/module/nms/NMSMap.kt @@ -9,6 +9,7 @@ import org.bukkit.map.MapCanvas import org.bukkit.map.MapRenderer import org.bukkit.map.MapView import org.tabooproject.reflex.Reflex.Companion.getProperty +import org.tabooproject.reflex.Reflex.Companion.invokeConstructor import org.tabooproject.reflex.Reflex.Companion.invokeMethod import org.tabooproject.reflex.Reflex.Companion.setProperty import org.tabooproject.reflex.Reflex.Companion.unsafeInstance @@ -190,7 +191,7 @@ fun BufferedImage.zoomed(width: Int = 128, height: Int = 128): BufferedImage { class NMSMap(val image: BufferedImage, var hand: Hand = Hand.MAIN, val builder: ItemBuilder.() -> Unit = {}) { enum class Hand { - + MAIN, OFF } @@ -200,7 +201,18 @@ class NMSMap(val image: BufferedImage, var hand: Hand = Hand.MAIN, val builder: val classPacketPlayOutMap = nmsClass("PacketPlayOutMap") val classCraftItemStack = obcClass("inventory.CraftItemStack") val classMapIcon by unsafeLazy { nmsClass("MapIcon") } - val classMapData: Class<*> by unsafeLazy { Class.forName("net.minecraft.world.level.saveddata.maps.WorldMap\$b") } + val classMapData: Class<*> by unsafeLazy { + when { + MinecraftVersion.isHigherOrEqual(MinecraftVersion.V1_20) -> { + Class.forName("net.minecraft.world.level.saveddata.maps.WorldMap.b") + } + + else -> { + Class.forName("net.minecraft.world.level.saveddata.maps.WorldMap\$b") + } + } + } + val classMapId: Class<*> by unsafeLazy { Class.forName("net.minecraft.world.level.saveddata.maps.MapId") } } val mapRenderer = object : MapRenderer() { @@ -266,6 +278,34 @@ class NMSMap(val image: BufferedImage, var hand: Hand = Hand.MAIN, val builder: val buffer = mapView.invokeMethod("render", player)!!.getProperty("buffer") val packet = classPacketPlayOutMap.unsafeInstance() when { + // 1.21+ + MinecraftVersion.isHigherOrEqual(MinecraftVersion.V1_21) -> { + packet.setProperty("mapId", classMapId.invokeConstructor((mapItem.itemMeta as MapMeta).mapId)) + packet.setProperty("scale", mapView.scale.value) + packet.setProperty("locked", false) + packet.setProperty("decorations", ArrayList()) + packet.setProperty("colorPatch", classMapData.unsafeInstance().also { + it.setProperty("startX", 0) + it.setProperty("startY", 0) + it.setProperty("width", 128) + it.setProperty("height", 128) + it.setProperty("mapColors", buffer) + }) + } + // 1.20+ + MinecraftVersion.isHigherOrEqual(MinecraftVersion.V1_20) -> { + packet.setProperty("mapId", mapView.id) + packet.setProperty("scale", mapView.scale.value) + packet.setProperty("locked", false) + packet.setProperty("decorations", ArrayList()) + packet.setProperty("colorPatch", classMapData.unsafeInstance().also { + it.setProperty("startX", 0) + it.setProperty("startY", 0) + it.setProperty("width", 128) + it.setProperty("height", 128) + it.setProperty("mapColors", buffer) + }) + } // 1.17+ MinecraftVersion.isUniversal -> { packet.setProperty("mapId", (mapItem.itemMeta as MapMeta).mapId) @@ -331,4 +371,4 @@ class NMSMap(val image: BufferedImage, var hand: Hand = Hand.MAIN, val builder: } return player.inventory.heldItemSlot + 36 } -} \ No newline at end of file +}