finalize
This commit is contained in:
parent
1c47e01048
commit
9b3ef2ea13
|
|
@ -2,7 +2,7 @@ plugins {
|
||||||
`java-library`
|
`java-library`
|
||||||
`maven-publish`
|
`maven-publish`
|
||||||
id("io.izzel.taboolib") version "1.42"
|
id("io.izzel.taboolib") version "1.42"
|
||||||
id("org.jetbrains.kotlin.jvm") version "1.5.10"
|
id("org.jetbrains.kotlin.jvm") version "1.7.10"
|
||||||
}
|
}
|
||||||
|
|
||||||
taboolib {
|
taboolib {
|
||||||
|
|
|
||||||
|
|
@ -8,18 +8,18 @@ import org.bukkit.entity.Player
|
||||||
import org.bukkit.inventory.Inventory
|
import org.bukkit.inventory.Inventory
|
||||||
import org.bukkit.inventory.ItemStack
|
import org.bukkit.inventory.ItemStack
|
||||||
import taboolib.library.xseries.XMaterial
|
import taboolib.library.xseries.XMaterial
|
||||||
import taboolib.module.ui.ClickType.*
|
import taboolib.module.ui.ClickType.CLICK
|
||||||
import taboolib.module.ui.buildMenu
|
import taboolib.module.ui.buildMenu
|
||||||
import taboolib.module.ui.type.Linked
|
import taboolib.module.ui.type.Linked
|
||||||
import taboolib.platform.util.asLangText
|
import taboolib.platform.util.asLangText
|
||||||
import taboolib.platform.util.buildItem
|
import taboolib.platform.util.buildItem
|
||||||
import taboolib.platform.util.sendLang
|
|
||||||
|
|
||||||
class ChunkInfoGUI(private val player: Player, private val centerChunk: Chunk) {
|
class ChunkInfoGUI(private val player: Player, private val centerChunk: Chunk) {
|
||||||
private var menu: Inventory = buildInventory()
|
private var menu: Inventory = buildInventory()
|
||||||
fun open() = player.openInventory(menu)
|
fun open() = player.openInventory(menu)
|
||||||
|
|
||||||
private fun buildInventory() = buildMenu<Linked<Chunk>>(player.asLangText("chunk_gui_claim_title")) {
|
private fun buildInventory() = buildMenu<Linked<Chunk>>(player.asLangText("chunk_gui_claim_title")) {
|
||||||
|
rows(6)
|
||||||
for (slot in 9..53) {
|
for (slot in 9..53) {
|
||||||
val chunkCoordinate = slot2ChunkCoordinate(slot)
|
val chunkCoordinate = slot2ChunkCoordinate(slot)
|
||||||
val chunk = centerChunk.world.getChunkAt(chunkCoordinate.first, chunkCoordinate.second)
|
val chunk = centerChunk.world.getChunkAt(chunkCoordinate.first, chunkCoordinate.second)
|
||||||
|
|
@ -51,7 +51,7 @@ class ChunkInfoGUI(private val player: Player, private val centerChunk: Chunk) {
|
||||||
|
|
||||||
private fun slot2ChunkCoordinate(slot: Int): Pair<Int, Int> {
|
private fun slot2ChunkCoordinate(slot: Int): Pair<Int, Int> {
|
||||||
val offset = slot - 31
|
val offset = slot - 31
|
||||||
if (offset == 0) return 3 to 3
|
if (offset == 0) return centerChunk.x to centerChunk.z
|
||||||
return centerChunk.x + (slot / 9) to centerChunk.z + (slot % 9)
|
return centerChunk.x + (slot / 9) to centerChunk.z + (slot % 9)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,17 +6,19 @@ import org.bukkit.Location
|
||||||
import org.bukkit.OfflinePlayer
|
import org.bukkit.OfflinePlayer
|
||||||
import org.bukkit.configuration.serialization.ConfigurationSerializable
|
import org.bukkit.configuration.serialization.ConfigurationSerializable
|
||||||
import org.bukkit.configuration.serialization.SerializableAs
|
import org.bukkit.configuration.serialization.SerializableAs
|
||||||
|
import taboolib.module.configuration.ConfigSection
|
||||||
|
import taboolib.module.configuration.util.getLocation
|
||||||
|
import taboolib.platform.util.toBukkitLocation
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
@SerializableAs("ChunkLoader")
|
data class ChunkLoader(val owner: OfflinePlayer, val chunk: Chunk) {
|
||||||
data class ChunkLoader(val owner: OfflinePlayer, val chunk: Chunk) : ConfigurationSerializable {
|
|
||||||
|
|
||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
constructor(map: Map<String, Any>) : this(
|
constructor(map: ConfigSection) : this(
|
||||||
Bukkit.getOfflinePlayer(UUID.fromString(map["owner"] as String)), (map["chunk"] as Location).chunk
|
Bukkit.getOfflinePlayer(UUID.fromString(map["owner"] as String)), map.getLocation("chunk")!!.toBukkitLocation().chunk
|
||||||
)
|
)
|
||||||
|
|
||||||
override fun serialize(): MutableMap<String, Any> = hashMapOf(
|
fun serialize(): MutableMap<String, Any> = hashMapOf(
|
||||||
"owner" to owner.uniqueId, "chunk" to chunk.getBlock(0, 0, 0).location
|
"owner" to owner.uniqueId, "chunk" to chunk.getBlock(0, 0, 0).location
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,14 +3,25 @@ package cc.maxmc.chunkloader.misc
|
||||||
import cc.maxmc.chunkloader.provider.ClaimProviderManager
|
import cc.maxmc.chunkloader.provider.ClaimProviderManager
|
||||||
import org.bukkit.Chunk
|
import org.bukkit.Chunk
|
||||||
import org.bukkit.entity.Player
|
import org.bukkit.entity.Player
|
||||||
|
import taboolib.common.LifeCycle
|
||||||
|
import taboolib.common.platform.SkipTo
|
||||||
import taboolib.common.platform.function.getDataFolder
|
import taboolib.common.platform.function.getDataFolder
|
||||||
|
import taboolib.module.configuration.ConfigSection
|
||||||
import taboolib.module.configuration.Configuration
|
import taboolib.module.configuration.Configuration
|
||||||
import taboolib.platform.util.sendLang
|
import taboolib.platform.util.sendLang
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
|
@SkipTo(LifeCycle.ACTIVE)
|
||||||
object ChunkLoaderManager {
|
object ChunkLoaderManager {
|
||||||
val loaderMap = HashMap<Chunk, ChunkLoader>()
|
val loaderMap = HashMap<Chunk, ChunkLoader>()
|
||||||
private val config = Configuration.loadFromFile(File(getDataFolder(), "loaders.yaml"))
|
private val storage by lazy {
|
||||||
|
val loaderFile = File(getDataFolder(), "loaders.yaml")
|
||||||
|
if (!loaderFile.exists()) {
|
||||||
|
loaderFile.parentFile.mkdirs()
|
||||||
|
loaderFile.createNewFile()
|
||||||
|
}
|
||||||
|
Configuration.loadFromFile(loaderFile)
|
||||||
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
loadChunkLoaders()
|
loadChunkLoaders()
|
||||||
|
|
@ -18,8 +29,8 @@ object ChunkLoaderManager {
|
||||||
|
|
||||||
private fun loadChunkLoaders() {
|
private fun loadChunkLoaders() {
|
||||||
@Suppress("UNCHECKED_CAST") val loaders =
|
@Suppress("UNCHECKED_CAST") val loaders =
|
||||||
config.getList("loaders", emptyList<ChunkLoader>()) as List<ChunkLoader>
|
storage.getList("loaders", emptyList<ConfigSection>()) as List<ConfigSection>
|
||||||
loaders.forEach {
|
loaders.map { ChunkLoader(it) }.forEach {
|
||||||
loaderMap[it.chunk] = it
|
loaderMap[it.chunk] = it
|
||||||
it.enable()
|
it.enable()
|
||||||
}
|
}
|
||||||
|
|
@ -27,14 +38,18 @@ object ChunkLoaderManager {
|
||||||
|
|
||||||
private fun registerChunkLoader(chunkLoader: ChunkLoader) {
|
private fun registerChunkLoader(chunkLoader: ChunkLoader) {
|
||||||
loaderMap[chunkLoader.chunk] = chunkLoader
|
loaderMap[chunkLoader.chunk] = chunkLoader
|
||||||
config["loaders"] = loaderMap.values.toList()
|
storage["loaders"] = loaderMap.values.toList().map {
|
||||||
config.saveToFile()
|
it.serialize()
|
||||||
|
}
|
||||||
|
storage.saveToFile()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun unregisterChunkLoader(chunkLoader: ChunkLoader) {
|
private fun unregisterChunkLoader(chunkLoader: ChunkLoader) {
|
||||||
loaderMap.remove(chunkLoader.chunk)
|
loaderMap.remove(chunkLoader.chunk)
|
||||||
config["loaders"] = loaderMap.values.toList()
|
storage["loaders"] = loaderMap.values.toList().map {
|
||||||
config.saveToFile()
|
it.serialize()
|
||||||
|
}
|
||||||
|
storage.saveToFile()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun tryClaimChunk(player: Player, chunk: Chunk) {
|
fun tryClaimChunk(player: Player, chunk: Chunk) {
|
||||||
|
|
@ -70,6 +85,7 @@ object ChunkLoaderManager {
|
||||||
if (loader.owner != player && !player.isOp && !player.hasPermission("chunk_loader.disclaim_force")) {
|
if (loader.owner != player && !player.isOp && !player.hasPermission("chunk_loader.disclaim_force")) {
|
||||||
return player.sendLang("chunk_disclaim_others")
|
return player.sendLang("chunk_disclaim_others")
|
||||||
}
|
}
|
||||||
|
loader.disable()
|
||||||
unregisterChunkLoader(loader)
|
unregisterChunkLoader(loader)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,4 +4,4 @@ chunk_claim_success: "§a| §7成功加载位于 §a{0} 的区块 (§6{1}/{2}§7
|
||||||
chunk_claim_reach_max: "§e| §7您加载的区块达到上限."
|
chunk_claim_reach_max: "§e| §7您加载的区块达到上限."
|
||||||
chunk_disclaim_system: "§c| §7该区块未被认领或为默认强加载区块,您无法取消加载."
|
chunk_disclaim_system: "§c| §7该区块未被认领或为默认强加载区块,您无法取消加载."
|
||||||
chunk_disclaim_others: "§c| §7该区块为 §c{0} 所加载, 您无法取消加载"
|
chunk_disclaim_others: "§c| §7该区块为 §c{0} 所加载, 您无法取消加载"
|
||||||
chunk_gui_claim_title: "§a| §7查看区块信息"
|
chunk_gui_claim_title: "§a| §f查看区块信息"
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
loaders:
|
||||||
Loading…
Reference in New Issue