diff --git a/module/module-ui/src/main/kotlin/taboolib/module/ui/MenuBuilder.kt b/module/module-ui/src/main/kotlin/taboolib/module/ui/MenuBuilder.kt index 084c35e0a..541c9e149 100644 --- a/module/module-ui/src/main/kotlin/taboolib/module/ui/MenuBuilder.kt +++ b/module/module-ui/src/main/kotlin/taboolib/module/ui/MenuBuilder.kt @@ -61,10 +61,10 @@ inline fun HumanEntity.openMenu(title: String = "chest", buil /** * 打开一个构建后的菜单 */ -fun HumanEntity.openMenu(buildMenu: Inventory) { +fun HumanEntity.openMenu(buildMenu: Inventory, changeId: Boolean = true) { try { if (buildMenu is VirtualInventory) { - val remoteInventory = openVirtualInventory(buildMenu) + val remoteInventory = openVirtualInventory(buildMenu, changeId) val basic = MenuHolder.fromInventory(buildMenu) if (basic != null) { remoteInventory.inject(basic) diff --git a/module/module-ui/src/main/kotlin/taboolib/module/ui/type/Basic.kt b/module/module-ui/src/main/kotlin/taboolib/module/ui/type/Basic.kt index 5949d2b90..d76a059c0 100644 --- a/module/module-ui/src/main/kotlin/taboolib/module/ui/type/Basic.kt +++ b/module/module-ui/src/main/kotlin/taboolib/module/ui/type/Basic.kt @@ -346,7 +346,7 @@ open class Basic(title: String = "chest") : Menu(title) { // 重新构建页面 build() // 重新打开页面 - viewers.forEach { it.openMenu(lastInventory) } + viewers.forEach { it.openMenu(lastInventory, changeId = false) } } catch (ex: Throwable) { ex.printStackTrace() } diff --git a/module/module-ui/src/main/kotlin/taboolib/module/ui/type/Stored.kt b/module/module-ui/src/main/kotlin/taboolib/module/ui/type/Stored.kt index 076bacc05..5ea089faa 100644 --- a/module/module-ui/src/main/kotlin/taboolib/module/ui/type/Stored.kt +++ b/module/module-ui/src/main/kotlin/taboolib/module/ui/type/Stored.kt @@ -18,7 +18,7 @@ open class Stored(title: String) : Basic(title) { /** 被改写 Rule 的 Stored 不支持虚拟页面 */ override fun virtualize(storageContents: List?) { - if (rule == EmptyRule) throw UnsupportedOperationException("Stored does not support virtual pages.") + if (rule != EmptyRule) throw UnsupportedOperationException("Stored does not support virtual pages.") else super.virtualize(storageContents) } diff --git a/module/module-ui/src/main/kotlin/taboolib/module/ui/virtual/InventoryHandler.kt b/module/module-ui/src/main/kotlin/taboolib/module/ui/virtual/InventoryHandler.kt index de8e5c5fe..3faeff35c 100644 --- a/module/module-ui/src/main/kotlin/taboolib/module/ui/virtual/InventoryHandler.kt +++ b/module/module-ui/src/main/kotlin/taboolib/module/ui/virtual/InventoryHandler.kt @@ -29,7 +29,7 @@ abstract class InventoryHandler { abstract fun parseToCraftChatMessage(source: String): Any - abstract fun openInventory(player: Player, inventory: VirtualInventory, cursorItem: ItemStack = player.itemOnCursor): RemoteInventory + abstract fun openInventory(player: Player, inventory: VirtualInventory, cursorItem: ItemStack = player.itemOnCursor, updateId: Boolean = true): RemoteInventory @PlatformSide([Platform.BUKKIT]) companion object { @@ -40,11 +40,13 @@ abstract class InventoryHandler { val playerRemoteInventoryMap = ConcurrentHashMap() - fun getContainerCounter(player: Player): Int { + fun getContainerCounter(player: Player, updateId: Boolean = true): Int { val id = playerContainerCounterMap.computeIfAbsent(player.name) { 0 } - val newId = id % 100 + 1 - playerContainerCounterMap[player.name] = newId - return newId + return if (updateId) { + val newId = id % 100 + 1 + playerContainerCounterMap[player.name] = newId + newId + } else id } @SubscribeEvent diff --git a/module/module-ui/src/main/kotlin/taboolib/module/ui/virtual/InventoryHandlerImpl.kt b/module/module-ui/src/main/kotlin/taboolib/module/ui/virtual/InventoryHandlerImpl.kt index 6f2c637f1..8e636e534 100644 --- a/module/module-ui/src/main/kotlin/taboolib/module/ui/virtual/InventoryHandlerImpl.kt +++ b/module/module-ui/src/main/kotlin/taboolib/module/ui/virtual/InventoryHandlerImpl.kt @@ -53,8 +53,8 @@ class InventoryHandlerImpl : InventoryHandler() { } } - override fun openInventory(player: Player, inventory: VirtualInventory, cursorItem: ItemStack): RemoteInventory { - val id = getContainerCounter(player) + override fun openInventory(player: Player, inventory: VirtualInventory, cursorItem: ItemStack, updateId: Boolean): RemoteInventory { + val id = getContainerCounter(player, updateId) when (major) { // 1.8 1.9, 1.10, 1.11, 1.12 // public static String getNotchInventoryType(InventoryType type) diff --git a/module/module-ui/src/main/kotlin/taboolib/module/ui/virtual/VirtualInventoryFactory.kt b/module/module-ui/src/main/kotlin/taboolib/module/ui/virtual/VirtualInventoryFactory.kt index e6c756320..227f479d0 100644 --- a/module/module-ui/src/main/kotlin/taboolib/module/ui/virtual/VirtualInventoryFactory.kt +++ b/module/module-ui/src/main/kotlin/taboolib/module/ui/virtual/VirtualInventoryFactory.kt @@ -25,8 +25,8 @@ fun Inventory.virtualize(storageContents: List? = null): VirtualInven /** * 使玩家打开虚拟页面 */ -fun HumanEntity.openVirtualInventory(inventory: VirtualInventory): RemoteInventory { - val remoteInventory = InventoryHandler.instance.openInventory(this as Player, inventory, ItemStack(Material.AIR)) +fun HumanEntity.openVirtualInventory(inventory: VirtualInventory, updateId: Boolean = true): RemoteInventory { + val remoteInventory = InventoryHandler.instance.openInventory(this as Player, inventory, ItemStack(Material.AIR), updateId) inventory.remoteInventory = remoteInventory InventoryHandler.playerRemoteInventoryMap[name] = remoteInventory // 唤起事件