finalize
This commit is contained in:
parent
f7b026bf8e
commit
1c47e01048
|
|
@ -1,5 +1,6 @@
|
|||
package cc.maxmc.chunkloader
|
||||
|
||||
import cc.maxmc.chunkloader.command.CommandOpenGUI
|
||||
import cc.maxmc.chunkloader.misc.ChunkLoaderManager
|
||||
import taboolib.common.platform.Plugin
|
||||
import taboolib.common.platform.function.info
|
||||
|
|
@ -7,7 +8,9 @@ import taboolib.common.platform.function.info
|
|||
object SimpleChunkLoader : Plugin() {
|
||||
|
||||
override fun onEnable() {
|
||||
info("")
|
||||
info("§a| §7Loading simple chunk loader.")
|
||||
ChunkLoaderManager
|
||||
CommandOpenGUI
|
||||
info("§a| §7Simple chunk loader loaded successfully.")
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
package cc.maxmc.chunkloader.command
|
||||
|
||||
import cc.maxmc.chunkloader.gui.ChunkInfoGUI
|
||||
import org.bukkit.entity.Player
|
||||
import taboolib.common.platform.command.command
|
||||
|
||||
object CommandOpenGUI {
|
||||
init {
|
||||
commandGUI()
|
||||
}
|
||||
|
||||
private fun commandGUI() = command("chunkloader") {
|
||||
execute<Player> { sender, _, _ ->
|
||||
ChunkInfoGUI(sender, sender.location.chunk).open()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -11,10 +11,15 @@ import taboolib.library.xseries.XMaterial
|
|||
import taboolib.module.ui.ClickType.*
|
||||
import taboolib.module.ui.buildMenu
|
||||
import taboolib.module.ui.type.Linked
|
||||
import taboolib.platform.util.asLangText
|
||||
import taboolib.platform.util.buildItem
|
||||
import taboolib.platform.util.sendLang
|
||||
|
||||
class ChunkInfoGUI(private val player: Player, private val centerChunk: Chunk) {
|
||||
val menu: Inventory = buildMenu<Linked<Chunk>>("§a| §7查看区块信息") {
|
||||
private var menu: Inventory = buildInventory()
|
||||
fun open() = player.openInventory(menu)
|
||||
|
||||
private fun buildInventory() = buildMenu<Linked<Chunk>>(player.asLangText("chunk_gui_claim_title")) {
|
||||
for (slot in 9..53) {
|
||||
val chunkCoordinate = slot2ChunkCoordinate(slot)
|
||||
val chunk = centerChunk.world.getChunkAt(chunkCoordinate.first, chunkCoordinate.second)
|
||||
|
|
@ -23,10 +28,12 @@ class ChunkInfoGUI(private val player: Player, private val centerChunk: Chunk) {
|
|||
assert(clickType == CLICK)
|
||||
if (clickEvent().click.isLeftClick) {
|
||||
ChunkLoaderManager.tryClaimChunk(player, chunk)
|
||||
updateInventory()
|
||||
return@set
|
||||
}
|
||||
if (clickEvent().click.isRightClick) {
|
||||
|
||||
ChunkLoaderManager.tryDisclaimChunk(player, chunk)
|
||||
updateInventory()
|
||||
return@set
|
||||
}
|
||||
player.sendMessage("喵喵喵?")
|
||||
|
|
@ -34,6 +41,11 @@ class ChunkInfoGUI(private val player: Player, private val centerChunk: Chunk) {
|
|||
}
|
||||
}
|
||||
|
||||
private fun updateInventory() {
|
||||
menu = buildInventory()
|
||||
player.openInventory(menu)
|
||||
}
|
||||
|
||||
private fun chunkCoordinate2Slot(coordinate: Pair<Int, Int>) =
|
||||
31 + (coordinate.second - centerChunk.z) * 9 + (coordinate.first - centerChunk.x)
|
||||
|
||||
|
|
|
|||
|
|
@ -31,6 +31,12 @@ object ChunkLoaderManager {
|
|||
config.saveToFile()
|
||||
}
|
||||
|
||||
private fun unregisterChunkLoader(chunkLoader: ChunkLoader) {
|
||||
loaderMap.remove(chunkLoader.chunk)
|
||||
config["loaders"] = loaderMap.values.toList()
|
||||
config.saveToFile()
|
||||
}
|
||||
|
||||
fun tryClaimChunk(player: Player, chunk: Chunk) {
|
||||
val type = chunk.type()
|
||||
if (type == ChunkType.SYSTEM) {
|
||||
|
|
@ -61,12 +67,13 @@ object ChunkLoaderManager {
|
|||
if (chunk.type() != ChunkType.CLAIMED) return player.sendLang("chunk_disclaim_system")
|
||||
|
||||
val loader = loaderMap[chunk]!!
|
||||
if (loader.owner != player) {
|
||||
if (player.isOp || player.hasPermission("chunk_loader.disclaim_force")) return player.sendLang("chunk_disclaim_others")
|
||||
if (loader.owner != player && !player.isOp && !player.hasPermission("chunk_loader.disclaim_force")) {
|
||||
return player.sendLang("chunk_disclaim_others")
|
||||
}
|
||||
unregisterChunkLoader(loader)
|
||||
}
|
||||
|
||||
fun calculateRemainClaims(player: Player): Int {
|
||||
private fun calculateRemainClaims(player: Player): Int {
|
||||
val maxPermCount = ClaimProviderManager.calculateTotalClaims(player)
|
||||
val used = calculateUsedClaims(player)
|
||||
|
||||
|
|
@ -75,7 +82,7 @@ object ChunkLoaderManager {
|
|||
return maxPermCount - used
|
||||
}
|
||||
|
||||
fun calculateUsedClaims(player: Player) =
|
||||
private fun calculateUsedClaims(player: Player) =
|
||||
loaderMap.filter { (_, loader) -> loader.owner.uniqueId == player.uniqueId }.size
|
||||
|
||||
fun Chunk.type(): ChunkType {
|
||||
|
|
|
|||
|
|
@ -4,3 +4,4 @@ chunk_claim_success: "§a| §7成功加载位于 §a{0} 的区块 (§6{1}/{2}§7
|
|||
chunk_claim_reach_max: "§e| §7您加载的区块达到上限."
|
||||
chunk_disclaim_system: "§c| §7该区块未被认领或为默认强加载区块,您无法取消加载."
|
||||
chunk_disclaim_others: "§c| §7该区块为 §c{0} 所加载, 您无法取消加载"
|
||||
chunk_gui_claim_title: "§a| §7查看区块信息"
|
||||
Loading…
Reference in New Issue