From e5f5ca4d7fad3a9c253e71b7a68fb1ed2092eda2 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Mon, 5 Jun 2023 14:39:42 +0100 Subject: [PATCH] Improved _example.yml, fixed slot conditions --- .../ecomenus/components/ConfigurableSlot.kt | 2 +- .../com/willfp/ecomenus/slots/SlotFunction.kt | 8 +++- .../src/main/resources/menus/_example.yml | 45 ++++++++++++++++--- 3 files changed, 47 insertions(+), 8 deletions(-) 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 b142ee3..183e64d 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 @@ -84,7 +84,7 @@ class ConfigurableSlot( action, plugin, context.with(section).with(typeName) - )?.toSlotAction() ?: continue + )?.toSlotAction(conditions) ?: continue onClick(clickType, function) } diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecomenus/slots/SlotFunction.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecomenus/slots/SlotFunction.kt index 8bb3a7e..345e2f7 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecomenus/slots/SlotFunction.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecomenus/slots/SlotFunction.kt @@ -3,11 +3,17 @@ package com.willfp.ecomenus.slots import com.willfp.eco.core.gui.menu.Menu import com.willfp.eco.core.gui.slot.Slot import com.willfp.ecomponent.SlotAction +import com.willfp.libreforge.EmptyProvidedHolder +import com.willfp.libreforge.conditions.ConditionList import org.bukkit.entity.Player import org.bukkit.event.inventory.InventoryClickEvent interface SlotFunction { fun execute(player: Player, event: InventoryClickEvent, slot: Slot, menu: Menu) - fun toSlotAction(): SlotAction = this::execute + fun toSlotAction(conditions: ConditionList): SlotAction = { player, event, slot, menu -> + if (conditions.areMet(player, EmptyProvidedHolder)) { + this.execute(player, event, slot, menu) + } + } } 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 3d78d49..6b8153d 100644 --- a/eco-core/core-plugin/src/main/resources/menus/_example.yml +++ b/eco-core/core-plugin/src/main/resources/menus/_example.yml @@ -35,15 +35,15 @@ forwards-arrow: item: arrow name:"&fNext Page" enabled: true location: - row: 3 - column: 6 + row: 6 + column: 8 backwards-arrow: item: arrow name:"&fPrevious Page" enabled: true location: - row: 3 - column: 4 + row: 6 + column: 2 pages: - page: 1 @@ -68,6 +68,18 @@ pages: - "210010012" - "211111112" - "211101112" + - page: 2 + mask: + items: + - gray_stained_glass_pane + - red_stained_glass_pane + pattern: + - "211101112" + - "211111112" + - "210000012" + - "210010012" + - "211111112" + - "211101112" slots: - item: barrier name:"&cClose" @@ -88,7 +100,7 @@ slots: conditions: [ ] # If the item should be shown if the conditions are not met - show-if-not-met: true + show-if-not-met: false left-click: - type: effects @@ -97,7 +109,7 @@ slots: args: message: "&cYou clicked the close button!" - - type: command + - type: close commands: [ ] - type: menu @@ -106,3 +118,24 @@ slots: - type: console_command commands: - "eco give %player% 100" + + - item: player_head head:%player% name:"&f%player%" + location: + row: 1 + column: 5 + page: 1 + + # Read https://plugins.auxilor.io/effects/configuring-a-condition + # The conditions required to click the item + conditions: [ ] + + # If the item should be shown if the conditions are not met + show-if-not-met: true + + left-click: + - type: menu + menu: other_example_menu + + - type: console_command + commands: + - "eco give %player% 100"