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:
@@ -37,7 +37,7 @@ allprojects {
|
||||
}
|
||||
|
||||
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.kotlin:kotlin-stdlib:1.7.10")
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ class CommandForceOpen(plugin: EcoPlugin) : Subcommand(
|
||||
|
||||
menu.forceOpen(player)
|
||||
sender.sendMessage(
|
||||
plugin.langYml.getMessage("opened", StringUtils.FormatOption.WITHOUT_PLACEHOLDERS)
|
||||
plugin.langYml.getMessage("opened")
|
||||
.replace("%player%", player.savedDisplayName)
|
||||
.replace("%menu%", menu.id)
|
||||
)
|
||||
|
||||
@@ -11,6 +11,8 @@ import com.willfp.eco.core.gui.slot
|
||||
import com.willfp.eco.core.gui.slot.Slot
|
||||
import com.willfp.eco.core.items.Items
|
||||
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.libreforge.ConfigViolation
|
||||
import com.willfp.libreforge.EmptyProvidedHolder
|
||||
@@ -40,10 +42,23 @@ class ConfigurableSlot(
|
||||
|
||||
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 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")) {
|
||||
this.lore = config.getFormattedStrings(
|
||||
"lore", placeholderContext(
|
||||
|
||||
@@ -8,6 +8,8 @@ import com.willfp.ecomenus.commands.DynamicMenuCommand
|
||||
import com.willfp.libreforge.EmptyProvidedHolder
|
||||
import com.willfp.libreforge.ViolationContext
|
||||
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
|
||||
|
||||
class EcoMenu(
|
||||
@@ -21,11 +23,23 @@ class EcoMenu(
|
||||
|
||||
private val conditions = Conditions.compile(
|
||||
config.getSubsections("conditions"),
|
||||
ViolationContext(plugin, "Menu $id conditions")
|
||||
ViolationContext(plugin, "menu $id conditions")
|
||||
)
|
||||
|
||||
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 {
|
||||
if (commandName != null) {
|
||||
DynamicMenuCommand(plugin, this, commandName).register()
|
||||
@@ -45,5 +59,11 @@ class EcoMenu(
|
||||
|
||||
fun forceOpen(player: Player, parent: Menu? = null) {
|
||||
menu.open(player, parent)
|
||||
openEffects?.trigger(player)
|
||||
}
|
||||
|
||||
fun handleClose(player: Player) {
|
||||
closeEffects?.trigger(player)
|
||||
menu.previousMenus[player].popOrNull()?.open(player)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,9 +91,8 @@ fun buildMenu(plugin: EcoPlugin, menu: EcoMenu, config: Config): Menu {
|
||||
}
|
||||
}
|
||||
|
||||
onClose { event, menu ->
|
||||
val player = event.player as Player
|
||||
menu.previousMenus[player].popOrNull()?.open(player)
|
||||
onClose { event, _ ->
|
||||
menu.handleClose(event.player as Player)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,8 +4,8 @@ import com.willfp.eco.core.EcoPlugin
|
||||
import com.willfp.eco.core.config.interfaces.Config
|
||||
import com.willfp.eco.core.gui.menu.Menu
|
||||
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.translatePlaceholders
|
||||
import com.willfp.ecomenus.slots.SlotFunction
|
||||
import com.willfp.ecomenus.slots.SlotType
|
||||
import com.willfp.libreforge.ViolationContext
|
||||
@@ -30,10 +30,7 @@ class CommandSlotFunction(
|
||||
for (command in commands) {
|
||||
Bukkit.dispatchCommand(
|
||||
sender ?: player,
|
||||
PlaceholderManager.translatePlaceholders(
|
||||
command.replace("%player%", player.name),
|
||||
placeholderContext(player = player)
|
||||
)
|
||||
command.translatePlaceholders(placeholderContext(player = player))
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,21 +32,7 @@ object SlotTypeEffects : SlotType("effects") {
|
||||
private val chain: Chain
|
||||
) : SlotFunction {
|
||||
override fun execute(player: Player, event: InventoryClickEvent, slot: Slot, menu: Menu) {
|
||||
chain.trigger(
|
||||
DispatchedTrigger(
|
||||
player,
|
||||
TriggerClickSlot,
|
||||
TriggerData(
|
||||
player = player
|
||||
)
|
||||
)
|
||||
)
|
||||
chain.trigger(player)
|
||||
}
|
||||
}
|
||||
|
||||
private object TriggerClickSlot : Trigger("click_slot") {
|
||||
override val parameters = setOf(
|
||||
TriggerParameter.PLAYER
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,13 @@ conditions: [ ]
|
||||
cannot-open-messages:
|
||||
- "&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
|
||||
# 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.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#libreforge-updater
|
||||
#Sat Jun 03 15:45:10 BST 2023
|
||||
kotlin.code.style=official
|
||||
libreforge-version=4.17.2
|
||||
version=0.0.1-ALPHA
|
||||
libreforge-version=4.18.0
|
||||
version=0.0.2-ALPHA
|
||||
Reference in New Issue
Block a user