Skip to content

Commit

Permalink
feat: add /lifecoreutil resetMapId
Browse files Browse the repository at this point in the history
  • Loading branch information
acrylic-style committed Sep 1, 2024
1 parent 49cc3ed commit bb41481
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ plugins {
}

group = "net.azisaba"
version = "1.15.2+6.17.0"
version = "1.15.2+6.17.1"

java {
toolchain.languageVersion.set(JavaLanguageVersion.of(8))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,18 @@ class LifeCoreUtilCommand(val plugin: LifeCore) : TabExecutor {
MapUtil.initializeMapRenderer((player as Player), player.inventory.itemInMainHand)
}
},
ResetMapId("地図IDをリセットします") {
override fun execute(plugin: LifeCore, player: CommandSender, args: Array<String>) {
player as Player
val meta = player.inventory.itemInMainHand.itemMeta as? MapMeta? ?: return player.sendMessage("this is not a map")
val mapView = meta.mapView ?: return player.sendMessage("mapView is null")
if (mapView.renderers.isEmpty() || mapView.renderers.filterIsInstance<CraftMapRenderer>().isNotEmpty()) {
return player.sendMessage("renderers[0] is an instance of CraftMapRenderer or is null")
}
meta.mapView = Bukkit.createMap(player.world)
player.inventory.setItemInMainHand(player.inventory.itemInMainHand.apply { itemMeta = meta })
}
},
FixItem("displayタグを修正します") {
override fun execute(plugin: LifeCore, player: CommandSender, args: Array<String>) {
val item = (player as Player).inventory.itemInMainHand
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/com/github/mori01231/lifecore/util/MapUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ object MapUtil {
if (item.type != Material.FILLED_MAP) return
val meta = item.itemMeta as? MapMeta? ?: return
val mapView = meta.mapView ?: return
if (mapView.renderers.getOrNull(0) !is CraftMapRenderer) {
val hasRenderer = mapView.renderers.isNotEmpty()
if (hasRenderer && mapView.renderers[0] !is CraftMapRenderer) {
if (mapView is CraftMapView) mapView.render(player as CraftPlayer)
return
}
Expand All @@ -59,7 +60,9 @@ object MapUtil {
} catch (_: Exception) {
return
}
mapView.removeRenderer(mapView.renderers[0])
if (hasRenderer) {
mapView.removeRenderer(mapView.renderers[0])
}
mapView.addRenderer(SerializedMapDataRenderer(serializedMapData))
if (mapView is CraftMapView) mapView.render(player as CraftPlayer)
}
Expand Down

0 comments on commit bb41481

Please sign in to comment.