9
0
mirror of https://github.com/Auxilor/EcoMenus.git synced 2025-12-19 15:09:20 +00:00

Added dynamic items, open effects, and close effects

This commit is contained in:
Auxilor
2023-06-05 14:27:04 +01:00
parent 490f15b7d2
commit 25f2a62033
9 changed files with 53 additions and 29 deletions

View File

@@ -37,7 +37,7 @@ allprojects {
} }
dependencies { dependencies {
compileOnly("com.willfp:eco:6.63.0") compileOnly("com.willfp:eco:6.64.0")
compileOnly("org.jetbrains:annotations:23.0.0") compileOnly("org.jetbrains:annotations:23.0.0")
compileOnly("org.jetbrains.kotlin:kotlin-stdlib:1.7.10") compileOnly("org.jetbrains.kotlin:kotlin-stdlib:1.7.10")
} }

View File

@@ -20,7 +20,7 @@ class CommandForceOpen(plugin: EcoPlugin) : Subcommand(
menu.forceOpen(player) menu.forceOpen(player)
sender.sendMessage( sender.sendMessage(
plugin.langYml.getMessage("opened", StringUtils.FormatOption.WITHOUT_PLACEHOLDERS) plugin.langYml.getMessage("opened")
.replace("%player%", player.savedDisplayName) .replace("%player%", player.savedDisplayName)
.replace("%menu%", menu.id) .replace("%menu%", menu.id)
) )

View File

@@ -11,6 +11,8 @@ import com.willfp.eco.core.gui.slot
import com.willfp.eco.core.gui.slot.Slot import com.willfp.eco.core.gui.slot.Slot
import com.willfp.eco.core.items.Items import com.willfp.eco.core.items.Items
import com.willfp.eco.core.placeholder.context.placeholderContext import com.willfp.eco.core.placeholder.context.placeholderContext
import com.willfp.eco.core.placeholder.findPlaceholders
import com.willfp.eco.core.placeholder.translatePlaceholders
import com.willfp.ecomenus.slots.SlotTypes import com.willfp.ecomenus.slots.SlotTypes
import com.willfp.libreforge.ConfigViolation import com.willfp.libreforge.ConfigViolation
import com.willfp.libreforge.EmptyProvidedHolder import com.willfp.libreforge.EmptyProvidedHolder
@@ -40,10 +42,23 @@ class ConfigurableSlot(
private val showIfNotMet = config.getBool("show-if-not-met") private val showIfNotMet = config.getBool("show-if-not-met")
private val itemLookupString = config.getString("item")
private val isDynamicBaseItem = itemLookupString.findPlaceholders().isNotEmpty()
private val baseItem = Items.lookup(config.getString("item")).item private val baseItem = Items.lookup(config.getString("item")).item
private val slot = slot({ player, _ -> private val slot = slot({ player, _ ->
baseItem.clone().fast().apply { val item = if (isDynamicBaseItem) {
Items.lookup(
itemLookupString
.translatePlaceholders(placeholderContext(player = player))
).item
} else {
baseItem
}
item.clone().fast().apply {
if (config.has("lore")) { if (config.has("lore")) {
this.lore = config.getFormattedStrings( this.lore = config.getFormattedStrings(
"lore", placeholderContext( "lore", placeholderContext(

View File

@@ -8,6 +8,8 @@ import com.willfp.ecomenus.commands.DynamicMenuCommand
import com.willfp.libreforge.EmptyProvidedHolder import com.willfp.libreforge.EmptyProvidedHolder
import com.willfp.libreforge.ViolationContext import com.willfp.libreforge.ViolationContext
import com.willfp.libreforge.conditions.Conditions import com.willfp.libreforge.conditions.Conditions
import com.willfp.libreforge.effects.Effects
import com.willfp.libreforge.effects.executors.impl.NormalExecutorFactory
import org.bukkit.entity.Player import org.bukkit.entity.Player
class EcoMenu( class EcoMenu(
@@ -21,11 +23,23 @@ class EcoMenu(
private val conditions = Conditions.compile( private val conditions = Conditions.compile(
config.getSubsections("conditions"), config.getSubsections("conditions"),
ViolationContext(plugin, "Menu $id conditions") ViolationContext(plugin, "menu $id conditions")
) )
private val cannotOpenMessages = config.getFormattedStrings("cannot-open-messages") private val cannotOpenMessages = config.getFormattedStrings("cannot-open-messages")
private val openEffects = Effects.compileChain(
config.getSubsections("open-effects"),
NormalExecutorFactory.create(),
ViolationContext(plugin, "menu $id open effects")
)
private val closeEffects = Effects.compileChain(
config.getSubsections("close-effects"),
NormalExecutorFactory.create(),
ViolationContext(plugin, "menu $id close effects")
)
init { init {
if (commandName != null) { if (commandName != null) {
DynamicMenuCommand(plugin, this, commandName).register() DynamicMenuCommand(plugin, this, commandName).register()
@@ -45,5 +59,11 @@ class EcoMenu(
fun forceOpen(player: Player, parent: Menu? = null) { fun forceOpen(player: Player, parent: Menu? = null) {
menu.open(player, parent) menu.open(player, parent)
openEffects?.trigger(player)
}
fun handleClose(player: Player) {
closeEffects?.trigger(player)
menu.previousMenus[player].popOrNull()?.open(player)
} }
} }

View File

@@ -91,9 +91,8 @@ fun buildMenu(plugin: EcoPlugin, menu: EcoMenu, config: Config): Menu {
} }
} }
onClose { event, menu -> onClose { event, _ ->
val player = event.player as Player menu.handleClose(event.player as Player)
menu.previousMenus[player].popOrNull()?.open(player)
} }
} }
} }

View File

@@ -4,8 +4,8 @@ import com.willfp.eco.core.EcoPlugin
import com.willfp.eco.core.config.interfaces.Config import com.willfp.eco.core.config.interfaces.Config
import com.willfp.eco.core.gui.menu.Menu import com.willfp.eco.core.gui.menu.Menu
import com.willfp.eco.core.gui.slot.Slot import com.willfp.eco.core.gui.slot.Slot
import com.willfp.eco.core.integrations.placeholder.PlaceholderManager
import com.willfp.eco.core.placeholder.context.placeholderContext import com.willfp.eco.core.placeholder.context.placeholderContext
import com.willfp.eco.core.placeholder.translatePlaceholders
import com.willfp.ecomenus.slots.SlotFunction import com.willfp.ecomenus.slots.SlotFunction
import com.willfp.ecomenus.slots.SlotType import com.willfp.ecomenus.slots.SlotType
import com.willfp.libreforge.ViolationContext import com.willfp.libreforge.ViolationContext
@@ -30,10 +30,7 @@ class CommandSlotFunction(
for (command in commands) { for (command in commands) {
Bukkit.dispatchCommand( Bukkit.dispatchCommand(
sender ?: player, sender ?: player,
PlaceholderManager.translatePlaceholders( command.translatePlaceholders(placeholderContext(player = player))
command.replace("%player%", player.name),
placeholderContext(player = player)
)
) )
} }
} }

View File

@@ -32,21 +32,7 @@ object SlotTypeEffects : SlotType("effects") {
private val chain: Chain private val chain: Chain
) : SlotFunction { ) : SlotFunction {
override fun execute(player: Player, event: InventoryClickEvent, slot: Slot, menu: Menu) { override fun execute(player: Player, event: InventoryClickEvent, slot: Slot, menu: Menu) {
chain.trigger( chain.trigger(player)
DispatchedTrigger(
player,
TriggerClickSlot,
TriggerData(
player = player
)
)
)
} }
} }
private object TriggerClickSlot : Trigger("click_slot") {
override val parameters = setOf(
TriggerParameter.PLAYER
)
}
} }

View File

@@ -21,6 +21,13 @@ conditions: [ ]
cannot-open-messages: cannot-open-messages:
- "&cYou cannot open this menu!" - "&cYou cannot open this menu!"
# Read https://plugins.auxilor.io/effects/configuring-an-effect
# Effects to run when the GUI is opened
open-effects: [ ]
# Effects to run when the GUI is closed
close-effects: [ ]
# Options for the page arrows # Options for the page arrows
# If on the first page, the backwards arrow will not be shown, # If on the first page, the backwards arrow will not be shown,
# and if on the last page, the forwards arrow will not be shown. # and if on the last page, the forwards arrow will not be shown.

View File

@@ -1,5 +1,5 @@
#libreforge-updater #libreforge-updater
#Sat Jun 03 15:45:10 BST 2023 #Sat Jun 03 15:45:10 BST 2023
kotlin.code.style=official kotlin.code.style=official
libreforge-version=4.17.2 libreforge-version=4.18.0
version=0.0.1-ALPHA version=0.0.2-ALPHA