From c6bc0dccff6232873043798b8e06dbfb9344f6b9 Mon Sep 17 00:00:00 2001 From: Micalhl Date: Wed, 14 Aug 2024 13:22:02 +0800 Subject: [PATCH] Update --- .../kotlin/com/mcstarrysky/land/data/Land.kt | 19 ++++++-- .../com/mcstarrysky/land/flag/PermAdmin.kt | 4 +- .../com/mcstarrysky/land/flag/PermBucket.kt | 4 +- .../com/mcstarrysky/land/flag/PermBuild.kt | 3 +- .../mcstarrysky/land/flag/PermContainer.kt | 3 +- .../land/flag/PermDamageAnimals.kt | 3 +- .../mcstarrysky/land/flag/PermDamageGolem.kt | 3 +- .../land/flag/PermDamageMonster.kt | 4 +- .../land/flag/PermEntityExplosion.kt | 4 +- .../com/mcstarrysky/land/flag/PermInteract.kt | 4 +- .../com/mcstarrysky/land/flag/PermMobSpawn.kt | 4 +- .../com/mcstarrysky/land/flag/PermMove.kt | 4 +- .../com/mcstarrysky/land/flag/PermTeleport.kt | 3 +- .../mcstarrysky/land/flag/PermTeleportIn.kt | 4 +- .../mcstarrysky/land/flag/PermTeleportOut.kt | 4 +- .../com/mcstarrysky/land/flag/Permission.kt | 6 +-- .../mcstarrysky/land/menu/LandFlagsMenu.kt | 20 ++++---- .../com/mcstarrysky/land/menu/LandInfoMenu.kt | 14 ++++-- ...peratorsMenu.kt => LandPlayerPermsMenu.kt} | 48 ++++++++++++++----- 19 files changed, 102 insertions(+), 56 deletions(-) rename src/main/kotlin/com/mcstarrysky/land/menu/{LandCooperatorsMenu.kt => LandPlayerPermsMenu.kt} (55%) diff --git a/src/main/kotlin/com/mcstarrysky/land/data/Land.kt b/src/main/kotlin/com/mcstarrysky/land/data/Land.kt index e2a4bf7..65327ef 100644 --- a/src/main/kotlin/com/mcstarrysky/land/data/Land.kt +++ b/src/main/kotlin/com/mcstarrysky/land/data/Land.kt @@ -110,12 +110,25 @@ data class Land( return flags[flag]?.cbool } - fun setFlag(flag: String, value: Boolean?) { + /** + * 设置权限 + * other == null -> 设置领地通用权限 + * other != null -> 设置玩家在该领地的权限 + */ + fun setFlag(flag: String, value: Boolean?, other: OfflinePlayer?) { if (value == null) { - flags -= flag + if (other != null) { + (users.computeIfAbsent(other.uniqueId) { HashMap() }) -= flag + } else { + flags -= flag + } return } - flags += flag to value + if (other != null) { + (users.computeIfAbsent(other.uniqueId) { HashMap() }) += flag to value + } else { + flags += flag to value + } } fun export() { diff --git a/src/main/kotlin/com/mcstarrysky/land/flag/PermAdmin.kt b/src/main/kotlin/com/mcstarrysky/land/flag/PermAdmin.kt index a7315e3..3efea2b 100644 --- a/src/main/kotlin/com/mcstarrysky/land/flag/PermAdmin.kt +++ b/src/main/kotlin/com/mcstarrysky/land/flag/PermAdmin.kt @@ -2,7 +2,7 @@ package com.mcstarrysky.land.flag import com.mcstarrysky.land.data.Land import com.mcstarrysky.land.util.registerPermission -import org.bukkit.entity.Player +import org.bukkit.OfflinePlayer import org.bukkit.inventory.ItemStack import taboolib.common.LifeCycle import taboolib.common.platform.Awake @@ -35,7 +35,7 @@ object PermAdmin : Permission { override val playerSide: Boolean get() = true - override fun generateMenuItem(land: Land, player: Player?): ItemStack { + override fun generateMenuItem(land: Land, player: OfflinePlayer?): ItemStack { return buildItem(XMaterial.COMMAND_BLOCK) { name = "&f管理权力 ${flagValue(land, player)}" lore += listOf( diff --git a/src/main/kotlin/com/mcstarrysky/land/flag/PermBucket.kt b/src/main/kotlin/com/mcstarrysky/land/flag/PermBucket.kt index d7f3aa7..634c9cc 100644 --- a/src/main/kotlin/com/mcstarrysky/land/flag/PermBucket.kt +++ b/src/main/kotlin/com/mcstarrysky/land/flag/PermBucket.kt @@ -4,7 +4,7 @@ import com.mcstarrysky.land.data.Land import com.mcstarrysky.land.manager.LandManager import com.mcstarrysky.land.util.prettyInfo import com.mcstarrysky.land.util.registerPermission -import org.bukkit.entity.Player +import org.bukkit.OfflinePlayer import org.bukkit.event.player.PlayerBucketEmptyEvent import org.bukkit.event.player.PlayerBucketFillEvent import org.bukkit.inventory.ItemStack @@ -40,7 +40,7 @@ object PermBucket : Permission { override val playerSide: Boolean get() = true - override fun generateMenuItem(land: Land, player: Player?): ItemStack { + override fun generateMenuItem(land: Land, player: OfflinePlayer?): ItemStack { return buildItem(XMaterial.BUCKET) { name = "&f使用桶 ${flagValue(land, player)}" lore += listOf( diff --git a/src/main/kotlin/com/mcstarrysky/land/flag/PermBuild.kt b/src/main/kotlin/com/mcstarrysky/land/flag/PermBuild.kt index 85e69ca..2471b5e 100644 --- a/src/main/kotlin/com/mcstarrysky/land/flag/PermBuild.kt +++ b/src/main/kotlin/com/mcstarrysky/land/flag/PermBuild.kt @@ -4,6 +4,7 @@ import com.mcstarrysky.land.data.Land import com.mcstarrysky.land.manager.LandManager import com.mcstarrysky.land.util.prettyInfo import com.mcstarrysky.land.util.registerPermission +import org.bukkit.OfflinePlayer import org.bukkit.entity.ArmorStand import org.bukkit.entity.Player import org.bukkit.event.block.Action @@ -47,7 +48,7 @@ object PermBuild : Permission { override val playerSide: Boolean get() = true - override fun generateMenuItem(land: Land, player: Player?): ItemStack { + override fun generateMenuItem(land: Land, player: OfflinePlayer?): ItemStack { return buildItem(XMaterial.GRASS_BLOCK) { name = "&f建筑 ${flagValue(land, player)}" lore += listOf( diff --git a/src/main/kotlin/com/mcstarrysky/land/flag/PermContainer.kt b/src/main/kotlin/com/mcstarrysky/land/flag/PermContainer.kt index 461af8d..8a17b4b 100644 --- a/src/main/kotlin/com/mcstarrysky/land/flag/PermContainer.kt +++ b/src/main/kotlin/com/mcstarrysky/land/flag/PermContainer.kt @@ -4,6 +4,7 @@ import com.mcstarrysky.land.data.Land import com.mcstarrysky.land.manager.LandManager import com.mcstarrysky.land.util.prettyInfo import com.mcstarrysky.land.util.registerPermission +import org.bukkit.OfflinePlayer import org.bukkit.entity.Player import org.bukkit.event.inventory.InventoryOpenEvent import org.bukkit.inventory.ItemFlag @@ -40,7 +41,7 @@ object PermContainer : Permission { override val playerSide: Boolean get() = true - override fun generateMenuItem(land: Land, player: Player?): ItemStack { + override fun generateMenuItem(land: Land, player: OfflinePlayer?): ItemStack { return buildItem(XMaterial.CHEST) { name = "&f容器 ${flagValue(land, player)}" lore += listOf( diff --git a/src/main/kotlin/com/mcstarrysky/land/flag/PermDamageAnimals.kt b/src/main/kotlin/com/mcstarrysky/land/flag/PermDamageAnimals.kt index 865a613..9c7410d 100644 --- a/src/main/kotlin/com/mcstarrysky/land/flag/PermDamageAnimals.kt +++ b/src/main/kotlin/com/mcstarrysky/land/flag/PermDamageAnimals.kt @@ -4,6 +4,7 @@ import com.mcstarrysky.land.data.Land import com.mcstarrysky.land.manager.LandManager import com.mcstarrysky.land.util.prettyInfo import com.mcstarrysky.land.util.registerPermission +import org.bukkit.OfflinePlayer import org.bukkit.entity.Animals import org.bukkit.entity.Player import org.bukkit.event.entity.EntityDamageByEntityEvent @@ -41,7 +42,7 @@ object PermDamageAnimals : Permission { override val playerSide: Boolean get() = true - override fun generateMenuItem(land: Land, player: Player?): ItemStack { + override fun generateMenuItem(land: Land, player: OfflinePlayer?): ItemStack { return buildItem(XMaterial.IRON_SWORD){ name = "&f攻击动物 ${flagValue(land, player)}" lore += listOf( diff --git a/src/main/kotlin/com/mcstarrysky/land/flag/PermDamageGolem.kt b/src/main/kotlin/com/mcstarrysky/land/flag/PermDamageGolem.kt index fd1f6c6..a9c363c 100644 --- a/src/main/kotlin/com/mcstarrysky/land/flag/PermDamageGolem.kt +++ b/src/main/kotlin/com/mcstarrysky/land/flag/PermDamageGolem.kt @@ -4,6 +4,7 @@ import com.mcstarrysky.land.data.Land import com.mcstarrysky.land.manager.LandManager import com.mcstarrysky.land.util.prettyInfo import com.mcstarrysky.land.util.registerPermission +import org.bukkit.OfflinePlayer import org.bukkit.entity.Golem import org.bukkit.entity.Player import org.bukkit.event.entity.EntityDamageByEntityEvent @@ -41,7 +42,7 @@ object PermDamageGolem : Permission { override val playerSide: Boolean get() = true - override fun generateMenuItem(land: Land, player: Player?): ItemStack { + override fun generateMenuItem(land: Land, player: OfflinePlayer?): ItemStack { return buildItem(XMaterial.STONE_SWORD){ name = "&f攻击傀儡 ${flagValue(land, player)}" lore += listOf( diff --git a/src/main/kotlin/com/mcstarrysky/land/flag/PermDamageMonster.kt b/src/main/kotlin/com/mcstarrysky/land/flag/PermDamageMonster.kt index de2454a..5999f4d 100644 --- a/src/main/kotlin/com/mcstarrysky/land/flag/PermDamageMonster.kt +++ b/src/main/kotlin/com/mcstarrysky/land/flag/PermDamageMonster.kt @@ -2,9 +2,9 @@ package com.mcstarrysky.land.flag import com.mcstarrysky.land.data.Land import com.mcstarrysky.land.manager.LandManager -import com.mcstarrysky.land.util.display import com.mcstarrysky.land.util.prettyInfo import com.mcstarrysky.land.util.registerPermission +import org.bukkit.OfflinePlayer import org.bukkit.entity.Monster import org.bukkit.entity.Player import org.bukkit.event.entity.EntityDamageByEntityEvent @@ -42,7 +42,7 @@ object PermDamageMonster : Permission{ override val playerSide: Boolean get() = true - override fun generateMenuItem(land: Land, player: Player?): ItemStack { + override fun generateMenuItem(land: Land, player: OfflinePlayer?): ItemStack { return buildItem(XMaterial.GOLDEN_SWORD){ name = "&f攻击怪物 ${flagValue(land, player)}" lore += listOf( diff --git a/src/main/kotlin/com/mcstarrysky/land/flag/PermEntityExplosion.kt b/src/main/kotlin/com/mcstarrysky/land/flag/PermEntityExplosion.kt index a962f26..05b5111 100644 --- a/src/main/kotlin/com/mcstarrysky/land/flag/PermEntityExplosion.kt +++ b/src/main/kotlin/com/mcstarrysky/land/flag/PermEntityExplosion.kt @@ -3,7 +3,7 @@ package com.mcstarrysky.land.flag import com.mcstarrysky.land.data.Land import com.mcstarrysky.land.manager.LandManager import com.mcstarrysky.land.util.registerPermission -import org.bukkit.entity.Player +import org.bukkit.OfflinePlayer import org.bukkit.event.entity.EntityExplodeEvent import org.bukkit.inventory.ItemStack import taboolib.common.LifeCycle @@ -36,7 +36,7 @@ object PermEntityExplosion : Permission { override val playerSide: Boolean get() = true - override fun generateMenuItem(land: Land, player: Player?): ItemStack { + override fun generateMenuItem(land: Land, player: OfflinePlayer?): ItemStack { return buildItem(XMaterial.CREEPER_SPAWN_EGG) { name = "&f爆炸 ${flagValue(land, player)}" lore += listOf( diff --git a/src/main/kotlin/com/mcstarrysky/land/flag/PermInteract.kt b/src/main/kotlin/com/mcstarrysky/land/flag/PermInteract.kt index fb93979..d14f440 100644 --- a/src/main/kotlin/com/mcstarrysky/land/flag/PermInteract.kt +++ b/src/main/kotlin/com/mcstarrysky/land/flag/PermInteract.kt @@ -4,7 +4,7 @@ import com.mcstarrysky.land.data.Land import com.mcstarrysky.land.manager.LandManager import com.mcstarrysky.land.util.prettyInfo import com.mcstarrysky.land.util.registerPermission -import org.bukkit.entity.Player +import org.bukkit.OfflinePlayer import org.bukkit.event.block.Action import org.bukkit.event.player.PlayerInteractEvent import org.bukkit.inventory.ItemStack @@ -40,7 +40,7 @@ object PermInteract : Permission { override val playerSide: Boolean get() = true - override fun generateMenuItem(land: Land, player: Player?): ItemStack { + override fun generateMenuItem(land: Land, player: OfflinePlayer?): ItemStack { return buildItem(XMaterial.OAK_DOOR) { name = "&f交互 ${flagValue(land, player)}" lore += listOf( diff --git a/src/main/kotlin/com/mcstarrysky/land/flag/PermMobSpawn.kt b/src/main/kotlin/com/mcstarrysky/land/flag/PermMobSpawn.kt index 73eef28..cc86822 100644 --- a/src/main/kotlin/com/mcstarrysky/land/flag/PermMobSpawn.kt +++ b/src/main/kotlin/com/mcstarrysky/land/flag/PermMobSpawn.kt @@ -3,8 +3,8 @@ package com.mcstarrysky.land.flag import com.mcstarrysky.land.data.Land import com.mcstarrysky.land.manager.LandManager import com.mcstarrysky.land.util.registerPermission +import org.bukkit.OfflinePlayer import org.bukkit.entity.Monster -import org.bukkit.entity.Player import org.bukkit.event.entity.EntitySpawnEvent import org.bukkit.inventory.ItemFlag import org.bukkit.inventory.ItemStack @@ -40,7 +40,7 @@ object PermMobSpawn : Permission { override val playerSide: Boolean get() = true - override fun generateMenuItem(land: Land, player: Player?): ItemStack { + override fun generateMenuItem(land: Land, player: OfflinePlayer?): ItemStack { return buildItem(XMaterial.ZOMBIE_SPAWN_EGG) { name = "&f怪物产生 ${flagValue(land, player)}" lore += listOf( diff --git a/src/main/kotlin/com/mcstarrysky/land/flag/PermMove.kt b/src/main/kotlin/com/mcstarrysky/land/flag/PermMove.kt index 86e8a3b..72eeb10 100644 --- a/src/main/kotlin/com/mcstarrysky/land/flag/PermMove.kt +++ b/src/main/kotlin/com/mcstarrysky/land/flag/PermMove.kt @@ -4,7 +4,7 @@ import com.mcstarrysky.land.data.Land import com.mcstarrysky.land.manager.LandManager import com.mcstarrysky.land.util.* import org.bukkit.Location -import org.bukkit.entity.Player +import org.bukkit.OfflinePlayer import org.bukkit.inventory.ItemFlag import org.bukkit.inventory.ItemStack import taboolib.common.LifeCycle @@ -38,7 +38,7 @@ object PermMove : Permission { override val playerSide: Boolean get() = true - override fun generateMenuItem(land: Land, player: Player?): ItemStack { + override fun generateMenuItem(land: Land, player: OfflinePlayer?): ItemStack { return buildItem(XMaterial.IRON_BOOTS) { name = "&f移动 ${flagValue(land, player)}" lore += listOf( diff --git a/src/main/kotlin/com/mcstarrysky/land/flag/PermTeleport.kt b/src/main/kotlin/com/mcstarrysky/land/flag/PermTeleport.kt index 55642ad..6e75b44 100644 --- a/src/main/kotlin/com/mcstarrysky/land/flag/PermTeleport.kt +++ b/src/main/kotlin/com/mcstarrysky/land/flag/PermTeleport.kt @@ -3,6 +3,7 @@ package com.mcstarrysky.land.flag import com.mcstarrysky.land.data.Land import com.mcstarrysky.land.util.prettyInfo import com.mcstarrysky.land.util.registerPermission +import org.bukkit.OfflinePlayer import org.bukkit.entity.Player import org.bukkit.inventory.ItemStack import taboolib.common.LifeCycle @@ -33,7 +34,7 @@ object PermTeleport : Permission { override val playerSide: Boolean get() = true - override fun generateMenuItem(land: Land, player: Player?): ItemStack { + override fun generateMenuItem(land: Land, player: OfflinePlayer?): ItemStack { return buildItem(XMaterial.ENDER_PEARL) { name = "&f传送 ${flagValue(land, player)}" lore += listOf( diff --git a/src/main/kotlin/com/mcstarrysky/land/flag/PermTeleportIn.kt b/src/main/kotlin/com/mcstarrysky/land/flag/PermTeleportIn.kt index 05d78ec..de009e5 100644 --- a/src/main/kotlin/com/mcstarrysky/land/flag/PermTeleportIn.kt +++ b/src/main/kotlin/com/mcstarrysky/land/flag/PermTeleportIn.kt @@ -4,7 +4,7 @@ import com.mcstarrysky.land.data.Land import com.mcstarrysky.land.manager.LandManager import com.mcstarrysky.land.util.prettyInfo import com.mcstarrysky.land.util.registerPermission -import org.bukkit.entity.Player +import org.bukkit.OfflinePlayer import org.bukkit.event.player.PlayerTeleportEvent import org.bukkit.inventory.ItemFlag import org.bukkit.inventory.ItemStack @@ -39,7 +39,7 @@ object PermTeleportIn : Permission { override val playerSide: Boolean get() = true - override fun generateMenuItem(land: Land, player: Player?): ItemStack { + override fun generateMenuItem(land: Land, player: OfflinePlayer?): ItemStack { return buildItem(XMaterial.DIAMOND_BOOTS) { name = "&f传送进来 ${flagValue(land, player)}" lore += listOf( diff --git a/src/main/kotlin/com/mcstarrysky/land/flag/PermTeleportOut.kt b/src/main/kotlin/com/mcstarrysky/land/flag/PermTeleportOut.kt index 3c9aa26..d061678 100644 --- a/src/main/kotlin/com/mcstarrysky/land/flag/PermTeleportOut.kt +++ b/src/main/kotlin/com/mcstarrysky/land/flag/PermTeleportOut.kt @@ -4,7 +4,7 @@ import com.mcstarrysky.land.data.Land import com.mcstarrysky.land.manager.LandManager import com.mcstarrysky.land.util.prettyInfo import com.mcstarrysky.land.util.registerPermission -import org.bukkit.entity.Player +import org.bukkit.OfflinePlayer import org.bukkit.event.player.PlayerTeleportEvent import org.bukkit.inventory.ItemFlag import org.bukkit.inventory.ItemStack @@ -39,7 +39,7 @@ object PermTeleportOut : Permission { override val playerSide: Boolean get() = true - override fun generateMenuItem(land: Land, player: Player?): ItemStack { + override fun generateMenuItem(land: Land, player: OfflinePlayer?): ItemStack { return buildItem(XMaterial.LEATHER_BOOTS) { name = "&f传送出去 ${flagValue(land, player)}" lore += listOf( diff --git a/src/main/kotlin/com/mcstarrysky/land/flag/Permission.kt b/src/main/kotlin/com/mcstarrysky/land/flag/Permission.kt index d66e8be..c3481c1 100644 --- a/src/main/kotlin/com/mcstarrysky/land/flag/Permission.kt +++ b/src/main/kotlin/com/mcstarrysky/land/flag/Permission.kt @@ -2,7 +2,7 @@ package com.mcstarrysky.land.flag import com.mcstarrysky.land.data.Land import com.mcstarrysky.land.util.display -import org.bukkit.entity.Player +import org.bukkit.OfflinePlayer import org.bukkit.inventory.ItemStack /** @@ -50,14 +50,14 @@ interface Permission { /** * 构建界面物品 */ - fun generateMenuItem(land: Land, player: Player? = null): ItemStack + fun generateMenuItem(land: Land, player: OfflinePlayer? = null): ItemStack /** * 适用于构建界面物品 * Player == null -> 该领地的该权限节点的权限设置情况 * Player != null -> 玩家在该领地的该权限节点的权限设置情况 */ - fun flagValue(land: Land, user: Player? = null): String { + fun flagValue(land: Land, user: OfflinePlayer? = null): String { if (user != null) { return land.users[user.uniqueId]?.get(id).display } diff --git a/src/main/kotlin/com/mcstarrysky/land/menu/LandFlagsMenu.kt b/src/main/kotlin/com/mcstarrysky/land/menu/LandFlagsMenu.kt index e216396..536ae40 100644 --- a/src/main/kotlin/com/mcstarrysky/land/menu/LandFlagsMenu.kt +++ b/src/main/kotlin/com/mcstarrysky/land/menu/LandFlagsMenu.kt @@ -6,6 +6,7 @@ import com.mcstarrysky.land.manager.LandManager import com.mcstarrysky.land.util.MenuRegistry import com.mcstarrysky.land.util.MenuRegistry.markHeader import com.mcstarrysky.land.util.MenuRegistry.markPageButton +import org.bukkit.OfflinePlayer import org.bukkit.entity.Player import org.bukkit.event.inventory.ClickType import taboolib.module.ui.openMenu @@ -21,8 +22,8 @@ import java.util.function.Consumer */ object LandFlagsMenu { - fun openMenu(player: Player, land: Land, back: Consumer?, elements: List) { - player.openMenu>("领地(ID:${land.id}) ${land.name} 标记管理") { + fun openMenu(player: Player, land: Land, other: OfflinePlayer?, back: Consumer?) { + player.openMenu>("标记管理") { virtualize() map( @@ -33,31 +34,32 @@ object LandFlagsMenu { slotsBy('#') + // TODO: filter elements { LandManager.permissions } - onGenerate(async = true) { _, flag, _, _ -> flag.generateMenuItem(land) } + onGenerate(async = true) { _, flag, _, _ -> flag.generateMenuItem(land, other) } markHeader() markPageButton() - set('b', MenuRegistry.BACK) { LandInfoMenu.openMenu(player, land, back, elements) } + set('b', MenuRegistry.BACK) { back?.accept(player) } onClick { event, flag -> when (event.virtualEvent().clickType) { ClickType.LEFT, ClickType.SHIFT_LEFT -> { // 如果没设置, 就设置成默认值 if (land.getFlagValueOrNull(flag.id) == null) { - land.setFlag(flag.id, flag.default) + land.setFlag(flag.id, flag.default, other) } else { val value = land.getFlag(flag.id) - land.setFlag(flag.id, !value) + land.setFlag(flag.id, !value, other) } - openMenu(player, land, back, elements) + openMenu(player, land, other, back) } ClickType.RIGHT, ClickType.SHIFT_RIGHT -> { if (land.getFlagValueOrNull(flag.id) != null) { - land.setFlag(flag.id, null) - openMenu(player, land, back, elements) + land.setFlag(flag.id, null, other) + openMenu(player, land, other, back) } } else -> { diff --git a/src/main/kotlin/com/mcstarrysky/land/menu/LandInfoMenu.kt b/src/main/kotlin/com/mcstarrysky/land/menu/LandInfoMenu.kt index 0e26ccc..f6c3597 100644 --- a/src/main/kotlin/com/mcstarrysky/land/menu/LandInfoMenu.kt +++ b/src/main/kotlin/com/mcstarrysky/land/menu/LandInfoMenu.kt @@ -233,19 +233,23 @@ object LandInfoMenu { colored() }) { if (!check(player, land)) return@set - LandFlagsMenu.openMenu(player, land, back, elements) + LandFlagsMenu.openMenu(player, land, null) { + openMenu(player, land, back, elements) + } } set('m', buildItem(XMaterial.PLAYER_HEAD) { - name = "&a查看协作者" + name = "&a管理玩家权限" lore += listOf( - "&7协作者具有领地的大部分权限", - "&7但没有领地的设置与修改权" + "&7管理指定玩家在领地内的权限", + "&7例如设置某个玩家禁止移动" ) colored() }) { if (!check(player, land)) return@set - LandCooperatorsMenu.openMenu(player, land, back, elements) + LandPlayerPermsMenu.openMenu(player, land) { + openMenu(player, land, back, elements) + } } } } diff --git a/src/main/kotlin/com/mcstarrysky/land/menu/LandCooperatorsMenu.kt b/src/main/kotlin/com/mcstarrysky/land/menu/LandPlayerPermsMenu.kt similarity index 55% rename from src/main/kotlin/com/mcstarrysky/land/menu/LandCooperatorsMenu.kt rename to src/main/kotlin/com/mcstarrysky/land/menu/LandPlayerPermsMenu.kt index 933c26d..041b4ae 100644 --- a/src/main/kotlin/com/mcstarrysky/land/menu/LandCooperatorsMenu.kt +++ b/src/main/kotlin/com/mcstarrysky/land/menu/LandPlayerPermsMenu.kt @@ -9,6 +9,7 @@ import com.mcstarrysky.land.util.skull import org.bukkit.Bukkit import org.bukkit.OfflinePlayer import org.bukkit.entity.Player +import org.bukkit.event.inventory.ClickType import taboolib.common.util.sync import taboolib.library.xseries.XMaterial import taboolib.module.ui.openMenu @@ -24,11 +25,12 @@ import java.util.function.Consumer * @author mical * @since 2024/8/3 16:45 */ -object LandCooperatorsMenu { +object LandPlayerPermsMenu { - fun openMenu(player: Player, land: Land, back: Consumer?, elements: List) { - player.openMenu>("领地(ID:${land.id}) ${land.name} 合作者") { - virtualize() + // 为什么要设计那个 elements 参数当返回? 什么脑回路 + fun openMenu(player: Player, land: Land, back: Consumer?) {//, elements: List) { + player.openMenu>("玩家权限管理") { + // virtualize() map( "b===+==pn", @@ -38,26 +40,37 @@ object LandCooperatorsMenu { slotsBy('#') - elements { land.cooperators.map { Bukkit.getOfflinePlayer(it) } } + elements { land.users.keys.map { Bukkit.getOfflinePlayer(it) } } markHeader() markPageButton() - set('b', MenuRegistry.BACK) { LandInfoMenu.openMenu(player, land, back, elements) } + set('b', MenuRegistry.BACK) { back?.accept(player) } onGenerate(async = true) { _, p, _, _ -> buildItem(XMaterial.PLAYER_HEAD) { name = "&f" + p.name lore += listOf( - "&e单击删除" + "&e左击删除, 右击管理权限" ) colored() }.skull(p.name) } - onClick { _, p -> - land.cooperators -= p.uniqueId - openMenu(player, land, back, elements) + onClick { e, p -> + when (e.clickEvent().click) { + ClickType.LEFT, ClickType.SHIFT_LEFT -> { + land.users -= p.uniqueId + openMenu(player, land, back) + } + ClickType.RIGHT, ClickType.SHIFT_RIGHT -> { + LandFlagsMenu.openMenu(player, land, p) { + openMenu(player, land, back) + } + } + else -> { + } + } } set('+', buildItem(XMaterial.NAME_TAG) { @@ -78,9 +91,18 @@ object LandCooperatorsMenu { clicker.prettyInfo("并没有找到这位玩家!") return@nextChat } - land.cooperators += offlinePlayer.uniqueId - clicker.prettyInfo("添加成功!") - sync { openMenu(clicker, land, back, elements) } + if (land.users[offlinePlayer.uniqueId] != null) { + clicker.prettyInfo("已存在该玩家的信息! 将为您直接打开设置面版!") + } else { + land.users[offlinePlayer.uniqueId] = HashMap() + clicker.prettyInfo("添加成功!") + } + // land.cooperators += offlinePlayer.uniqueId + // 优化: 添加后直接打开对应玩家的权限配置面板, 因为玩家添加就是为了设置的, 直接打开省一步操作, 优化体验 + // sync { openMenu(clicker, land, back) } + sync { LandFlagsMenu.openMenu(clicker, land, offlinePlayer) { + openMenu(clicker, land, back) + } } } }