Fixed several effect bugs
This commit is contained in:
@@ -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))
|
||||
|
||||
@@ -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<Chain>
|
||||
private lateinit var denyEffects: Optional<Chain>
|
||||
|
||||
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
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user