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 violationContext = ViolationContext(plugin, "Inscription Table")
|
||||||
|
|
||||||
val openEffects = Effects.compile(
|
val openEffects = Effects.compileChain(
|
||||||
plugin.configYml.getSubsections("gui.open-effects"),
|
plugin.configYml.getSubsections("gui.open-effects"),
|
||||||
violationContext.with("Open Effects")
|
violationContext.with("Open Effects")
|
||||||
)
|
)
|
||||||
|
|
||||||
val closeEffects = Effects.compile(
|
val closeEffects = Effects.compileChain(
|
||||||
plugin.configYml.getSubsections("gui.close-effects"),
|
plugin.configYml.getSubsections("gui.close-effects"),
|
||||||
violationContext.with("Close Effects")
|
violationContext.with("Close Effects")
|
||||||
)
|
)
|
||||||
@@ -139,13 +139,13 @@ internal fun updateInscribeMenu(plugin: EcoScrollsPlugin) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onOpen { player, _ ->
|
onOpen { player, _ ->
|
||||||
openEffects.trigger(TriggerData(player = player).dispatch(player.toDispatcher()))
|
openEffects?.trigger(TriggerData(player = player).dispatch(player.toDispatcher()))
|
||||||
}
|
}
|
||||||
|
|
||||||
onClose { event, menu ->
|
onClose { event, menu ->
|
||||||
val player = event.player as Player
|
val player = event.player as Player
|
||||||
|
|
||||||
closeEffects.trigger(TriggerData(player = player).dispatch(player.toDispatcher()))
|
closeEffects?.trigger(TriggerData(player = player).dispatch(player.toDispatcher()))
|
||||||
|
|
||||||
DropQueue(player)
|
DropQueue(player)
|
||||||
.addItems(menu.getCaptiveItems(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.ecoscrolls.scrolls.event.ScrollTryInscribeEvent
|
||||||
import com.willfp.libreforge.NamedValue
|
import com.willfp.libreforge.NamedValue
|
||||||
import com.willfp.libreforge.ViolationContext
|
import com.willfp.libreforge.ViolationContext
|
||||||
|
import com.willfp.libreforge.effects.Chain
|
||||||
import com.willfp.libreforge.effects.EffectList
|
import com.willfp.libreforge.effects.EffectList
|
||||||
import com.willfp.libreforge.effects.Effects
|
import com.willfp.libreforge.effects.Effects
|
||||||
import com.willfp.libreforge.toDispatcher
|
import com.willfp.libreforge.toDispatcher
|
||||||
import com.willfp.libreforge.triggers.TriggerData
|
import com.willfp.libreforge.triggers.TriggerData
|
||||||
import org.bukkit.entity.Player
|
import org.bukkit.entity.Player
|
||||||
import org.bukkit.inventory.ItemStack
|
import org.bukkit.inventory.ItemStack
|
||||||
|
import java.util.Optional
|
||||||
|
|
||||||
class InscriptionHandler(private val plugin: EcoScrollsPlugin) {
|
class InscriptionHandler(private val plugin: EcoScrollsPlugin) {
|
||||||
private lateinit var applyEffects: EffectList
|
private lateinit var applyEffects: Optional<Chain>
|
||||||
private lateinit var denyEffects: EffectList
|
private lateinit var denyEffects: Optional<Chain>
|
||||||
|
|
||||||
val scrollLimit = plugin.configYml.getInt("inscription.scroll-limit")
|
val scrollLimit = plugin.configYml.getInt("inscription.scroll-limit")
|
||||||
.let { if (it <= 0) Int.MAX_VALUE else it }
|
.let { if (it <= 0) Int.MAX_VALUE else it }
|
||||||
@@ -22,15 +24,15 @@ class InscriptionHandler(private val plugin: EcoScrollsPlugin) {
|
|||||||
internal fun reload() {
|
internal fun reload() {
|
||||||
val context = ViolationContext(plugin, "Inscriptions")
|
val context = ViolationContext(plugin, "Inscriptions")
|
||||||
|
|
||||||
applyEffects = Effects.compile(
|
applyEffects = Optional.ofNullable(Effects.compileChain(
|
||||||
plugin.configYml.getSubsections("inscription.apply-effects"),
|
plugin.configYml.getSubsections("inscription.apply-effects"),
|
||||||
context.with("Apply Effects")
|
context.with("Apply Effects")
|
||||||
)
|
))
|
||||||
|
|
||||||
denyEffects = Effects.compile(
|
denyEffects = Optional.ofNullable(Effects.compileChain(
|
||||||
plugin.configYml.getSubsections("inscription.deny-effects"),
|
plugin.configYml.getSubsections("inscription.deny-effects"),
|
||||||
context.with("Deny Effects")
|
context.with("Deny Effects")
|
||||||
)
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun inscriptionTrigger(item: ItemStack, scroll: Scroll, player: Player) =
|
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)
|
val didInscribe = scroll.inscribe(item, player)
|
||||||
|
|
||||||
if (didInscribe) {
|
if (didInscribe) {
|
||||||
applyEffects.trigger(inscriptionTrigger(item, scroll, player))
|
applyEffects.ifPresent {
|
||||||
|
it.trigger(inscriptionTrigger(item, scroll, player))
|
||||||
|
}
|
||||||
|
|
||||||
val event = ScrollInscribeEvent(player, scroll, item)
|
val event = ScrollInscribeEvent(player, scroll, item)
|
||||||
plugin.server.pluginManager.callEvent(event)
|
plugin.server.pluginManager.callEvent(event)
|
||||||
} else {
|
} else {
|
||||||
denyEffects.trigger(inscriptionTrigger(item, scroll, player))
|
denyEffects.ifPresent {
|
||||||
|
it.trigger(inscriptionTrigger(item, scroll, player))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return didInscribe
|
return didInscribe
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ class Scroll(
|
|||||||
context.with("inscription conditions")
|
context.with("inscription conditions")
|
||||||
)
|
)
|
||||||
|
|
||||||
private val inscriptionEffects = Effects.compile(
|
private val inscriptionEffects = Effects.compileChain(
|
||||||
config.getSubsections("inscription.effects"),
|
config.getSubsections("inscription.effects"),
|
||||||
context.with("inscription effects")
|
context.with("inscription effects")
|
||||||
)
|
)
|
||||||
@@ -230,7 +230,7 @@ class Scroll(
|
|||||||
|
|
||||||
inscribe(itemStack)
|
inscribe(itemStack)
|
||||||
|
|
||||||
inscriptionEffects.trigger(
|
inscriptionEffects?.trigger(
|
||||||
TriggerData(
|
TriggerData(
|
||||||
player = player,
|
player = player,
|
||||||
item = itemStack,
|
item = itemStack,
|
||||||
|
|||||||
Reference in New Issue
Block a user