mirror of
https://github.com/Auxilor/EcoMenus.git
synced 2025-12-19 15:09:20 +00:00
Added pagination
This commit is contained in:
@@ -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<MenuLayer>(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"),
|
||||
|
||||
@@ -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 : PageBuilder> 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
|
||||
|
||||
@@ -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")
|
||||
|
||||
|
||||
@@ -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<ConfigurableSlot>()
|
||||
|
||||
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!"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user