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 bf0deaf commit cb13a14
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 32 deletions.
29 changes: 25 additions & 4 deletions src/main/kotlin/com/mcstarrysky/land/data/Land.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
@file:Suppress("DEPRECATION")

package com.mcstarrysky.land.data

import com.mcstarrysky.land.flag.PermAdmin
import com.mcstarrysky.land.flag.PermTeleport
import com.mcstarrysky.land.flag.Permission
import com.mcstarrysky.land.manager.LandManager
import com.mcstarrysky.land.serializers.ChunkSerializer
import com.mcstarrysky.land.serializers.LocationSerializer
Expand All @@ -18,6 +22,7 @@ import org.bukkit.OfflinePlayer
import org.bukkit.entity.Player
import taboolib.common5.cbool
import java.util.Date
import java.util.HashMap
import java.util.UUID

/**
Expand All @@ -41,10 +46,22 @@ data class Land(
var leaveMessage: String? = "你离开了 &{#8abcd1}$name",
@Serializable(with = LocationSerializer::class)
var tpLocation: Location,
@Deprecated(message = "协作者功能已废除")
val cooperators: MutableList<@Serializable(with = UUIDSerializer::class) UUID>,
val flags: MutableMap<String, Boolean> = mutableMapOf()
val flags: MutableMap<String, Boolean> = mutableMapOf(),
// 玩家 UUID 对一个 Map, Map 是 权限节点对应的值
val users: MutableMap<@Serializable(with = UUIDSerializer::class) UUID, MutableMap<String, Boolean>>,
) {

init {
// 迁移协作者
if (cooperators.isNotEmpty()) {
cooperators.forEach { uuid ->
(users.computeIfAbsent(uuid) { HashMap() }) += PermAdmin.id to true
}
}
}

@Transient
val date = DATE_FORMAT.format(Date(timestamp))

Expand All @@ -56,15 +73,19 @@ data class Land(
PermTeleport.teleport(player, this)
}

fun hasPermission(player: Player): Boolean {
return player.isOp || player.uniqueId == owner || player.uniqueId in cooperators
fun hasPermission(player: Player, perm: Permission? = null): Boolean {
return if (perm == null) {
player.isOp || player.uniqueId == owner || users[player.uniqueId]?.get(PermAdmin.id) == true
} else {
users[player.uniqueId]?.get(perm.id) == true
}
}

fun saveToString(): String {
return json.encodeToString(this)
}

fun getOwner(): OfflinePlayer? {
private fun getOwner(): OfflinePlayer? {
if (owner != ZERO_UUID) {
return Bukkit.getOfflinePlayer(owner)
}
Expand Down
51 changes: 51 additions & 0 deletions src/main/kotlin/com/mcstarrysky/land/flag/PermAdmin.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.mcstarrysky.land.flag

import com.mcstarrysky.land.data.Land
import com.mcstarrysky.land.util.display
import com.mcstarrysky.land.util.registerPermission
import org.bukkit.inventory.ItemStack
import taboolib.common.LifeCycle
import taboolib.common.platform.Awake
import taboolib.library.xseries.XMaterial
import taboolib.platform.util.buildItem

/**
* Land
* com.mcstarrysky.land.flag.PermAdmin
*
* @author mical
* @since 2024/8/14 11:58
*/
object PermAdmin : Permission {

@Awake(LifeCycle.ENABLE)
private fun init() {
registerPermission()
}

override val id: String
get() = "admin"

override val default: Boolean
get() = false

override val worldSide: Boolean
get() = true

override val playerSide: Boolean
get() = true

override fun generateMenuItem(land: Land): ItemStack {
return buildItem(XMaterial.COMMAND_BLOCK) {
name = "&f管理权力 ${land.getFlagOrNull(id).display}"
lore += listOf(
"&7允许行为:",
"&8除管理领地与扩展领地外的所有权力",
"",
"&e左键修改值, 右键取消设置"
)
if (land.getFlagOrNull(id) == true) shiny()
colored()
}
}
}

This file was deleted.

0 comments on commit cb13a14

Please sign in to comment.