@ -9,7 +9,8 @@ import org.bukkit.configuration.ConfigurationSection
import org.bukkit.inventory.Inventory
import org.bukkit.inventory.Inventory
import org.bukkit.inventory.ItemStack
import org.bukkit.inventory.ItemStack
import java.io.File
import java.io.File
import java.lang.IllegalArgumentException
import kotlin.math.ceil
import kotlin.math.max
object Configurations {
object Configurations {
var dataFolder = File ( " " )
var dataFolder = File ( " " )
@ -94,7 +95,7 @@ class ShopConfig(val name: String, file: File) : ConfigFile(file) {
}
}
val title by string ( " name " , " &a $name " )
val title by string ( " name " , " &a $name " )
val size by int ( " size " , 9 )
val size by int ( " size " , 18 )
val menuRow by int ( " buttons.menuRow " , - 1 )
val menuRow by int ( " buttons.menuRow " , - 1 )
val blocksRaw by section ( " items " )
val blocksRaw by section ( " items " )
@ -123,9 +124,22 @@ class ShopConfig(val name: String, file: File) : ConfigFile(file) {
}
}
?: listOf ( )
?: listOf ( )
val inventory : Inventory = Bukkit . createInventory ( null , size , title . c ) . apply {
val pages = ceil ( blocks . size . toDouble ( ) / ( size - 9 ) . toDouble ( ) ) . toInt ( )
//Set Single Row Menu
val inventories = mutableListOf < Inventory > ( )
if ( menuRow != - 1 ) {
val inventory : Inventory
init {
inventory = makeInventory ( size , title , menuRow , blocks , 1 )
inventories += inventory
for ( i in 2. . pages ) {
inventories += makeInventory ( size , title , menuRow , blocks , i )
}
}
}
fun makeInventory ( size : Int , title : String , menuRow : Int = - 1 , items : List < ShopConfig . Block > , page : Int ) : Inventory {
return Bukkit . createInventory ( null , size , title . c ) . apply {
if ( menuRow > 0 ) {
val buttons = Configurations . main . buttons
val buttons = Configurations . main . buttons
for ( i in menuRow until menuRow + 9 ) {
for ( i in menuRow until menuRow + 9 ) {
setItem ( i , buttons . pane )
setItem ( i , buttons . pane )
@ -135,15 +149,17 @@ class ShopConfig(val name: String, file: File) : ConfigFile(file) {
setItem ( menuRow + 8 , buttons . forward )
setItem ( menuRow + 8 , buttons . forward )
}
}
blocks . forEach {
val dropping = ( page - 1 ) * ( size - max ( 0 , menuRow ) )
setItem ( firstEmpty ( ) , it . item )
items . drop ( dropping ) . forEach {
if ( firstEmpty ( ) != - 1 ) setItem ( firstEmpty ( ) , it . item )
else return @apply
}
}
}
}
}
}
fun ConfigurationSection . asItem ( buy : Int = - 1 , sell : Int = - 1 ) : ItemStack {
fun ConfigurationSection . asItem ( buy : Int = - 1 , sell : Int = - 1 ) : ItemStack {
val material = Material . valueOf ( getString ( " material " ) . toUpperCase ( ) )
val material = Material . valueOf ( getString ( " material " ) . toUpperCase ( ) )
val item = ItemStack ( material , getInt ( " quantity " , 1 ) , getInt ( " da ta " , 0 ) . toShort ( ) )
val item = ItemStack ( material , getInt ( " quantity " , 1 ) , getInt ( " da mage " , 0 ) . toShort ( ) )
item . itemMeta = item . itemMeta . apply {
item . itemMeta = item . itemMeta . apply {
displayName = getString ( " name " , " " ) . c
displayName = getString ( " name " , " " ) . c