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 fcebfd0 commit a81f3cf
Show file tree
Hide file tree
Showing 14 changed files with 132 additions and 64 deletions.
3 changes: 1 addition & 2 deletions src/main/kotlin/com/mcstarrysky/land/Land.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import taboolib.common.env.RuntimeDependencies
import taboolib.common.env.RuntimeDependency
import taboolib.common.platform.Plugin
import taboolib.library.xseries.XMaterial
import taboolib.module.ui.virtual.InventoryHandler
import taboolib.platform.util.buildItem

/**
Expand Down Expand Up @@ -64,7 +63,7 @@ object Land : Plugin() {

override fun onEnable() {
LandManager.import()
InventoryHandler.instance
// InventoryHandler.instance
}

override fun onDisable() {
Expand Down
6 changes: 6 additions & 0 deletions src/main/kotlin/com/mcstarrysky/land/LandCommands.kt
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,11 @@ object LandCommands {
}
}
}
command("landdelete", permission = "admin") {
exec<Player> {
val land = LandManager.getLand(sender.location) ?: return@exec
land.area -= sender.location.chunk
}
}
}
}
36 changes: 19 additions & 17 deletions src/main/kotlin/com/mcstarrysky/land/data/Land.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
@file:Suppress("DEPRECATION")

package com.mcstarrysky.land.data

import com.mcstarrysky.land.Land
Expand Down Expand Up @@ -27,8 +25,8 @@ import taboolib.module.chat.Components
import taboolib.platform.util.checkItem
import taboolib.platform.util.takeItem
import java.util.Date
import java.util.HashMap
import java.util.UUID
import kotlin.collections.HashMap

/**
* Land
Expand All @@ -51,22 +49,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>,
// @Deprecated(message = "协作者功能已废除")
// val cooperators: MutableList<@Serializable(with = UUIDSerializer::class) UUID>,
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
}
cooperators.clear()
}
}
// init {
// // 迁移协作者
// if (cooperators.isNotEmpty()) {
// cooperators.forEach { uuid ->
// (users.computeIfAbsent(uuid) { HashMap() }) += PermAdmin.id to true
// }
// cooperators.clear()
// }
// }

@Transient
val date = DATE_FORMAT.format(Date(timestamp))
Expand All @@ -85,6 +83,10 @@ data class Land(
player.prettyInfo("你所要占领的区块已被其他领地占领, 请换一个区块!")
return
}
if (!ChunkUtils.isAdjacentToAnyChunk(location.chunk, area)) {
player.prettyInfo("占领的区块必须与你领地相邻!")
return
}
if (player.checkItem(Land.crystal, 3)) {
player.inventory.takeItem(3) { it.isSimilar(Land.crystal) }
area += location.chunk
Expand All @@ -93,7 +95,7 @@ data class Land(
// 这里用到一个奇怪的操作
Components.parseRaw(
GsonComponentSerializer.gson()
.serialize(GsonComponentSerializer.gson().deserialize(cacheMessageWithPrefix("抱歉, 你要准备 3 个").toRawMessage())
.serialize(GsonComponentSerializer.gson().deserialize(cacheMessageWithPrefix("抱歉, 你要准备 3 个 ").toRawMessage())
.append(LegacyComponentSerializer.legacyAmpersand().deserialize("&b开拓水晶")
.hoverEvent(Land.crystal.clone().asHoverEvent())))
).append(cacheMessageWithPrefixColor(" 才能占领一个区块"))
Expand All @@ -111,8 +113,8 @@ data class Land(
}

fun hasPermission(player: Player, perm: Permission? = null): Boolean {
return if (perm == null) {
player.isOp || player.uniqueId == owner || users[player.uniqueId]?.get(PermAdmin.id) == true
return isAdmin(player) || if (perm == null) {
users[player.uniqueId]?.get(PermAdmin.id) == true
} else {
users[player.uniqueId]?.get(perm.id) ?: getFlag(perm.id)
}
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 @@ -20,6 +20,7 @@ import taboolib.common.LifeCycle
import taboolib.common.platform.Awake
import taboolib.common.platform.event.SubscribeEvent
import taboolib.library.xseries.XMaterial
import taboolib.platform.util.attacker
import taboolib.platform.util.buildItem

/**
Expand Down Expand Up @@ -124,7 +125,7 @@ object PermBuild : Permission {
@SubscribeEvent(ignoreCancelled = true)
fun e(e: EntityDamageByEntityEvent) {
if (e.entity is ArmorStand) {
val player = e.damager as? Player ?: return
val player = e.attacker as? Player ?: return
// val player = Servers.getAttackerInDamageEvent(e) ?: return
LandManager.getLand(e.entity.location.block.location)?.run {
if (!hasPermission(player, this@PermBuild)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import taboolib.common.LifeCycle
import taboolib.common.platform.Awake
import taboolib.common.platform.event.SubscribeEvent
import taboolib.library.xseries.XMaterial
import taboolib.platform.util.attacker
import taboolib.platform.util.buildItem

/**
Expand Down Expand Up @@ -60,7 +61,7 @@ object PermDamageAnimals : Permission {
@SubscribeEvent(ignoreCancelled = true)
fun e(e: EntityDamageByEntityEvent) {
if (e.entity is Animals) {
val player = e.damager as? Player ?: return
val player = e.attacker as? Player ?: return
LandManager.getLand(e.entity.location)?.run {
if (!hasPermission(player, this@PermDamageAnimals)) {
e.isCancelled = true
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 @@ -14,6 +14,7 @@ import taboolib.common.LifeCycle
import taboolib.common.platform.Awake
import taboolib.common.platform.event.SubscribeEvent
import taboolib.library.xseries.XMaterial
import taboolib.platform.util.attacker
import taboolib.platform.util.buildItem

/**
Expand Down Expand Up @@ -60,7 +61,7 @@ object PermDamageGolem : Permission {
@SubscribeEvent(ignoreCancelled = true)
fun e(e: EntityDamageByEntityEvent) {
if (e.entity is Golem) {
val player = e.damager as? Player ?: return
val player = e.attacker as? Player ?: return
LandManager.getLand(e.entity.location)?.run {
if (!hasPermission(player, this@PermDamageGolem)) {
e.isCancelled = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import taboolib.common.LifeCycle
import taboolib.common.platform.Awake
import taboolib.common.platform.event.SubscribeEvent
import taboolib.library.xseries.XMaterial
import taboolib.platform.util.attacker
import taboolib.platform.util.buildItem

/**
Expand Down Expand Up @@ -61,7 +62,7 @@ object PermDamageMonster : Permission{
@SubscribeEvent(ignoreCancelled = true)
fun e(e: EntityDamageByEntityEvent) {
if (e.entity is Monster) {
val player = e.damager as Player
val player = e.attacker as? Player ?: return
LandManager.getLand(e.entity.location)?.run {
if (!hasPermission(player, this@PermDamageMonster)) {
e.isCancelled = true
Expand Down
73 changes: 52 additions & 21 deletions src/main/kotlin/com/mcstarrysky/land/listener/PosSelection.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ object PosSelection {
val pos1 = ConcurrentHashMap<UUID, Chunk>()
val pos2 = ConcurrentHashMap<UUID, Chunk>()

// @SubscribeEvent
@SubscribeEvent
fun e(e: PlayerInteractEvent) {
val player = e.player
// 主手
Expand All @@ -35,43 +35,74 @@ object PosSelection {
// 判断左右键
when {
e.isLeftClickBlock() -> {
e.isCancelled = true
val pos = e.clickedBlock!!.location.chunk
pos1.computeIfAbsent(player.uniqueId) { pos }
if (pos2[player.uniqueId] == null) {
player.prettyInfo("+========选择的范围信息========+[](br)" +
"世界: &b" + LandSettings.worldAliases[pos.world.name] + "[](br)" +
"点1: &b(${pos.x}, ${pos.z})[](br)" +
"+===================================+")
listOf(
"+========选择的范围信息========+",
"世界: &{#8cc269}" + LandSettings.worldAliases[pos.world.name],
"点1: &{#8cc269}(${pos.x}, ${pos.z})",
"+===========================+"
).forEach { player.prettyInfo(it) }
// player.prettyInfo("+========选择的范围信息========+[](br)" +
// "世界: &{#8cc269}" + LandSettings.worldAliases[pos.world.name] + "[](br)" +
// "点1: &{#8cc269}(${pos.x}, ${pos.z})[](br)" +
// "+===================================+")
//"+==(输入/land进入领地主菜单)==+")
} else {
val p2 = pos2[player.uniqueId]!!
val chunks = ChunkUtils.getChunksInRectangle(pos.world, pos, p2)
player.prettyInfo("+========选择的范围信息========+[](br)" +
"世界: &b" + LandSettings.worldAliases[pos.world.name] + "[](br)" +
"点1: &b(${pos.x}, ${pos.z})[](br)" +
"点2: &b(${p2.x}, ${p2.z})[](br)" +
"范围花费: 每区块3*区块数${chunks.size}=${3*chunks.size}个开拓水晶[](br)" +
"+==(输入/land进入领地主菜单)==+")
listOf(
"+========选择的范围信息========+",
"世界: &{#8cc269}" + LandSettings.worldAliases[pos.world.name],
"点1: &{#8cc269}(${pos.x}, ${pos.z})",
"点2: &{#8cc269}(${p2.x}, ${p2.z})",
"范围花费: 每区块3*共${chunks.size}个区块=${3*chunks.size}个开拓水晶",
"+====(输入/land进入领地主菜单)====+"
).forEach { player.prettyInfo(it) }
// player.prettyInfo("+========选择的范围信息========+[](br)" +
// "世界: &{#8cc269}" + LandSettings.worldAliases[pos.world.name] + "[](br)" +
// "点1: &{#8cc269}(${pos.x}, ${pos.z})[](br)" +
// "点2: &{#8cc269}(${p2.x}, ${p2.z})[](br)" +
// "范围花费: 每区块3*共${chunks.size}个区块=${3*chunks.size}个开拓水晶[](br)" +
// "+==(输入/land进入领地主菜单)==+")
}
}
e.isRightClickBlock() -> {
e.isCancelled = true
val pos = e.clickedBlock!!.location.chunk
pos2.computeIfAbsent(player.uniqueId) { pos }
if (pos1[player.uniqueId] == null) {
player.prettyInfo("+========选择的范围信息========+[](br)" +
"世界: &b" + LandSettings.worldAliases[pos.world.name] + "[](br)" +
"点2: &b(${pos.x}, ${pos.z})[](br)" +
"+===================================+")
listOf(
"+========选择的范围信息========+",
"世界: &{#8cc269}" + LandSettings.worldAliases[pos.world.name],
"点2: &{#8cc269}(${pos.x}, ${pos.z})",
"+===========================+"
).forEach { player.prettyInfo(it) }
// player.prettyInfo("+========选择的范围信息========+[](br)" +
// "世界: &{#8cc269}" + LandSettings.worldAliases[pos.world.name] + "[](br)" +
// "点2: &{#8cc269}(${pos.x}, ${pos.z})[](br)" +
// "+===================================+")
//"+==(输入/land进入领地主菜单)==+")
} else {
val p1 = pos1[player.uniqueId]!!
val chunks = ChunkUtils.getChunksInRectangle(pos.world, pos, p1)
player.prettyInfo("+========选择的范围信息========+[](br)" +
"世界: &b" + LandSettings.worldAliases[pos.world.name] + "[](br)" +
"点1: &b(${p1.x}, ${p1.z})[](br)" +
"点2: &b(${pos.x}, ${pos.z})[](br)" +
"范围花费: 每区块3*区块数${chunks.size}=${3*chunks.size}个开拓水晶[](br)" +
"+==(输入/land进入领地主菜单)==+")
listOf(
"+========选择的范围信息========+",
"世界: &{#8cc269}" + LandSettings.worldAliases[pos.world.name],
"点1: &{#8cc269}(${p1.x}, ${p1.z})",
"点2: &{#8cc269}(${pos.x}, ${pos.z})",
"范围花费: 每区块3*共${chunks.size}个区块=${3*chunks.size}个开拓水晶",
"+====(输入/land进入领地主菜单)====+"
).forEach { player.prettyInfo(it) }

// player.prettyInfo("+========选择的范围信息========+[](br)" +
// "世界: &{#8cc269}" + LandSettings.worldAliases[pos.world.name] + "[](br)" +
// "点1: &{#8cc269}(${p1.x}, ${p1.z})[](br)" +
// "点2: &{#8cc269}(${pos.x}, ${pos.z})[](br)" +
// "范围花费: 每区块3*区块数${chunks.size}=${3*chunks.size}个开拓水晶[](br)" +
// "+==(输入/land进入领地主菜单)==+")
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/main/kotlin/com/mcstarrysky/land/manager/LandManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,15 @@ object LandManager {
GsonComponentSerializer.gson()
.serialize(
GsonComponentSerializer.gson()
.deserialize(cacheMessageWithPrefix("抱歉, 你要准备 $crystalNeeds").toRawMessage())
.deserialize(cacheMessageWithPrefix("抱歉, 你要准备 $crystalNeeds ").toRawMessage())
.append(
LegacyComponentSerializer.legacyAmpersand().deserialize("&b开拓水晶")
.hoverEvent(com.mcstarrysky.land.Land.crystal.clone().asHoverEvent())
)
)
).append(cacheMessageWithPrefixColor(" 才能占领你选中的这 ${area.size} 个区块"))
.sendTo(adaptPlayer(player))
return
}

val centre = LocationUtils.calculateLandCenter(area, player.world)
Expand All @@ -163,7 +164,7 @@ object LandManager {
name,
area = area.toMutableList(),
tpLocation = centre,
cooperators = mutableListOf(),
// cooperators = mutableListOf(),
users = mutableMapOf()
)
for (perm in defaultFlags) {
Expand Down Expand Up @@ -206,7 +207,7 @@ object LandManager {
"${player.name} 的免费领地",
area = area.toMutableList(),
tpLocation = clickedLocation.add(0.0, 1.0, 0.0),
cooperators = mutableListOf(),
// cooperators = mutableListOf(),
users = mutableMapOf()
)
for (perm in defaultFlags) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/com/mcstarrysky/land/menu/LandFlagsMenu.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ object LandFlagsMenu {
fun openMenu(player: Player, land: Land, other: OfflinePlayer?, back: Consumer<Player>?) {
val title = if (other == null) "领地标记管理" else "${other.name} 的标记管理"
player.openMenu<PageableChest<Permission>>(title) {
virtualize()
// virtualize()

map(
"b======pn",
Expand Down Expand Up @@ -60,7 +60,7 @@ object LandFlagsMenu {
set('b', MenuRegistry.BACK) { back?.accept(player) }

onClick { event, flag ->
when (event.virtualEvent().clickType) {
when (event.clickEvent().click) {
ClickType.LEFT, ClickType.SHIFT_LEFT -> {
// 如果没设置, 就设置成默认值
if (land.getFlagValueOrNull(flag.id) == null) {
Expand Down
Loading

0 comments on commit a81f3cf

Please sign in to comment.