53 lines
1.5 KiB
Kotlin
53 lines
1.5 KiB
Kotlin
package pw.hamzantal.shopreborn
|
|
|
|
import hazae41.minecraft.kutils.bukkit.ConfigFile
|
|
import hazae41.minecraft.kutils.bukkit.keys
|
|
import org.bukkit.Bukkit
|
|
import org.bukkit.Material
|
|
import org.bukkit.configuration.ConfigurationSection
|
|
import org.bukkit.inventory.ItemStack
|
|
import java.io.File
|
|
|
|
object Configurations {
|
|
lateinit var main: MainConfig
|
|
val shops = mutableListOf<ConfigFile>()
|
|
}
|
|
|
|
class MainConfig(file: File) : ConfigFile(file) {
|
|
data class Block(val item: ItemStack, val slot: Int, val commands: List<String>)
|
|
|
|
var shops by section("shops")
|
|
|
|
var size by int("startGUI.size")
|
|
var title by string("startGUI.title")
|
|
var blocksRaw by section("shopGUI.blocks")
|
|
|
|
val blocks = blocksRaw?.keys
|
|
?.map { blocksRaw!!.getConfigurationSection(it) }
|
|
?.map {
|
|
Block(
|
|
it.asItem(),
|
|
it.getInt("slot"),
|
|
it.getStringList("commands")
|
|
)
|
|
}
|
|
?: listOf()
|
|
|
|
val inventory by lazy {
|
|
val inv = Bukkit.createInventory(null, size, title.c)
|
|
blocks.forEach {
|
|
inv.setItem(it.slot, it.item)
|
|
}
|
|
inv
|
|
}
|
|
}
|
|
|
|
fun ConfigurationSection.asItem(): ItemStack {
|
|
val material = Material.valueOf(getString("material").toUpperCase())
|
|
val item = ItemStack(material, getInt("quantity", 1), getInt("data", 0).toShort())
|
|
item.itemMeta.apply {
|
|
displayName = getString("name", "")
|
|
lore = getStringList("lore").map { it.c }
|
|
}
|
|
return item
|
|
} |