From e7e7f20ff15865f576521cea7dae39f07581f45e Mon Sep 17 00:00:00 2001 From: Bkm016 Date: Sun, 28 Jan 2024 21:15:58 +0800 Subject: [PATCH] =?UTF-8?q?[6.1.0][dev]=20=E5=AE=8C=E5=96=84=20UI=20?= =?UTF-8?q?=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../taboolib/module/kether/KetherLoader.kt | 2 + .../kotlin/taboolib/module/ui/ClickEvent.kt | 4 +- .../taboolib/module/ui/ClickListener.kt | 10 +- .../main/kotlin/taboolib/module/ui/Menu.kt | 6 +- .../kotlin/taboolib/module/ui/MenuBuilder.kt | 30 +++- .../kotlin/taboolib/module/ui/MenuHolder.kt | 6 +- .../kotlin/taboolib/module/ui/type/Anvil.kt | 2 +- .../kotlin/taboolib/module/ui/type/Basic.kt | 166 +---------------- .../kotlin/taboolib/module/ui/type/Chest.kt | 167 ++++++++++++++++++ .../kotlin/taboolib/module/ui/type/Hopper.kt | 2 +- .../kotlin/taboolib/module/ui/type/Linked.kt | 85 +-------- .../taboolib/module/ui/type/PageableChest.kt | 86 +++++++++ .../taboolib/module/ui/type/StorableChest.kt | 62 +++++++ .../kotlin/taboolib/module/ui/type/Stored.kt | 61 +------ .../taboolib/module/ui/type/impl/AnvilImpl.kt | 2 +- .../type/impl/{BasicImpl.kt => ChestImpl.kt} | 8 +- .../module/ui/type/impl/HopperImpl.kt | 2 +- .../{LinkedImpl.kt => PageableChestImpl.kt} | 4 +- .../{StoredImpl.kt => StorableChestImpl.kt} | 6 +- .../ui/virtual/VirtualInventoryFactory.kt | 10 +- .../taboolib/platform/BukkitOpenContainer.kt | 7 +- ...kitOpenContainer.kt => BukkitContainer.kt} | 2 +- .../taboolib/platform/BungeeOpenContainer.kt | 7 +- ...geeOpenContainer.kt => BungeeContainer.kt} | 2 +- .../platform/VelocityOpenContainer.kt | 13 +- ...yOpenContainer.kt => VelocityContainer.kt} | 2 +- 26 files changed, 410 insertions(+), 344 deletions(-) create mode 100644 module/module-ui/src/main/kotlin/taboolib/module/ui/type/Chest.kt create mode 100644 module/module-ui/src/main/kotlin/taboolib/module/ui/type/PageableChest.kt create mode 100644 module/module-ui/src/main/kotlin/taboolib/module/ui/type/StorableChest.kt rename module/module-ui/src/main/kotlin/taboolib/module/ui/type/impl/{BasicImpl.kt => ChestImpl.kt} (97%) rename module/module-ui/src/main/kotlin/taboolib/module/ui/type/impl/{LinkedImpl.kt => PageableChestImpl.kt} (98%) rename module/module-ui/src/main/kotlin/taboolib/module/ui/type/impl/{StoredImpl.kt => StorableChestImpl.kt} (97%) rename platform/platform-bukkit-impl/src/main/kotlin/taboolib/platform/type/{BukkitOpenContainer.kt => BukkitContainer.kt} (94%) rename platform/platform-bungee-impl/src/main/kotlin/taboolib/platform/type/{BungeeOpenContainer.kt => BungeeContainer.kt} (94%) rename platform/platform-velocity-impl/src/main/kotlin/taboolib/platform/type/{VelocityOpenContainer.kt => VelocityContainer.kt} (93%) diff --git a/module/module-kether/src/main/kotlin/taboolib/module/kether/KetherLoader.kt b/module/module-kether/src/main/kotlin/taboolib/module/kether/KetherLoader.kt index 3dab01bbb..0b6270d76 100644 --- a/module/module-kether/src/main/kotlin/taboolib/module/kether/KetherLoader.kt +++ b/module/module-kether/src/main/kotlin/taboolib/module/kether/KetherLoader.kt @@ -60,10 +60,12 @@ class KetherLoader : ClassVisitor(0) { /** 注册 Parser */ fun registerParser(parser: ScriptActionParser<*>, name: Array, namespace: String = "kether", shared: Boolean = false) { + // 共享 Parser 到所有 TabooLib 插件 if (shared) { sharedParser += name to namespace getOpenContainers().forEach { it.call(StandardChannel.REMOTE_ADD_ACTION, arrayOf(pluginId, name, namespace)) } } + // 注册到自己 name.forEach { Kether.addAction(it, parser, namespace) } } diff --git a/module/module-ui/src/main/kotlin/taboolib/module/ui/ClickEvent.kt b/module/module-ui/src/main/kotlin/taboolib/module/ui/ClickEvent.kt index 57ef89206..48c01f96d 100755 --- a/module/module-ui/src/main/kotlin/taboolib/module/ui/ClickEvent.kt +++ b/module/module-ui/src/main/kotlin/taboolib/module/ui/ClickEvent.kt @@ -7,7 +7,7 @@ import org.bukkit.event.inventory.InventoryDragEvent import org.bukkit.event.inventory.InventoryInteractEvent import org.bukkit.inventory.Inventory import org.bukkit.inventory.ItemStack -import taboolib.module.ui.type.Basic +import taboolib.module.ui.type.Chest import taboolib.module.ui.virtual.RemoteInventory import taboolib.module.ui.virtual.VirtualInventoryInteractEvent @@ -15,7 +15,7 @@ import taboolib.module.ui.virtual.VirtualInventoryInteractEvent * @author 坏黑 * @since 2019-05-21 18:09 */ -class ClickEvent(private val bukkitEvent: InventoryInteractEvent, val clickType: ClickType, val slot: Char, val builder: Basic) { +class ClickEvent(private val bukkitEvent: InventoryInteractEvent, val clickType: ClickType, val slot: Char, val builder: Chest) { val clicker: Player get() = bukkitEvent.whoClicked as Player diff --git a/module/module-ui/src/main/kotlin/taboolib/module/ui/ClickListener.kt b/module/module-ui/src/main/kotlin/taboolib/module/ui/ClickListener.kt index ee95851cb..705d9cdd6 100644 --- a/module/module-ui/src/main/kotlin/taboolib/module/ui/ClickListener.kt +++ b/module/module-ui/src/main/kotlin/taboolib/module/ui/ClickListener.kt @@ -19,7 +19,7 @@ import taboolib.common.platform.PlatformSide import taboolib.common.platform.event.SubscribeEvent import taboolib.common.platform.function.submit import taboolib.common.platform.function.submitAsync -import taboolib.module.ui.type.impl.BasicImpl +import taboolib.module.ui.type.impl.ChestImpl import taboolib.platform.util.isNotAir import taboolib.platform.util.setMeta @@ -38,7 +38,7 @@ internal object ClickListener { @SubscribeEvent fun onOpen(e: InventoryOpenEvent) { - val builder = MenuHolder.fromInventory(e.inventory) as? BasicImpl ?: return + val builder = MenuHolder.fromInventory(e.inventory) as? ChestImpl ?: return // 构建回调 submit { builder.buildCallback(e.player as Player, e.inventory) @@ -54,7 +54,7 @@ internal object ClickListener { @Suppress("DuplicatedCode") @SubscribeEvent fun onClick(e: InventoryClickEvent) { - val builder = MenuHolder.fromInventory(e.inventory) as? BasicImpl ?: return + val builder = MenuHolder.fromInventory(e.inventory) as? ChestImpl ?: return // 锁定主手 if (builder.handLocked && (e.rawSlot - e.inventory.size - 27 == e.whoClicked.inventory.heldItemSlot || e.click == org.bukkit.event.inventory.ClickType.NUMBER_KEY && e.hotbarButton == e.whoClicked.inventory.heldItemSlot)) { e.isCancelled = true @@ -101,7 +101,7 @@ internal object ClickListener { @SubscribeEvent fun onDrag(e: InventoryDragEvent) { - val menu = MenuHolder.fromInventory(e.inventory) as? BasicImpl ?: return + val menu = MenuHolder.fromInventory(e.inventory) as? ChestImpl ?: return val clickEvent = ClickEvent(e, ClickType.DRAG, ' ', menu) menu.clickCallback.forEach { it.invoke(clickEvent) } menu.selfClickCallback(clickEvent) @@ -109,7 +109,7 @@ internal object ClickListener { @SubscribeEvent fun onClose(e: InventoryCloseEvent) { - val menu = MenuHolder.fromInventory(e.inventory) as? BasicImpl ?: return + val menu = MenuHolder.fromInventory(e.inventory) as? ChestImpl ?: return // 标题更新 && 跳过关闭回调 if (menu.isUpdateTitle && menu.isSkipCloseCallbackOnUpdateTitle) { return diff --git a/module/module-ui/src/main/kotlin/taboolib/module/ui/Menu.kt b/module/module-ui/src/main/kotlin/taboolib/module/ui/Menu.kt index 51d556e6e..de690c9c1 100644 --- a/module/module-ui/src/main/kotlin/taboolib/module/ui/Menu.kt +++ b/module/module-ui/src/main/kotlin/taboolib/module/ui/Menu.kt @@ -19,10 +19,10 @@ interface Menu { init { impl[Anvil::class.java] = AnvilImpl::class.java - impl[Basic::class.java] = BasicImpl::class.java + impl[Chest::class.java] = ChestImpl::class.java impl[Hopper::class.java] = HopperImpl::class.java - impl[Linked::class.java] = LinkedImpl::class.java - impl[Stored::class.java] = StoredImpl::class.java + impl[PageableChest::class.java] = PageableChestImpl::class.java + impl[StorableChest::class.java] = StorableChestImpl::class.java } /** 注册实现 */ 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 11fc1bfbc..fcf37f0ea 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 @@ -5,15 +5,22 @@ import org.bukkit.event.inventory.ClickType import org.bukkit.event.inventory.InventoryClickEvent import org.bukkit.inventory.Inventory import org.bukkit.inventory.ItemStack +import taboolib.common.OpenListener +import taboolib.common.OpenResult import taboolib.common.event.InternalEventBus +import taboolib.common.platform.Awake +import taboolib.common.platform.function.getOpenContainers import taboolib.module.nms.PacketSendEvent -import taboolib.module.ui.type.impl.BasicImpl +import taboolib.module.ui.type.impl.ChestImpl import taboolib.module.ui.virtual.InventoryHandler import taboolib.module.ui.virtual.VirtualInventory import taboolib.module.ui.virtual.inject import taboolib.module.ui.virtual.openVirtualInventory import taboolib.platform.util.isNotAir +/** + * 允许在 Vanilla Inventory 中使用 Raw Title + */ var isRawTitleInVanillaInventoryEnabled = false private set @@ -27,7 +34,12 @@ var isRawTitleInVanillaInventoryEnabled = false * 虚拟菜单不需要开启该选项 */ fun enableRawTitleInVanillaInventory() { + // 防止重复注册 + if (isRawTitleInVanillaInventoryEnabled) { + return + } isRawTitleInVanillaInventoryEnabled = true + // 监听数据包 InternalEventBus.listen { e -> if (e.packet.name == "PacketPlayOutOpenWindow") { // 全版本都是 c,不错 @@ -37,6 +49,20 @@ fun enableRawTitleInVanillaInventory() { } } } + // 告知所有 TabooLib 插件,该监听器已被注册 + getOpenContainers().forEach { it.call("LISTEN_RAW_TITLE_IN_VANILLA_INVENTORY", emptyArray()) } +} + +@Awake +class RawTitleOpenListener : OpenListener { + + override fun call(name: String, data: Array?): OpenResult { + if (name == "LISTEN_RAW_TITLE_IN_VANILLA_INVENTORY") { + isRawTitleInVanillaInventoryEnabled = true + return OpenResult.successful() + } + return OpenResult.failed() + } } /** @@ -67,7 +93,7 @@ fun HumanEntity.openMenu(buildMenu: Inventory, changeId: Boolean = true) { if (buildMenu is VirtualInventory) { val remoteInventory = openVirtualInventory(buildMenu, changeId) val basic = MenuHolder.fromInventory(buildMenu) - if (basic is BasicImpl) { + if (basic is ChestImpl) { remoteInventory.inject(basic) } } else { diff --git a/module/module-ui/src/main/kotlin/taboolib/module/ui/MenuHolder.kt b/module/module-ui/src/main/kotlin/taboolib/module/ui/MenuHolder.kt index ad3f7e392..f8d5a4937 100755 --- a/module/module-ui/src/main/kotlin/taboolib/module/ui/MenuHolder.kt +++ b/module/module-ui/src/main/kotlin/taboolib/module/ui/MenuHolder.kt @@ -3,14 +3,14 @@ package taboolib.module.ui import org.bukkit.Bukkit import org.bukkit.inventory.Inventory import org.bukkit.inventory.InventoryHolder -import taboolib.module.ui.type.Basic +import taboolib.module.ui.type.Chest /** * @author 坏黑 * @since 2019-05-21 20:28 */ @Suppress("LeakingThis") -open class MenuHolder(val menu: Basic) : InventoryHolder { +open class MenuHolder(val menu: Chest) : InventoryHolder { private val inventory = Bukkit.createInventory(this, if (menu.rows > 0) menu.rows * 9 else menu.slots.size * 9, menu.title) @@ -20,7 +20,7 @@ open class MenuHolder(val menu: Basic) : InventoryHolder { companion object { - fun fromInventory(inventory: Inventory): Basic? { + fun fromInventory(inventory: Inventory): Chest? { return (inventory.holder as? MenuHolder)?.menu } } diff --git a/module/module-ui/src/main/kotlin/taboolib/module/ui/type/Anvil.kt b/module/module-ui/src/main/kotlin/taboolib/module/ui/type/Anvil.kt index b9c7d2908..d865e686d 100644 --- a/module/module-ui/src/main/kotlin/taboolib/module/ui/type/Anvil.kt +++ b/module/module-ui/src/main/kotlin/taboolib/module/ui/type/Anvil.kt @@ -6,7 +6,7 @@ import org.bukkit.inventory.Inventory /** * 铁砧容器 */ -interface Anvil : Basic { +interface Anvil : Chest { /** 当物品被重命名时 */ fun onRename(callback: (Player, String, Inventory) -> Unit) 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 454fca6d3..11b1fd1c9 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 @@ -1,167 +1,9 @@ package taboolib.module.ui.type -import org.bukkit.entity.Player -import org.bukkit.event.inventory.InventoryCloseEvent -import org.bukkit.inventory.Inventory -import org.bukkit.inventory.ItemStack -import taboolib.library.xseries.XMaterial -import taboolib.module.ui.ClickEvent -import taboolib.module.ui.Menu -import taboolib.module.ui.MenuHolder -import taboolib.platform.util.ItemBuilder -import java.util.concurrent.ConcurrentHashMap -import java.util.concurrent.CopyOnWriteArrayList +import taboolib.module.ui.type.impl.ChestImpl /** - * 标准容器 + * 向下兼容 */ -interface Basic : Menu { - - /** 获取行数 */ - val rows: Int - - /** 是否正在使用虚拟化 */ - val virtualized: Boolean - - /** 虚拟化时玩家背包内容 */ - val virtualizedStorageContents: List? - - /** 物品与对应抽象字符关系 **/ - val items: ConcurrentHashMap - - /** 抽象字符布局 **/ - val slots: CopyOnWriteArrayList> - - /** 是否锁定主手 **/ - val handLocked: Boolean - - /** 是否打开过 **/ - val isOpened: Boolean - - /** - * 启用虚拟化页面(将自动阻止所有点击行为) - */ - fun virtualize(storageContents: List? = null) - - /** - * 隐藏玩家背包(自动启动虚拟页面) - */ - fun hidePlayerInventory() - - /** - * 行数 - * 为 1 - 6 之间的整数,并非原版 9 的倍数 - */ - fun rows(rows: Int) - - /** - * 设置是否锁定玩家手部动作 - * 设置为 true 则将阻止玩家在使用菜单时进行包括但不限于 - * 丢弃物品,拿出菜单物品等行为 - * - * @param handLocked 锁定 - */ - fun handLocked(handLocked: Boolean) - - /** - * 设置 MenuHolder 创建回调 - */ - fun holder(func: (menu: Basic) -> MenuHolder) - - /** - * 页面构建时触发回调 - * 可选是否异步执行 - */ - fun onBuild(async: Boolean = false, callback: (player: Player, inventory: Inventory) -> Unit) - - /** - * 页面关闭时触发回调 - * 只能触发一次(玩家客户端强制关闭时会触发两次原版 InventoryCloseEvent 事件) - * - * TODO 2023/10/09 若启用虚拟化菜单,则 player.closeInventory() 不会触发该回调函数 - */ - fun onClose(once: Boolean = true, skipUpdateTitle: Boolean = true, callback: (event: InventoryCloseEvent) -> Unit) - - /** - * 点击事件回调 - * 仅在特定位置下触发 - */ - fun onClick(bind: Int, callback: (event: ClickEvent) -> Unit = {}) - - /** - * 点击事件回调 - * 仅在特定位置下触发 - */ - fun onClick(bind: Char, callback: (event: ClickEvent) -> Unit = {}) - - /** - * 整页点击事件回调 - * 可选是否自动锁定点击位置 - */ - fun onClick(lock: Boolean = false, callback: (event: ClickEvent) -> Unit = {}) - - /** - * 使用抽象字符页面布局 - */ - fun map(vararg slots: String) - - /** - * 根据抽象符号设置物品 - */ - fun set(slot: Char, itemStack: ItemStack) - - /** - * 根据位置设置物品 - */ - fun set(slot: Int, itemStack: ItemStack) - - /** - * 根据抽象符号设置物品 - */ - fun set(slot: Char, callback: () -> ItemStack) - - /** - * 根据位置设置物品 - */ - fun set(slot: Int, callback: () -> ItemStack) - - /** - * 根据抽象符号设置物品 - */ - fun set(slot: Char, material: XMaterial, itemBuilder: ItemBuilder.() -> Unit = {}) - - /** - * 根据位置设置物品 - */ - fun set(slot: Int, material: XMaterial, itemBuilder: ItemBuilder.() -> Unit = {}) - - /** - * 根据抽象符号设置物品 - */ - fun set(slot: Char, itemStack: ItemStack, onClick: ClickEvent.() -> Unit = {}) - - /** - * 根据位置设置物品 - */ - fun set(slot: Int, itemStack: ItemStack, onClick: ClickEvent.() -> Unit = {}) - - /** - * 获取位置对应的抽象字符 - */ - fun getSlot(slot: Int): Char - - /** - * 获取抽象字符对应的位置 - */ - fun getSlots(slot: Char): List - - /** - * 获取抽象字符对应的首个位置 - */ - fun getFirstSlot(slot: Char): Int - - /** - * 更新标题 - */ - fun updateTitle(title: String) -} \ No newline at end of file +@Deprecated("Use Chest instead.", ReplaceWith("Chest")) +open class Basic(override var title: String) : ChestImpl(title) \ No newline at end of file diff --git a/module/module-ui/src/main/kotlin/taboolib/module/ui/type/Chest.kt b/module/module-ui/src/main/kotlin/taboolib/module/ui/type/Chest.kt new file mode 100644 index 000000000..913cb4bc3 --- /dev/null +++ b/module/module-ui/src/main/kotlin/taboolib/module/ui/type/Chest.kt @@ -0,0 +1,167 @@ +package taboolib.module.ui.type + +import org.bukkit.entity.Player +import org.bukkit.event.inventory.InventoryCloseEvent +import org.bukkit.inventory.Inventory +import org.bukkit.inventory.ItemStack +import taboolib.library.xseries.XMaterial +import taboolib.module.ui.ClickEvent +import taboolib.module.ui.Menu +import taboolib.module.ui.MenuHolder +import taboolib.platform.util.ItemBuilder +import java.util.concurrent.ConcurrentHashMap +import java.util.concurrent.CopyOnWriteArrayList + +/** + * 标准容器 + */ +interface Chest : Menu { + + /** 获取行数 */ + val rows: Int + + /** 是否正在使用虚拟化 */ + val virtualized: Boolean + + /** 虚拟化时玩家背包内容 */ + val virtualizedStorageContents: List? + + /** 物品与对应抽象字符关系 **/ + val items: ConcurrentHashMap + + /** 抽象字符布局 **/ + val slots: CopyOnWriteArrayList> + + /** 是否锁定主手 **/ + val handLocked: Boolean + + /** 是否打开过 **/ + val isOpened: Boolean + + /** + * 启用虚拟化页面(将自动阻止所有点击行为) + */ + fun virtualize(storageContents: List? = null) + + /** + * 隐藏玩家背包(自动启动虚拟页面) + */ + fun hidePlayerInventory() + + /** + * 行数 + * 为 1 - 6 之间的整数,并非原版 9 的倍数 + */ + fun rows(rows: Int) + + /** + * 设置是否锁定玩家手部动作 + * 设置为 true 则将阻止玩家在使用菜单时进行包括但不限于 + * 丢弃物品,拿出菜单物品等行为 + * + * @param handLocked 锁定 + */ + fun handLocked(handLocked: Boolean) + + /** + * 设置 MenuHolder 创建回调 + */ + fun holder(func: (menu: Chest) -> MenuHolder) + + /** + * 页面构建时触发回调 + * 可选是否异步执行 + */ + fun onBuild(async: Boolean = false, callback: (player: Player, inventory: Inventory) -> Unit) + + /** + * 页面关闭时触发回调 + * 只能触发一次(玩家客户端强制关闭时会触发两次原版 InventoryCloseEvent 事件) + * + * TODO 2023/10/09 若启用虚拟化菜单,则 player.closeInventory() 不会触发该回调函数 + */ + fun onClose(once: Boolean = true, skipUpdateTitle: Boolean = true, callback: (event: InventoryCloseEvent) -> Unit) + + /** + * 点击事件回调 + * 仅在特定位置下触发 + */ + fun onClick(bind: Int, callback: (event: ClickEvent) -> Unit = {}) + + /** + * 点击事件回调 + * 仅在特定位置下触发 + */ + fun onClick(bind: Char, callback: (event: ClickEvent) -> Unit = {}) + + /** + * 整页点击事件回调 + * 可选是否自动锁定点击位置 + */ + fun onClick(lock: Boolean = false, callback: (event: ClickEvent) -> Unit = {}) + + /** + * 使用抽象字符页面布局 + */ + fun map(vararg slots: String) + + /** + * 根据抽象符号设置物品 + */ + fun set(slot: Char, itemStack: ItemStack) + + /** + * 根据位置设置物品 + */ + fun set(slot: Int, itemStack: ItemStack) + + /** + * 根据抽象符号设置物品 + */ + fun set(slot: Char, callback: () -> ItemStack) + + /** + * 根据位置设置物品 + */ + fun set(slot: Int, callback: () -> ItemStack) + + /** + * 根据抽象符号设置物品 + */ + fun set(slot: Char, material: XMaterial, itemBuilder: ItemBuilder.() -> Unit = {}) + + /** + * 根据位置设置物品 + */ + fun set(slot: Int, material: XMaterial, itemBuilder: ItemBuilder.() -> Unit = {}) + + /** + * 根据抽象符号设置物品 + */ + fun set(slot: Char, itemStack: ItemStack, onClick: ClickEvent.() -> Unit = {}) + + /** + * 根据位置设置物品 + */ + fun set(slot: Int, itemStack: ItemStack, onClick: ClickEvent.() -> Unit = {}) + + /** + * 获取位置对应的抽象字符 + */ + fun getSlot(slot: Int): Char + + /** + * 获取抽象字符对应的位置 + */ + fun getSlots(slot: Char): List + + /** + * 获取抽象字符对应的首个位置 + */ + fun getFirstSlot(slot: Char): Int + + /** + * 更新标题 + */ + fun updateTitle(title: String) +} \ No newline at end of file diff --git a/module/module-ui/src/main/kotlin/taboolib/module/ui/type/Hopper.kt b/module/module-ui/src/main/kotlin/taboolib/module/ui/type/Hopper.kt index ddfcde548..03291f606 100644 --- a/module/module-ui/src/main/kotlin/taboolib/module/ui/type/Hopper.kt +++ b/module/module-ui/src/main/kotlin/taboolib/module/ui/type/Hopper.kt @@ -3,4 +3,4 @@ package taboolib.module.ui.type /** * 漏斗容器 */ -interface Hopper : Basic \ No newline at end of file +interface Hopper : Chest \ No newline at end of file diff --git a/module/module-ui/src/main/kotlin/taboolib/module/ui/type/Linked.kt b/module/module-ui/src/main/kotlin/taboolib/module/ui/type/Linked.kt index 013ef38a5..cd71d0d20 100644 --- a/module/module-ui/src/main/kotlin/taboolib/module/ui/type/Linked.kt +++ b/module/module-ui/src/main/kotlin/taboolib/module/ui/type/Linked.kt @@ -1,86 +1,9 @@ package taboolib.module.ui.type -import org.bukkit.entity.Player -import org.bukkit.inventory.Inventory -import org.bukkit.inventory.ItemStack -import taboolib.module.ui.ClickEvent +import taboolib.module.ui.type.impl.PageableChestImpl /** - * 可翻页容器 + * 向下兼容 */ -interface Linked : Basic { - - /** 页数 **/ - val page: Int - - /** - * 是否锁定所有位置 - * 默认为 true - */ - fun menuLocked(lockAll: Boolean) - - /** - * 设置页数 - */ - fun page(page: Int) - - /** - * 设置可用位置 - */ - fun slots(slots: List) - - /** - * 通过抽象字符选择由 map 函数铺设的页面位置 - */ - fun slotsBy(char: Char) - - /** - * 可用元素列表回调 - */ - fun elements(elements: () -> List) - - /** - * 元素对应物品生成回调 - */ - fun onGenerate(async: Boolean = false, callback: (player: Player, element: T, index: Int, slot: Int) -> ItemStack) - - /** - * 页面构建回调 - */ - fun onBuild(async: Boolean, callback: (inventory: Inventory) -> Unit) - - /** - * 元素点击回调 - */ - fun onClick(callback: (event: ClickEvent, element: T) -> Unit) - - /** - * 设置下一页按钮 - */ - fun setNextPage(slot: Int, callback: (page: Int, hasNextPage: Boolean) -> ItemStack) - - /** - * 设置上一页按钮 - */ - fun setPreviousPage(slot: Int, callback: (page: Int, hasPreviousPage: Boolean) -> ItemStack) - - /** - * 切换页面回调 - */ - fun onPageChange(callback: (player: Player) -> Unit) - - /** - * 是否可以返回上一页 - */ - fun hasPreviousPage(): Boolean - - /** - * 是否可以前往下一页 - */ - fun hasNextPage(): Boolean - - /** - * 重制元素列表缓存 - */ - fun resetElementsCache() -} \ No newline at end of file +@Deprecated("Use PageableChest instead.", ReplaceWith("PageableChest")) +open class Linked(override var title: String) : PageableChestImpl(title) \ No newline at end of file diff --git a/module/module-ui/src/main/kotlin/taboolib/module/ui/type/PageableChest.kt b/module/module-ui/src/main/kotlin/taboolib/module/ui/type/PageableChest.kt new file mode 100644 index 000000000..902849272 --- /dev/null +++ b/module/module-ui/src/main/kotlin/taboolib/module/ui/type/PageableChest.kt @@ -0,0 +1,86 @@ +package taboolib.module.ui.type + +import org.bukkit.entity.Player +import org.bukkit.inventory.Inventory +import org.bukkit.inventory.ItemStack +import taboolib.module.ui.ClickEvent + +/** + * 可翻页容器 + */ +interface PageableChest : Chest { + + /** 页数 **/ + val page: Int + + /** + * 是否锁定所有位置 + * 默认为 true + */ + fun menuLocked(lockAll: Boolean) + + /** + * 设置页数 + */ + fun page(page: Int) + + /** + * 设置可用位置 + */ + fun slots(slots: List) + + /** + * 通过抽象字符选择由 map 函数铺设的页面位置 + */ + fun slotsBy(char: Char) + + /** + * 可用元素列表回调 + */ + fun elements(elements: () -> List) + + /** + * 元素对应物品生成回调 + */ + fun onGenerate(async: Boolean = false, callback: (player: Player, element: T, index: Int, slot: Int) -> ItemStack) + + /** + * 页面构建回调 + */ + fun onBuild(async: Boolean, callback: (inventory: Inventory) -> Unit) + + /** + * 元素点击回调 + */ + fun onClick(callback: (event: ClickEvent, element: T) -> Unit) + + /** + * 设置下一页按钮 + */ + fun setNextPage(slot: Int, callback: (page: Int, hasNextPage: Boolean) -> ItemStack) + + /** + * 设置上一页按钮 + */ + fun setPreviousPage(slot: Int, callback: (page: Int, hasPreviousPage: Boolean) -> ItemStack) + + /** + * 切换页面回调 + */ + fun onPageChange(callback: (player: Player) -> Unit) + + /** + * 是否可以返回上一页 + */ + fun hasPreviousPage(): Boolean + + /** + * 是否可以前往下一页 + */ + fun hasNextPage(): Boolean + + /** + * 重制元素列表缓存 + */ + fun resetElementsCache() +} \ No newline at end of file diff --git a/module/module-ui/src/main/kotlin/taboolib/module/ui/type/StorableChest.kt b/module/module-ui/src/main/kotlin/taboolib/module/ui/type/StorableChest.kt new file mode 100644 index 000000000..9df7c0593 --- /dev/null +++ b/module/module-ui/src/main/kotlin/taboolib/module/ui/type/StorableChest.kt @@ -0,0 +1,62 @@ +package taboolib.module.ui.type + +import org.bukkit.inventory.Inventory +import org.bukkit.inventory.ItemStack + +/** + * 可储存容器 + */ +interface StorableChest : Chest { + + /** + * 定义页面规则 + */ + fun rule(rule: Rule.() -> Unit) + + /** + * 页面规则 + */ + interface Rule { + + /** + * 定义判定位置 + * 玩家是否可以将物品放入 + */ + fun checkSlot(intRange: Int, checkSlot: (inventory: Inventory, itemStack: ItemStack) -> Boolean) + + /** + * 定义判定位置 + * 玩家是否可以将物品放入 + */ + fun checkSlot(intRange: IntRange, callback: (inventory: Inventory, itemStack: ItemStack) -> Boolean) + + /** + * 定义判定位置 + * 玩家是否可以将物品放入 + */ + fun checkSlot(callback: (inventory: Inventory, itemStack: ItemStack, slot: Int) -> Boolean) + + /** + * 获取页面中首个有效的位置 + * 用于玩家 SHIFT 点击快速放入物品,不再触发 checkSlot 回调 + */ + fun firstSlot(firstSlot: (inventory: Inventory, itemStack: ItemStack) -> Int) + + /** + * 物品写入回调 + */ + fun writeItem(writeItem: (inventory: Inventory, itemStack: ItemStack, slot: Int) -> Unit) + + /** + * 物品写入回调 + */ + fun writeItem(writeItem: (inventory: Inventory, itemStack: ItemStack, slot: Int, type: BukkitClickType) -> Unit) + + /** + * 读取物品回调 + */ + fun readItem(readItem: (inventory: Inventory, slot: Int) -> ItemStack?) + } +} + +typealias BukkitClickType = org.bukkit.event.inventory.ClickType \ No newline at end of file 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 39e61bd4c..b378ee2ad 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 @@ -1,62 +1,9 @@ package taboolib.module.ui.type -import org.bukkit.inventory.Inventory -import org.bukkit.inventory.ItemStack +import taboolib.module.ui.type.impl.StorableChestImpl /** - * 可储存容器 + * 向下兼容 */ -interface Stored : Basic { - - /** - * 定义页面规则 - */ - fun rule(rule: Rule.() -> Unit) - - /** - * 页面规则 - */ - interface Rule { - - /** - * 定义判定位置 - * 玩家是否可以将物品放入 - */ - fun checkSlot(intRange: Int, checkSlot: (inventory: Inventory, itemStack: ItemStack) -> Boolean) - - /** - * 定义判定位置 - * 玩家是否可以将物品放入 - */ - fun checkSlot(intRange: IntRange, callback: (inventory: Inventory, itemStack: ItemStack) -> Boolean) - - /** - * 定义判定位置 - * 玩家是否可以将物品放入 - */ - fun checkSlot(callback: (inventory: Inventory, itemStack: ItemStack, slot: Int) -> Boolean) - - /** - * 获取页面中首个有效的位置 - * 用于玩家 SHIFT 点击快速放入物品,不再触发 checkSlot 回调 - */ - fun firstSlot(firstSlot: (inventory: Inventory, itemStack: ItemStack) -> Int) - - /** - * 物品写入回调 - */ - fun writeItem(writeItem: (inventory: Inventory, itemStack: ItemStack, slot: Int) -> Unit) - - /** - * 物品写入回调 - */ - fun writeItem(writeItem: (inventory: Inventory, itemStack: ItemStack, slot: Int, type: BukkitClickType) -> Unit) - - /** - * 读取物品回调 - */ - fun readItem(readItem: (inventory: Inventory, slot: Int) -> ItemStack?) - } -} - -typealias BukkitClickType = org.bukkit.event.inventory.ClickType \ No newline at end of file +@Deprecated("Use StorableChest instead.", ReplaceWith("StorableChest")) +open class Stored(override var title: String) : StorableChestImpl(title) \ No newline at end of file diff --git a/module/module-ui/src/main/kotlin/taboolib/module/ui/type/impl/AnvilImpl.kt b/module/module-ui/src/main/kotlin/taboolib/module/ui/type/impl/AnvilImpl.kt index 5dfcc9b0a..f670436ed 100644 --- a/module/module-ui/src/main/kotlin/taboolib/module/ui/type/impl/AnvilImpl.kt +++ b/module/module-ui/src/main/kotlin/taboolib/module/ui/type/impl/AnvilImpl.kt @@ -17,7 +17,7 @@ import taboolib.module.ui.virtual.virtualize * @author arasple * @since 2023/11/18 16:50 */ -open class AnvilImpl(title: String) : BasicImpl(title), Anvil, AnvilCallback { +open class AnvilImpl(title: String) : ChestImpl(title), Anvil, AnvilCallback { internal var renameCallback: ((Player, String, Inventory) -> Unit)? = null diff --git a/module/module-ui/src/main/kotlin/taboolib/module/ui/type/impl/BasicImpl.kt b/module/module-ui/src/main/kotlin/taboolib/module/ui/type/impl/ChestImpl.kt similarity index 97% rename from module/module-ui/src/main/kotlin/taboolib/module/ui/type/impl/BasicImpl.kt rename to module/module-ui/src/main/kotlin/taboolib/module/ui/type/impl/ChestImpl.kt index b7a4e4588..7c5b160dd 100644 --- a/module/module-ui/src/main/kotlin/taboolib/module/ui/type/impl/BasicImpl.kt +++ b/module/module-ui/src/main/kotlin/taboolib/module/ui/type/impl/ChestImpl.kt @@ -11,14 +11,14 @@ import taboolib.module.ui.ClickEvent import taboolib.module.ui.ClickType import taboolib.module.ui.MenuHolder import taboolib.module.ui.openMenu -import taboolib.module.ui.type.Basic +import taboolib.module.ui.type.Chest import taboolib.module.ui.virtual.virtualize import taboolib.platform.util.ItemBuilder import taboolib.platform.util.buildItem import java.util.concurrent.ConcurrentHashMap import java.util.concurrent.CopyOnWriteArrayList -open class BasicImpl(override var title: String = "chest") : Basic { +open class ChestImpl(override var title: String) : Chest { /** 最后一次构建的页面 */ lateinit var lastInventory: Inventory @@ -45,7 +45,7 @@ open class BasicImpl(override var title: String = "chest") : Basic { override var isOpened = false /** MenuHolder 回调 **/ - var holderCallback: ((menu: BasicImpl) -> MenuHolder) = { MenuHolder(it) } + var holderCallback: ((menu: ChestImpl) -> MenuHolder) = { MenuHolder(it) } /** 点击回调 **/ val clickCallback = CopyOnWriteArrayList<(event: ClickEvent) -> Unit>() @@ -114,7 +114,7 @@ open class BasicImpl(override var title: String = "chest") : Basic { /** * 设置 MenuHolder 创建回调 */ - override fun holder(func: (menu: Basic) -> MenuHolder) { + override fun holder(func: (menu: Chest) -> MenuHolder) { this.holderCallback = func } diff --git a/module/module-ui/src/main/kotlin/taboolib/module/ui/type/impl/HopperImpl.kt b/module/module-ui/src/main/kotlin/taboolib/module/ui/type/impl/HopperImpl.kt index b2e1c5662..95865317b 100644 --- a/module/module-ui/src/main/kotlin/taboolib/module/ui/type/impl/HopperImpl.kt +++ b/module/module-ui/src/main/kotlin/taboolib/module/ui/type/impl/HopperImpl.kt @@ -7,7 +7,7 @@ import org.bukkit.inventory.Inventory import org.bukkit.inventory.ItemStack import taboolib.module.ui.virtual.virtualize -open class HopperImpl(title: String = "chest") : BasicImpl(title) { +open class HopperImpl(title: String) : ChestImpl(title) { override fun build(): Inventory { var inventory = Bukkit.createInventory(holderCallback(this), InventoryType.HOPPER, title) diff --git a/module/module-ui/src/main/kotlin/taboolib/module/ui/type/impl/LinkedImpl.kt b/module/module-ui/src/main/kotlin/taboolib/module/ui/type/impl/PageableChestImpl.kt similarity index 98% rename from module/module-ui/src/main/kotlin/taboolib/module/ui/type/impl/LinkedImpl.kt rename to module/module-ui/src/main/kotlin/taboolib/module/ui/type/impl/PageableChestImpl.kt index 44e114beb..1e7b2918d 100644 --- a/module/module-ui/src/main/kotlin/taboolib/module/ui/type/impl/LinkedImpl.kt +++ b/module/module-ui/src/main/kotlin/taboolib/module/ui/type/impl/PageableChestImpl.kt @@ -6,14 +6,14 @@ import org.bukkit.inventory.Inventory import org.bukkit.inventory.ItemStack import taboolib.common.util.subList import taboolib.module.ui.ClickEvent -import taboolib.module.ui.type.Linked +import taboolib.module.ui.type.PageableChest import taboolib.module.ui.virtual.VirtualInventory import taboolib.module.ui.virtual.inject import taboolib.module.ui.virtual.openVirtualInventory import taboolib.platform.util.isNotAir import java.util.concurrent.CopyOnWriteArrayList -open class LinkedImpl(title: String) : BasicImpl(title), Linked { +open class PageableChestImpl(title: String) : ChestImpl(title), PageableChest { /** 页数 **/ override var page = 0 diff --git a/module/module-ui/src/main/kotlin/taboolib/module/ui/type/impl/StoredImpl.kt b/module/module-ui/src/main/kotlin/taboolib/module/ui/type/impl/StorableChestImpl.kt similarity index 97% rename from module/module-ui/src/main/kotlin/taboolib/module/ui/type/impl/StoredImpl.kt rename to module/module-ui/src/main/kotlin/taboolib/module/ui/type/impl/StorableChestImpl.kt index 17bba4546..1f28dd4c9 100644 --- a/module/module-ui/src/main/kotlin/taboolib/module/ui/type/impl/StoredImpl.kt +++ b/module/module-ui/src/main/kotlin/taboolib/module/ui/type/impl/StorableChestImpl.kt @@ -10,7 +10,7 @@ import taboolib.module.ui.type.* import taboolib.platform.util.isAir import taboolib.platform.util.isNotAir -open class StoredImpl(title: String) : BasicImpl(title), Stored { +open class StorableChestImpl(title: String) : ChestImpl(title), StorableChest { /** 页面规则 **/ val rule = RuleImpl @@ -18,7 +18,7 @@ open class StoredImpl(title: String) : BasicImpl(title), Stored { /** * 定义页面规则 */ - override fun rule(rule: Stored.Rule.() -> Unit) { + override fun rule(rule: StorableChest.Rule.() -> Unit) { if (virtualized) error("cannot change rule when virtualized") rule(this.rule) } @@ -126,7 +126,7 @@ open class StoredImpl(title: String) : BasicImpl(title), Stored { return super.build() } - object RuleImpl : Stored.Rule { + object RuleImpl : StorableChest.Rule { /** 检查判定位置回调 **/ var checkSlot: ((inventory: Inventory, itemStack: ItemStack, slot: Int) -> Boolean) = { _, _, _ -> true } 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 d7afc1e96..0654a5268 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 @@ -13,7 +13,9 @@ import taboolib.common.platform.function.isPrimaryThread import taboolib.common.platform.function.submit import taboolib.module.ui.ClickEvent import taboolib.module.ui.ClickType -import taboolib.module.ui.type.impl.BasicImpl +import taboolib.module.ui.type.Basic +import taboolib.module.ui.type.Chest +import taboolib.module.ui.type.impl.ChestImpl /** * 将背包转换为 VirtualInventory 实例 @@ -38,10 +40,14 @@ fun HumanEntity.openVirtualInventory(inventory: VirtualInventory, updateId: Bool return remoteInventory } +fun RemoteInventory.inject(menu: Basic) = inject(menu as ChestImpl) + +fun RemoteInventory.inject(menu: Chest) = inject(menu as ChestImpl) + /** * 注入事件到 Basic 页面 */ -fun RemoteInventory.inject(menu: BasicImpl) { +fun RemoteInventory.inject(menu: T) { onClick { // 处理事件 try { diff --git a/platform/platform-bukkit-impl/src/main/kotlin/taboolib/platform/BukkitOpenContainer.kt b/platform/platform-bukkit-impl/src/main/kotlin/taboolib/platform/BukkitOpenContainer.kt index 2d2691db6..7ffcea48f 100644 --- a/platform/platform-bukkit-impl/src/main/kotlin/taboolib/platform/BukkitOpenContainer.kt +++ b/platform/platform-bukkit-impl/src/main/kotlin/taboolib/platform/BukkitOpenContainer.kt @@ -5,8 +5,9 @@ import taboolib.common.OpenContainer import taboolib.common.platform.Awake import taboolib.common.platform.Platform import taboolib.common.platform.PlatformSide +import taboolib.common.platform.function.pluginId import taboolib.common.platform.service.PlatformOpenContainer -import taboolib.platform.type.BukkitOpenContainer +import taboolib.platform.type.BukkitContainer /** * TabooLib @@ -22,8 +23,8 @@ class BukkitOpenContainer : PlatformOpenContainer { val pluginContainer = HashMap() override fun getOpenContainers(): List { - return Bukkit.getPluginManager().plugins.filter { it.javaClass.name.endsWith("platform.BukkitPlugin") }.mapNotNull { - pluginContainer.computeIfAbsent(it.name) { _ -> BukkitOpenContainer(it) } + return Bukkit.getPluginManager().plugins.filter { it.javaClass.name.endsWith("platform.BukkitPlugin") && it.name != pluginId }.mapNotNull { + pluginContainer.computeIfAbsent(it.name) { _ -> BukkitContainer(it) } } } } \ No newline at end of file diff --git a/platform/platform-bukkit-impl/src/main/kotlin/taboolib/platform/type/BukkitOpenContainer.kt b/platform/platform-bukkit-impl/src/main/kotlin/taboolib/platform/type/BukkitContainer.kt similarity index 94% rename from platform/platform-bukkit-impl/src/main/kotlin/taboolib/platform/type/BukkitOpenContainer.kt rename to platform/platform-bukkit-impl/src/main/kotlin/taboolib/platform/type/BukkitContainer.kt index 5f84ff144..f823ac7dd 100644 --- a/platform/platform-bukkit-impl/src/main/kotlin/taboolib/platform/type/BukkitOpenContainer.kt +++ b/platform/platform-bukkit-impl/src/main/kotlin/taboolib/platform/type/BukkitContainer.kt @@ -12,7 +12,7 @@ import taboolib.common.OpenResult * @author sky * @since 2021/7/3 1:44 上午 */ -class BukkitOpenContainer(plugin: Plugin) : OpenContainer { +class BukkitContainer(plugin: Plugin) : OpenContainer { private val name = plugin.name private val main = plugin.description.main diff --git a/platform/platform-bungee-impl/src/main/kotlin/taboolib/platform/BungeeOpenContainer.kt b/platform/platform-bungee-impl/src/main/kotlin/taboolib/platform/BungeeOpenContainer.kt index 397309962..aacbc4252 100644 --- a/platform/platform-bungee-impl/src/main/kotlin/taboolib/platform/BungeeOpenContainer.kt +++ b/platform/platform-bungee-impl/src/main/kotlin/taboolib/platform/BungeeOpenContainer.kt @@ -5,8 +5,9 @@ import taboolib.common.OpenContainer import taboolib.common.platform.Awake import taboolib.common.platform.Platform import taboolib.common.platform.PlatformSide +import taboolib.common.platform.function.pluginId import taboolib.common.platform.service.PlatformOpenContainer -import taboolib.platform.type.BungeeOpenContainer +import taboolib.platform.type.BungeeContainer /** * TabooLib @@ -22,8 +23,8 @@ class BungeeOpenContainer : PlatformOpenContainer { val pluginContainer = HashMap() override fun getOpenContainers(): List { - return BungeeCord.getInstance().pluginManager.plugins.filter { it.javaClass.name.endsWith("platform.BungeePlugin") }.mapNotNull { - pluginContainer.computeIfAbsent(it.description.name) { _ -> BungeeOpenContainer(it) } + return BungeeCord.getInstance().pluginManager.plugins.filter { it.javaClass.name.endsWith("platform.BungeePlugin") && it.description.name != pluginId }.mapNotNull { + pluginContainer.computeIfAbsent(it.description.name) { _ -> BungeeContainer(it) } } } } \ No newline at end of file diff --git a/platform/platform-bungee-impl/src/main/kotlin/taboolib/platform/type/BungeeOpenContainer.kt b/platform/platform-bungee-impl/src/main/kotlin/taboolib/platform/type/BungeeContainer.kt similarity index 94% rename from platform/platform-bungee-impl/src/main/kotlin/taboolib/platform/type/BungeeOpenContainer.kt rename to platform/platform-bungee-impl/src/main/kotlin/taboolib/platform/type/BungeeContainer.kt index 44bcea4cf..e290247df 100644 --- a/platform/platform-bungee-impl/src/main/kotlin/taboolib/platform/type/BungeeOpenContainer.kt +++ b/platform/platform-bungee-impl/src/main/kotlin/taboolib/platform/type/BungeeContainer.kt @@ -12,7 +12,7 @@ import taboolib.common.OpenResult * @author sky * @since 2021/7/3 1:44 上午 */ -class BungeeOpenContainer(plugin: Plugin) : OpenContainer { +class BungeeContainer(plugin: Plugin) : OpenContainer { private val name = plugin.description.name private val main = plugin.description.main!! diff --git a/platform/platform-velocity-impl/src/main/kotlin/taboolib/platform/VelocityOpenContainer.kt b/platform/platform-velocity-impl/src/main/kotlin/taboolib/platform/VelocityOpenContainer.kt index 078c0c418..14a6f1c74 100644 --- a/platform/platform-velocity-impl/src/main/kotlin/taboolib/platform/VelocityOpenContainer.kt +++ b/platform/platform-velocity-impl/src/main/kotlin/taboolib/platform/VelocityOpenContainer.kt @@ -4,8 +4,10 @@ import taboolib.common.OpenContainer import taboolib.common.platform.Awake import taboolib.common.platform.Platform import taboolib.common.platform.PlatformSide +import taboolib.common.platform.function.pluginId import taboolib.common.platform.service.PlatformOpenContainer -import taboolib.platform.type.VelocityOpenContainer +import taboolib.common.util.orNull +import taboolib.platform.type.VelocityContainer /** * TabooLib @@ -21,9 +23,10 @@ class VelocityOpenContainer : PlatformOpenContainer { val pluginContainer = HashMap() override fun getOpenContainers(): List { - val plugins = VelocityPlugin.getInstance().server.pluginManager.plugins - return plugins.filter { it.instance.orElse(null)?.javaClass?.name?.endsWith("platform.VelocityPlugin") == true }.mapNotNull { - pluginContainer.computeIfAbsent(it.description.id) { _ -> VelocityOpenContainer(it) } - } + return VelocityPlugin.getInstance().server.pluginManager.plugins + .filter { it.instance.orElse(null)?.javaClass?.name?.endsWith("platform.VelocityPlugin") == true && it.description.name.orNull() != pluginId } + .mapNotNull { + pluginContainer.computeIfAbsent(it.description.id) { _ -> VelocityContainer(it) } + } } } \ No newline at end of file diff --git a/platform/platform-velocity-impl/src/main/kotlin/taboolib/platform/type/VelocityOpenContainer.kt b/platform/platform-velocity-impl/src/main/kotlin/taboolib/platform/type/VelocityContainer.kt similarity index 93% rename from platform/platform-velocity-impl/src/main/kotlin/taboolib/platform/type/VelocityOpenContainer.kt rename to platform/platform-velocity-impl/src/main/kotlin/taboolib/platform/type/VelocityContainer.kt index 528809478..64933d69b 100644 --- a/platform/platform-velocity-impl/src/main/kotlin/taboolib/platform/type/VelocityOpenContainer.kt +++ b/platform/platform-velocity-impl/src/main/kotlin/taboolib/platform/type/VelocityContainer.kt @@ -12,7 +12,7 @@ import taboolib.common.OpenResult * @author sky * @since 2021/7/3 1:44 上午 */ -class VelocityOpenContainer(plugin: PluginContainer) : OpenContainer { +class VelocityContainer(plugin: PluginContainer) : OpenContainer { private val name = plugin.description.id private val main = plugin.instance.get().javaClass.name