From 3fe0a8071dda4976d85237c7f7084f4f8bce4507 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Wed, 17 Jul 2024 16:09:39 +0100 Subject: [PATCH] Fixed several effect bugs --- .../willfp/ecoscrolls/gui/InscriptionTable.kt | 8 +++---- .../ecoscrolls/scrolls/InscriptionHandler.kt | 22 ++++++++++++------- .../com/willfp/ecoscrolls/scrolls/Scroll.kt | 4 ++-- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoscrolls/gui/InscriptionTable.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoscrolls/gui/InscriptionTable.kt index 35600fc..d87e578 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoscrolls/gui/InscriptionTable.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoscrolls/gui/InscriptionTable.kt @@ -58,12 +58,12 @@ internal fun updateInscribeMenu(plugin: EcoScrollsPlugin) { val violationContext = ViolationContext(plugin, "Inscription Table") - val openEffects = Effects.compile( + val openEffects = Effects.compileChain( plugin.configYml.getSubsections("gui.open-effects"), violationContext.with("Open Effects") ) - val closeEffects = Effects.compile( + val closeEffects = Effects.compileChain( plugin.configYml.getSubsections("gui.close-effects"), violationContext.with("Close Effects") ) @@ -139,13 +139,13 @@ internal fun updateInscribeMenu(plugin: EcoScrollsPlugin) { } onOpen { player, _ -> - openEffects.trigger(TriggerData(player = player).dispatch(player.toDispatcher())) + openEffects?.trigger(TriggerData(player = player).dispatch(player.toDispatcher())) } onClose { event, menu -> val player = event.player as Player - closeEffects.trigger(TriggerData(player = player).dispatch(player.toDispatcher())) + closeEffects?.trigger(TriggerData(player = player).dispatch(player.toDispatcher())) DropQueue(player) .addItems(menu.getCaptiveItems(player)) diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoscrolls/scrolls/InscriptionHandler.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoscrolls/scrolls/InscriptionHandler.kt index 963c4a2..db721eb 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoscrolls/scrolls/InscriptionHandler.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoscrolls/scrolls/InscriptionHandler.kt @@ -5,16 +5,18 @@ import com.willfp.ecoscrolls.scrolls.event.ScrollInscribeEvent import com.willfp.ecoscrolls.scrolls.event.ScrollTryInscribeEvent import com.willfp.libreforge.NamedValue import com.willfp.libreforge.ViolationContext +import com.willfp.libreforge.effects.Chain import com.willfp.libreforge.effects.EffectList import com.willfp.libreforge.effects.Effects import com.willfp.libreforge.toDispatcher import com.willfp.libreforge.triggers.TriggerData import org.bukkit.entity.Player import org.bukkit.inventory.ItemStack +import java.util.Optional class InscriptionHandler(private val plugin: EcoScrollsPlugin) { - private lateinit var applyEffects: EffectList - private lateinit var denyEffects: EffectList + private lateinit var applyEffects: Optional + private lateinit var denyEffects: Optional val scrollLimit = plugin.configYml.getInt("inscription.scroll-limit") .let { if (it <= 0) Int.MAX_VALUE else it } @@ -22,15 +24,15 @@ class InscriptionHandler(private val plugin: EcoScrollsPlugin) { internal fun reload() { val context = ViolationContext(plugin, "Inscriptions") - applyEffects = Effects.compile( + applyEffects = Optional.ofNullable(Effects.compileChain( plugin.configYml.getSubsections("inscription.apply-effects"), context.with("Apply Effects") - ) + )) - denyEffects = Effects.compile( + denyEffects = Optional.ofNullable(Effects.compileChain( plugin.configYml.getSubsections("inscription.deny-effects"), context.with("Deny Effects") - ) + )) } private fun inscriptionTrigger(item: ItemStack, scroll: Scroll, player: Player) = @@ -72,12 +74,16 @@ class InscriptionHandler(private val plugin: EcoScrollsPlugin) { val didInscribe = scroll.inscribe(item, player) if (didInscribe) { - applyEffects.trigger(inscriptionTrigger(item, scroll, player)) + applyEffects.ifPresent { + it.trigger(inscriptionTrigger(item, scroll, player)) + } val event = ScrollInscribeEvent(player, scroll, item) plugin.server.pluginManager.callEvent(event) } else { - denyEffects.trigger(inscriptionTrigger(item, scroll, player)) + denyEffects.ifPresent { + it.trigger(inscriptionTrigger(item, scroll, player)) + } } return didInscribe diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoscrolls/scrolls/Scroll.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoscrolls/scrolls/Scroll.kt index ec92d4f..0182515 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoscrolls/scrolls/Scroll.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoscrolls/scrolls/Scroll.kt @@ -97,7 +97,7 @@ class Scroll( context.with("inscription conditions") ) - private val inscriptionEffects = Effects.compile( + private val inscriptionEffects = Effects.compileChain( config.getSubsections("inscription.effects"), context.with("inscription effects") ) @@ -230,7 +230,7 @@ class Scroll( inscribe(itemStack) - inscriptionEffects.trigger( + inscriptionEffects?.trigger( TriggerData( player = player, item = itemStack,