diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecomenus/components/ConfigurableSlot.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecomenus/components/ConfigurableSlot.kt index 69a0c3c..236041b 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecomenus/components/ConfigurableSlot.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecomenus/components/ConfigurableSlot.kt @@ -24,11 +24,12 @@ class ConfigurableSlot( ) : PositionedComponent { override val row: Int = config.getInt("location.row") override val column: Int = config.getInt("location.column") + val page: Int = config.getInt("location.page") override val layer = runCatching { enumValueOf(config.getString("layer")) } .getOrElse { MenuLayer.MIDDLE } - val context = baseContext.with("slot at row ${row}, column $column") + val context = baseContext.with("slot at row ${row}, column $column, page $page") private val conditions = Conditions.compile( config.getSubsections("conditions"), diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecomenus/components/PositionedComponent.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecomenus/components/PositionedComponent.kt index 20664b4..f7d43e6 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecomenus/components/PositionedComponent.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecomenus/components/PositionedComponent.kt @@ -3,6 +3,7 @@ package com.willfp.ecomenus.components import com.willfp.eco.core.gui.GUIComponent import com.willfp.eco.core.gui.menu.MenuBuilder import com.willfp.eco.core.gui.menu.MenuLayer +import com.willfp.eco.core.gui.page.PageBuilder interface PositionedComponent : GUIComponent { val row: Int @@ -23,11 +24,13 @@ interface PositionedComponent : GUIComponent { override fun getColumns() = columnSize } -fun MenuBuilder.addComponent( +// Little hack to prevent two identical methods +@Suppress("UNCHECKED_CAST") +fun T.addComponent( component: PositionedComponent -) = if (component.isEnabled) addComponent( +): T = if (component.isEnabled) addComponent( component.layer, component.row, component.column, component -) else this +) as T else this diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecomenus/components/impl/PositionedPageChanger.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecomenus/components/impl/PositionedPageChanger.kt index fd5efa8..541b416 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecomenus/components/impl/PositionedPageChanger.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecomenus/components/impl/PositionedPageChanger.kt @@ -2,6 +2,7 @@ package com.willfp.ecomenus.components.impl import com.willfp.eco.core.config.interfaces.Config import com.willfp.eco.core.gui.menu.Menu +import com.willfp.eco.core.gui.menu.MenuLayer import com.willfp.eco.core.gui.page.PageChanger import com.willfp.eco.core.items.Items import com.willfp.ecomenus.components.PositionedComponent @@ -18,6 +19,7 @@ class PositionedPageChanger( override val row: Int = config.getInt("location.row") override val column: Int = config.getInt("location.column") + override val layer = MenuLayer.TOP override val isEnabled = config.getBool("enabled") diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecomenus/menus/Menu.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecomenus/menus/Menu.kt index a44bfd3..445f431 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecomenus/menus/Menu.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecomenus/menus/Menu.kt @@ -37,15 +37,26 @@ fun Menu.close(player: Player) = this.previousMenus[player].popOrNull()?.open(player) ?: player.closeInventory() fun buildMenu(plugin: EcoPlugin, menu: EcoMenu, config: Config): Menu { - val mask = FillerMask( - MaskItems.fromItemNames(config.getStrings("mask.materials")), - *config.getStrings("mask.pattern").toTypedArray() - ) + val pageConfigs = config.getSubsections("pages") - return menu(mask.rows) { + val slots = mutableListOf() + + for (slotConfig in config.getSubsections("slots")) { + val slot = ConfigurableSlot( + plugin, + ViolationContext(plugin, "menu ${menu.id}"), + slotConfig + ) + + slots += slot + } + + return menu(config.getInt("rows")) { title = config.getFormattedString("title") - setMask(mask) + allowChangingHeldItem() + + maxPages(pageConfigs.size) addComponent( PositionedPageChanger( @@ -61,19 +72,26 @@ fun buildMenu(plugin: EcoPlugin, menu: EcoMenu, config: Config): Menu { ) ) - for (page in config.getSubsections("pages")) { - addPage(page.getInt("page")) { - for (slotConfig in config.getSubsections("slots")) { - val slot = ConfigurableSlot( - plugin, - ViolationContext(plugin, "menu ${menu.id}"), - slotConfig - ) + for (page in pageConfigs) { + val mask = FillerMask( + MaskItems.fromItemNames(page.getStrings("mask.items")), + *page.getStrings("mask.pattern").toTypedArray() + ) + + val pageNumber = page.getInt("page") + + addPage(pageNumber) { + setMask(mask) + + for (slot in slots) { + if (pageNumber != slot.page) { + continue + } try { - addComponent(slot) + this.addComponent(slot) } catch (e: Exception) { - slot.context.log(ConfigViolation("location", "The location of the slot is invalid!")) + slot.context.log(ConfigViolation("location", "Invalid location!")) } } } diff --git a/eco-core/core-plugin/src/main/resources/menus/_example.yml b/eco-core/core-plugin/src/main/resources/menus/_example.yml index a4786c6..2ee1c51 100644 --- a/eco-core/core-plugin/src/main/resources/menus/_example.yml +++ b/eco-core/core-plugin/src/main/resources/menus/_example.yml @@ -10,30 +10,8 @@ title: "Example GUI" # (Optional) The command to open the GUI, if not set, there will be no command. command: examplemenu -mask: - # The way the mask works is by having a list of materials - # And then a pattern to use those materials. - - # The size of the GUI is determined by the size of the mask. - - # The pattern is the rows in the GUI - # Each line must be 9 long, and the amount of rows should be the amount of rows in the GUI - # A zero represents nothing - # A 1 represents the first material - # A 2 represents the second material - # And so on, you can add up to 9. - - materials: - - gray_stained_glass_pane - - black_stained_glass_pane - pattern: - - "211101112" - - "211111112" - - "210000012" - - "210010012" - - "211111112" - - "211101112" - +# The size of the GUI, between 1 and 6 +rows: 6 # Read https://plugins.auxilor.io/effects/configuring-a-condition # The conditions required to open the GUI @@ -62,38 +40,62 @@ backwards-arrow: pages: - page: 1 - slots: - - item: barrier name:"&cClose" - lore: [ ] - location: - row: 6 - column: 5 - # (Optional) You can specify the layer of the slot. - # The layer can be any of: lower, middle, upper, or top (defaults to middle) - # This is useful if you want to have a slot on top of another slot, and - # have the upper slot show if some conditions are met. - layer: middle + mask: + # The way the mask works is by having a list of materials + # And then a pattern to use those materials. - # Read https://plugins.auxilor.io/effects/configuring-a-condition - # The conditions required to click the item - conditions: [ ] + # The pattern is the rows in the GUI + # Each line must be 9 long, and the amount of rows should be the amount of rows in the GUI + # A zero represents nothing + # A 1 represents the first material + # A 2 represents the second material + # And so on, you can add up to 9. - # If the item should be shown if the conditions are not met - show-if-not-met: true + items: + - gray_stained_glass_pane + - black_stained_glass_pane + pattern: + - "211101112" + - "211111112" + - "210000012" + - "210010012" + - "211111112" + - "211101112" - left-click: - - type: effects - effects: - - id: send_message - args: - message: "&cYou clicked the close button!" +slots: + - item: barrier name:"&cClose" + lore: [ ] + location: + row: 6 + column: 5 + page: 1 - - type: command - commands: [ ] + # (Optional) You can specify the layer of the slot. + # The layer can be any of: lower, middle, upper, or top (defaults to middle) + # This is useful if you want to have a slot on top of another slot, and + # have the upper slot show if some conditions are met. + layer: middle - - type: menu - menu: other_example_menu + # Read https://plugins.auxilor.io/effects/configuring-a-condition + # The conditions required to click the item + conditions: [ ] - - item: console_command - commands: - - "eco give %player% 100" + # If the item should be shown if the conditions are not met + show-if-not-met: true + + left-click: + - type: effects + effects: + - id: send_message + args: + message: "&cYou clicked the close button!" + + - type: command + commands: [ ] + + - type: menu + menu: other_example_menu + + - item: console_command + commands: + - "eco give %player% 100"