diff --git a/core/src/main/kotlin/com/willfp/libreforge/NamedValue.kt b/core/src/main/kotlin/com/willfp/libreforge/NamedValue.kt index cb934fed2..47abb1520 100644 --- a/core/src/main/kotlin/com/willfp/libreforge/NamedValue.kt +++ b/core/src/main/kotlin/com/willfp/libreforge/NamedValue.kt @@ -6,7 +6,7 @@ import com.willfp.eco.core.placeholder.context.PlaceholderContext import com.willfp.eco.core.placeholder.templates.SimpleInjectablePlaceholder open class NamedValue constructor( - identifiers: Collection, + val identifiers: Collection, value: String ) { constructor( diff --git a/core/src/main/kotlin/com/willfp/libreforge/effects/impl/EffectAddHolder.kt b/core/src/main/kotlin/com/willfp/libreforge/effects/impl/EffectAddHolder.kt index 070583baf..f5fd731ad 100644 --- a/core/src/main/kotlin/com/willfp/libreforge/effects/impl/EffectAddHolder.kt +++ b/core/src/main/kotlin/com/willfp/libreforge/effects/impl/EffectAddHolder.kt @@ -2,6 +2,7 @@ package com.willfp.libreforge.effects.impl import com.willfp.eco.core.config.interfaces.Config import com.willfp.eco.core.map.listMap +import com.willfp.libreforge.GlobalDispatcher.uuid import com.willfp.libreforge.Holder import com.willfp.libreforge.HolderTemplate import com.willfp.libreforge.SimpleProvidedHolder @@ -12,21 +13,20 @@ import com.willfp.libreforge.effects.Effect import com.willfp.libreforge.effects.Effects import com.willfp.libreforge.generatePlaceholders import com.willfp.libreforge.getIntFromExpression +import com.willfp.libreforge.isType import com.willfp.libreforge.nest import com.willfp.libreforge.plugin import com.willfp.libreforge.registerGenericHolderProvider import com.willfp.libreforge.triggers.TriggerData import com.willfp.libreforge.triggers.TriggerParameter +import org.bukkit.entity.Player import java.util.UUID object EffectAddHolder : Effect("add_holder") { - override val parameters = setOf( - TriggerParameter.PLAYER - ) + override val isPermanent = false override val arguments = arguments { require("effects", "You must specify the effects!") - // require("conditions", "You must specify the conditions!") require("duration", "You must specify the duration (in ticks)!") } @@ -39,15 +39,14 @@ object EffectAddHolder : Effect("add_holder") { } override fun onTrigger(config: Config, data: TriggerData, compileData: HolderTemplate): Boolean { - val player = data.player ?: return false - + val dispatcher = data.dispatcher val duration = config.getIntFromExpression("duration", data) val holder = compileData.toHolder().nest(data.holder) - holders[player.uniqueId] += holder + holders[dispatcher.uuid] += holder plugin.scheduler.runLater(duration.toLong()) { - holders[player.uniqueId] -= holder + holders[dispatcher.uuid] -= holder } return true diff --git a/core/src/main/kotlin/com/willfp/libreforge/effects/impl/EffectAddHolderInRadius.kt b/core/src/main/kotlin/com/willfp/libreforge/effects/impl/EffectAddHolderInRadius.kt index 61a330718..f1e4135e9 100644 --- a/core/src/main/kotlin/com/willfp/libreforge/effects/impl/EffectAddHolderInRadius.kt +++ b/core/src/main/kotlin/com/willfp/libreforge/effects/impl/EffectAddHolderInRadius.kt @@ -4,6 +4,7 @@ import com.github.benmanes.caffeine.cache.Caffeine import com.willfp.eco.core.config.interfaces.Config import com.willfp.libreforge.Dispatcher import com.willfp.libreforge.EmptyProvidedHolder.holder +import com.willfp.libreforge.GlobalDispatcher.location import com.willfp.libreforge.Holder import com.willfp.libreforge.HolderTemplate import com.willfp.libreforge.SimpleProvidedHolder @@ -25,13 +26,10 @@ import java.util.UUID import java.util.concurrent.TimeUnit object EffectAddHolderInRadius : Effect("add_holder_in_radius") { - override val parameters = setOf( - TriggerParameter.PLAYER - ) + override val isPermanent = false override val arguments = arguments { require("effects", "You must specify the effects!") - // require("conditions", "You must specify the conditions!") require("duration", "You must specify the duration (in ticks)!") require("radius", "You must specify the radius!") } @@ -52,8 +50,8 @@ object EffectAddHolderInRadius : Effect("add_holder_in_radius") } override fun onTrigger(config: Config, data: TriggerData, compileData: HolderTemplate): Boolean { - val player = data.player ?: return false - val location = data.location ?: return false + val dispatcher = data.dispatcher + val location = dispatcher.location ?: return false val radius = config.getDoubleFromExpression("radius", data) val duration = config.getIntFromExpression("duration", data) @@ -63,7 +61,7 @@ object EffectAddHolderInRadius : Effect("add_holder_in_radius") compileData.toHolder().nest(data.holder), location, radius, - player.uniqueId, + dispatcher.uuid, applyToSelf ) diff --git a/core/src/main/kotlin/com/willfp/libreforge/effects/impl/EffectAddHolderToVictim.kt b/core/src/main/kotlin/com/willfp/libreforge/effects/impl/EffectAddHolderToVictim.kt index eab6bce0f..9f2703cae 100644 --- a/core/src/main/kotlin/com/willfp/libreforge/effects/impl/EffectAddHolderToVictim.kt +++ b/core/src/main/kotlin/com/willfp/libreforge/effects/impl/EffectAddHolderToVictim.kt @@ -26,7 +26,6 @@ object EffectAddHolderToVictim : Effect("add_holder_to_victim") override val arguments = arguments { require("effects", "You must specify the effects!") - // require("conditions", "You must specify the conditions!") require("duration", "You must specify the duration (in ticks)!") } diff --git a/core/src/main/kotlin/com/willfp/libreforge/effects/impl/EffectAddPermanentHolderInRadius.kt b/core/src/main/kotlin/com/willfp/libreforge/effects/impl/EffectAddPermanentHolderInRadius.kt index a369b5467..4fc01fd41 100644 --- a/core/src/main/kotlin/com/willfp/libreforge/effects/impl/EffectAddPermanentHolderInRadius.kt +++ b/core/src/main/kotlin/com/willfp/libreforge/effects/impl/EffectAddPermanentHolderInRadius.kt @@ -24,7 +24,6 @@ import java.util.concurrent.TimeUnit object EffectAddPermanentHolderInRadius : Effect("add_permanent_holder_in_radius") { override val arguments = arguments { require("effects", "You must specify the effects!") - // require("conditions", "You must specify the conditions!") require("radius", "You must specify the radius!") } diff --git a/core/src/main/kotlin/com/willfp/libreforge/triggers/DispatchedTrigger.kt b/core/src/main/kotlin/com/willfp/libreforge/triggers/DispatchedTrigger.kt index e00cb36d0..d3d178988 100644 --- a/core/src/main/kotlin/com/willfp/libreforge/triggers/DispatchedTrigger.kt +++ b/core/src/main/kotlin/com/willfp/libreforge/triggers/DispatchedTrigger.kt @@ -8,7 +8,7 @@ import com.willfp.libreforge.toDispatcher import com.willfp.libreforge.triggers.placeholders.TriggerPlaceholders import org.bukkit.entity.Player -data class DispatchedTrigger( +class DispatchedTrigger( val dispatcher: Dispatcher<*>, val trigger: Trigger, val data: TriggerData @@ -61,4 +61,13 @@ data class DispatchedTrigger( _placeholders += placeholder.createPlaceholders(data) } } + + /** + * Copy this [DispatchedTrigger], optionally overriding some values. + */ + fun copy( + dispatcher: Dispatcher<*> = this.dispatcher, + trigger: Trigger = this.trigger, + data: TriggerData = this.data + ): DispatchedTrigger = DispatchedTrigger(dispatcher, trigger, data).inheritPlaceholders(this) } diff --git a/core/src/main/kotlin/com/willfp/libreforge/triggers/Trigger.kt b/core/src/main/kotlin/com/willfp/libreforge/triggers/Trigger.kt index 4d97be108..103b04405 100644 --- a/core/src/main/kotlin/com/willfp/libreforge/triggers/Trigger.kt +++ b/core/src/main/kotlin/com/willfp/libreforge/triggers/Trigger.kt @@ -93,7 +93,7 @@ abstract class Trigger( continue } - val withHolder = data.copy(holder = holder) + val withHolder = dispatch.data.copy(holder = holder) val dispatchWithHolder = DispatchedTrigger(dispatcher, this, withHolder).inheritPlaceholders(dispatch) for (placeholder in holder.generatePlaceholders(dispatcher)) {