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