Skip to content

Commit

Permalink
Fixed several bugs with nested chains, holders, placeholders
Browse files Browse the repository at this point in the history
  • Loading branch information
WillFP committed Dec 12, 2023
1 parent 293dbff commit 00f0eb7
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 20 deletions.
2 changes: 1 addition & 1 deletion core/src/main/kotlin/com/willfp/libreforge/NamedValue.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
val identifiers: Collection<String>,
value: String
) {
constructor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<HolderTemplate>("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)!")
}

Expand All @@ -39,15 +39,14 @@ object EffectAddHolder : Effect<HolderTemplate>("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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -25,13 +26,10 @@ import java.util.UUID
import java.util.concurrent.TimeUnit

object EffectAddHolderInRadius : Effect<HolderTemplate>("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!")
}
Expand All @@ -52,8 +50,8 @@ object EffectAddHolderInRadius : Effect<HolderTemplate>("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)
Expand All @@ -63,7 +61,7 @@ object EffectAddHolderInRadius : Effect<HolderTemplate>("add_holder_in_radius")
compileData.toHolder().nest(data.holder),
location,
radius,
player.uniqueId,
dispatcher.uuid,
applyToSelf
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ object EffectAddHolderToVictim : Effect<HolderTemplate>("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)!")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import java.util.concurrent.TimeUnit
object EffectAddPermanentHolderInRadius : Effect<HolderTemplate>("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!")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down

0 comments on commit 00f0eb7

Please sign in to comment.