@ -5,6 +5,7 @@ import hazae41.minecraft.kutils.bukkit.keys
import org.bukkit.Bukkit
import org.bukkit.Bukkit
import org.bukkit.Material
import org.bukkit.Material
import org.bukkit.configuration.ConfigurationSection
import org.bukkit.configuration.ConfigurationSection
import org.bukkit.inventory.Inventory
import org.bukkit.inventory.ItemStack
import org.bukkit.inventory.ItemStack
import java.io.File
import java.io.File
@ -18,35 +19,35 @@ class MainConfig(file: File) : ConfigFile(file) {
var shops by section ( " shops " )
var shops by section ( " shops " )
var size by int ( " s tart GUI.size" )
var size by int ( " s hop GUI.size" )
var title by string ( " s tart GUI.title" )
var title by string ( " s hop GUI.title" )
var blocksRaw by section ( " shopGUI.blocks " )
var blocksRaw by section ( " shopGUI.blocks " )
val blocks = blocksRaw ?. keys
val blocks = blocksRaw ?. keys
?. map { blocksRaw !! . getConfigurationSection ( it ) }
?. map { blocksRaw !! . getConfigurationSection ( it ) }
?. map {
?. map {
Block (
Block (
it . asItem( ) ,
it . getConfigurationSection( " item " ) . asItem( ) ,
it . getInt ( " slot " ) ,
it . getInt ( " slot " ) ,
it . getStringList ( " commands " )
it . getStringList ( " commands " )
)
)
}
}
?: listOf ( )
?: listOf ( )
val inventory by lazy {
val inventory : Inventory = Bukkit . createInventory ( null , size , title . c ) . apply {
val inv = Bukkit . createInventory ( null , size , title . c )
blocks . forEach {
blocks . forEach {
inv . setItem ( it . slot , it . item )
println ( it )
setItem ( it . slot , it . item )
}
}
inv
}
}
}
}
fun ConfigurationSection . asItem ( ) : ItemStack {
fun ConfigurationSection . asItem ( ) : ItemStack {
val material = Material . valueOf ( getString ( " material " ) . toUpperCase ( ) )
val material = Material . valueOf ( getString ( " material " ) . toUpperCase ( ) )
val item = ItemStack ( material , getInt ( " quantity " , 1 ) , getInt ( " data " , 0 ) . toShort ( ) )
val item = ItemStack ( material , getInt ( " quantity " , 1 ) , getInt ( " data " , 0 ) . toShort ( ) )
item . itemMeta . apply {
displayName = getString ( " name " , " " )
item . itemMeta = item . itemMeta . apply {
displayName = getString ( " name " , " " ) . c
lore = getStringList ( " lore " ) . map { it . c }
lore = getStringList ( " lore " ) . map { it . c }
}
}
return item
return item