Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Micalhl committed Aug 14, 2024
1 parent 0770981 commit c6bc0dc
Show file tree
Hide file tree
Showing 19 changed files with 102 additions and 56 deletions.
19 changes: 16 additions & 3 deletions src/main/kotlin/com/mcstarrysky/land/data/Land.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/com/mcstarrysky/land/flag/PermAdmin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/com/mcstarrysky/land/flag/PermBucket.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
3 changes: 2 additions & 1 deletion src/main/kotlin/com/mcstarrysky/land/flag/PermBuild.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
3 changes: 2 additions & 1 deletion src/main/kotlin/com/mcstarrysky/land/flag/PermContainer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
3 changes: 2 additions & 1 deletion src/main/kotlin/com/mcstarrysky/land/flag/PermDamageGolem.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/com/mcstarrysky/land/flag/PermInteract.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/com/mcstarrysky/land/flag/PermMobSpawn.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/com/mcstarrysky/land/flag/PermMove.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
3 changes: 2 additions & 1 deletion src/main/kotlin/com/mcstarrysky/land/flag/PermTeleport.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/com/mcstarrysky/land/flag/PermTeleportIn.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/com/mcstarrysky/land/flag/PermTeleportOut.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions src/main/kotlin/com/mcstarrysky/land/flag/Permission.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand Down Expand Up @@ -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
}
Expand Down
20 changes: 11 additions & 9 deletions src/main/kotlin/com/mcstarrysky/land/menu/LandFlagsMenu.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -21,8 +22,8 @@ import java.util.function.Consumer
*/
object LandFlagsMenu {

fun openMenu(player: Player, land: Land, back: Consumer<Player>?, elements: List<Land>) {
player.openMenu<PageableChest<Permission>>("领地(ID:${land.id}) ${land.name} 标记管理") {
fun openMenu(player: Player, land: Land, other: OfflinePlayer?, back: Consumer<Player>?) {
player.openMenu<PageableChest<Permission>>("标记管理") {
virtualize()

map(
Expand All @@ -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 -> {
Expand Down
14 changes: 9 additions & 5 deletions src/main/kotlin/com/mcstarrysky/land/menu/LandInfoMenu.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
}
Expand Down
Loading

0 comments on commit c6bc0dc

Please sign in to comment.