diff --git a/engine/engine-core/src/main/kotlin/com/typewritermc/core/extension/annotations/GenericConstraint.kt b/engine/engine-core/src/main/kotlin/com/typewritermc/core/extension/annotations/GenericConstraint.kt index 4faecc2025..aeadceb0d6 100644 --- a/engine/engine-core/src/main/kotlin/com/typewritermc/core/extension/annotations/GenericConstraint.kt +++ b/engine/engine-core/src/main/kotlin/com/typewritermc/core/extension/annotations/GenericConstraint.kt @@ -3,4 +3,5 @@ package com.typewritermc.core.extension.annotations import kotlin.reflect.KClass @Target(AnnotationTarget.CLASS) +@Repeatable annotation class GenericConstraint(val type: KClass<*>) diff --git a/engine/engine-core/src/main/kotlin/com/typewritermc/core/utils/point/Generic.kt b/engine/engine-core/src/main/kotlin/com/typewritermc/core/utils/point/Generic.kt index cd3c5f33d7..64c13f7d08 100644 --- a/engine/engine-core/src/main/kotlin/com/typewritermc/core/utils/point/Generic.kt +++ b/engine/engine-core/src/main/kotlin/com/typewritermc/core/utils/point/Generic.kt @@ -2,6 +2,7 @@ package com.typewritermc.core.utils.point import com.google.gson.Gson import com.google.gson.JsonElement +import com.google.gson.JsonObject import org.koin.core.component.KoinComponent import org.koin.core.component.inject import org.koin.core.qualifier.named @@ -10,6 +11,10 @@ import kotlin.reflect.KClass class Generic( val data: JsonElement, ) : KoinComponent { + companion object { + val Empty = Generic(JsonObject()) + } + private val gson: Gson by inject(named("dataSerializer")) fun get(klass: Class): T? { diff --git a/engine/engine-core/src/main/kotlin/com/typewritermc/core/utils/point/World.kt b/engine/engine-core/src/main/kotlin/com/typewritermc/core/utils/point/World.kt index 2d2adf8244..8ba24ca706 100644 --- a/engine/engine-core/src/main/kotlin/com/typewritermc/core/utils/point/World.kt +++ b/engine/engine-core/src/main/kotlin/com/typewritermc/core/utils/point/World.kt @@ -2,4 +2,8 @@ package com.typewritermc.core.utils.point data class World( val identifier: String, -) \ No newline at end of file +) { + companion object { + val Empty = World("") + } +} \ No newline at end of file diff --git a/engine/engine-paper/src/main/kotlin/com/typewritermc/engine/paper/entry/entries/DialogueEntry.kt b/engine/engine-paper/src/main/kotlin/com/typewritermc/engine/paper/entry/entries/DialogueEntry.kt index 4eec22684b..a971b5a26e 100644 --- a/engine/engine-paper/src/main/kotlin/com/typewritermc/engine/paper/entry/entries/DialogueEntry.kt +++ b/engine/engine-paper/src/main/kotlin/com/typewritermc/engine/paper/entry/entries/DialogueEntry.kt @@ -10,7 +10,7 @@ interface DialogueEntry : TriggerableEntry { @Help("The speaker of the dialogue") val speaker: Ref - val speakerDisplayName: String - get() = speaker.get()?.displayName ?: "" + val speakerDisplayName: Var + get() = speaker.get()?.displayName ?: ConstVar("") } diff --git a/engine/engine-paper/src/main/kotlin/com/typewritermc/engine/paper/entry/entries/EntityEntry.kt b/engine/engine-paper/src/main/kotlin/com/typewritermc/engine/paper/entry/entries/EntityEntry.kt index 46ebba6a88..982deded9e 100644 --- a/engine/engine-paper/src/main/kotlin/com/typewritermc/engine/paper/entry/entries/EntityEntry.kt +++ b/engine/engine-paper/src/main/kotlin/com/typewritermc/engine/paper/entry/entries/EntityEntry.kt @@ -5,9 +5,11 @@ import com.typewritermc.core.entries.Ref import com.typewritermc.core.entries.ref import com.typewritermc.core.extension.annotations.* import com.typewritermc.core.utils.point.Position -import com.typewritermc.engine.paper.entry.* +import com.typewritermc.engine.paper.entry.ManifestEntry +import com.typewritermc.engine.paper.entry.PlaceholderEntry import com.typewritermc.engine.paper.entry.entity.* -import com.typewritermc.engine.paper.utils.EmitterSoundSource +import com.typewritermc.engine.paper.entry.findDisplay +import com.typewritermc.engine.paper.entry.inAudience import com.typewritermc.engine.paper.utils.Sound import org.bukkit.entity.Player import kotlin.reflect.KClass @@ -17,12 +19,12 @@ interface SpeakerEntry : PlaceholderEntry { @Colored @Placeholder @Help("The name of the entity that will be displayed in the chat (e.g. 'Steve' or 'Alex').") - val displayName: String + val displayName: Var @Help("The sound that will be played when the entity speaks.") val sound: Sound - override fun display(player: Player?): String? = displayName + override fun display(player: Player?): String? = displayName.get(player) } /** @@ -90,9 +92,14 @@ interface SharedEntityActivityEntry : EntityActivityEntry { context: ActivityContext, currentLocation: PositionProperty ): EntityActivity { - if (context !is SharedActivityContext) throw WrongActivityContextException(context, SharedActivityContext::class, this) + if (context !is SharedActivityContext) throw WrongActivityContextException( + context, + SharedActivityContext::class, + this + ) return create(context, currentLocation) as EntityActivity } + fun create(context: SharedActivityContext, currentLocation: PositionProperty): EntityActivity } @@ -102,10 +109,18 @@ interface IndividualEntityActivityEntry : EntityActivityEntry { context: ActivityContext, currentLocation: PositionProperty ): EntityActivity { - if (context !is IndividualActivityContext) throw WrongActivityContextException(context, IndividualActivityContext::class, this) + if (context !is IndividualActivityContext) throw WrongActivityContextException( + context, + IndividualActivityContext::class, + this + ) return create(context, currentLocation) as EntityActivity } - fun create(context: IndividualActivityContext, currentLocation: PositionProperty): EntityActivity + + fun create( + context: IndividualActivityContext, + currentLocation: PositionProperty + ): EntityActivity } @Tags("generic_entity_activity") @@ -130,7 +145,12 @@ interface GenericEntityActivityEntry : SharedEntityActivityEntry, IndividualEnti } } -class WrongActivityContextException(context: ActivityContext, expected: KClass, entry: EntityActivityEntry) : IllegalStateException(""" +class WrongActivityContextException( + context: ActivityContext, + expected: KClass, + entry: EntityActivityEntry +) : IllegalStateException( + """ |The activity context for ${entry.name} is not of the expected type. |Expected: $expected |Actual: $context @@ -141,4 +161,5 @@ class WrongActivityContextException(context: ActivityContext, expected: KClass val facts: List> get() = emptyList() fun questStatus(player: Player): QuestStatus - override fun display(player: Player?): String = displayName.parsePlaceholders(player) + override fun display(player: Player?): String = displayName.get(player)?.parsePlaceholders(player) ?: "" override fun display(): AudienceFilter = QuestAudienceFilter( ref() ) @@ -64,7 +64,7 @@ interface ObjectiveEntry : AudienceFilterEntry, PlaceholderEntry, PriorityEntry @Help("The name to display to the player.") @Colored @Placeholder - val display: String + val display: Var override fun display(): AudienceFilter { return ObjectiveAudienceFilter( @@ -79,6 +79,8 @@ interface ObjectiveEntry : AudienceFilterEntry, PlaceholderEntry, PriorityEntry criteria.matches(player) -> showingObjectiveDisplay else -> inactiveObjectiveDisplay } + val display = display.get(player) ?: "" + return text.asMiniWithResolvers(parsed("display", display)).asMini().parsePlaceholders(player) } } diff --git a/engine/engine-paper/src/main/kotlin/com/typewritermc/engine/paper/entry/entries/SidebarEntry.kt b/engine/engine-paper/src/main/kotlin/com/typewritermc/engine/paper/entry/entries/SidebarEntry.kt index 2adc03b2f4..d75bafb77b 100644 --- a/engine/engine-paper/src/main/kotlin/com/typewritermc/engine/paper/entry/entries/SidebarEntry.kt +++ b/engine/engine-paper/src/main/kotlin/com/typewritermc/engine/paper/entry/entries/SidebarEntry.kt @@ -31,9 +31,11 @@ interface SidebarEntry : AudienceFilterEntry, PlaceholderEntry, PriorityEntry { @Help("The title of the sidebar") @Colored @Placeholder - val title: String + val title: Var - override fun display(player: Player?): String? = title.parsePlaceholders(player) + override fun display(player: Player?): String? { + return title.get(player)?.parsePlaceholders(player) ?: "" + } override fun display(): AudienceFilter = SidebarFilter(ref()) { player -> PlayerSidebarDisplay(player, SidebarFilter::class, ref()) diff --git a/engine/engine-paper/src/main/kotlin/com/typewritermc/engine/paper/entry/entries/VariableEntry.kt b/engine/engine-paper/src/main/kotlin/com/typewritermc/engine/paper/entry/entries/VariableEntry.kt index f7b8152f03..8d4b1a8d89 100644 --- a/engine/engine-paper/src/main/kotlin/com/typewritermc/engine/paper/entry/entries/VariableEntry.kt +++ b/engine/engine-paper/src/main/kotlin/com/typewritermc/engine/paper/entry/entries/VariableEntry.kt @@ -9,6 +9,8 @@ import org.bukkit.entity.Player import org.koin.core.component.KoinComponent import org.koin.core.component.inject import org.koin.core.qualifier.named +import kotlin.contracts.ExperimentalContracts +import kotlin.contracts.contract import kotlin.reflect.KClass @Tags("variable") @@ -36,6 +38,16 @@ sealed interface Var { fun get(player: Player): T } +@OptIn(ExperimentalContracts::class) +fun Var.get(player: Player?): T? { + contract { + returns(null) implies (player == null) + } + if (this is ConstVar<*>) return this.value as T + if (player == null) return null + return get(player) +} + class ConstVar(val value: T) : Var { override fun get(player: Player): T = value } @@ -49,4 +61,15 @@ class BackedVar( val entry = ref.get() ?: throw IllegalStateException("Could not find variable entry") return entry.get(VarContext(player, data, klass)) } -} \ No newline at end of file +} + +class MappedVar( + private val variable:Var, + private val mapper: (Player, T) -> T, +) : Var { + override fun get(player: Player): T { + return mapper(player, variable.get(player)) + } +} + +fun Var.map(mapper: (Player, T) -> T): Var = MappedVar(this, mapper) \ No newline at end of file diff --git a/engine/engine-paper/src/main/kotlin/com/typewritermc/engine/paper/loader/serializers/VarSerializer.kt b/engine/engine-paper/src/main/kotlin/com/typewritermc/engine/paper/loader/serializers/VarSerializer.kt index a8fbf0ace2..b6ff477a5f 100644 --- a/engine/engine-paper/src/main/kotlin/com/typewritermc/engine/paper/loader/serializers/VarSerializer.kt +++ b/engine/engine-paper/src/main/kotlin/com/typewritermc/engine/paper/loader/serializers/VarSerializer.kt @@ -24,6 +24,9 @@ class VarSerializer : DataSerializer> { obj.add("data", context.serialize(src.data)) return obj } + is MappedVar<*> -> { + throw IllegalStateException("Could not serialize mapped var") + } } } diff --git a/engine/engine-paper/src/main/kotlin/com/typewritermc/engine/paper/loader/serializers/WorldSerializer.kt b/engine/engine-paper/src/main/kotlin/com/typewritermc/engine/paper/loader/serializers/WorldSerializer.kt index 1a89cb3b85..9244414446 100644 --- a/engine/engine-paper/src/main/kotlin/com/typewritermc/engine/paper/loader/serializers/WorldSerializer.kt +++ b/engine/engine-paper/src/main/kotlin/com/typewritermc/engine/paper/loader/serializers/WorldSerializer.kt @@ -13,12 +13,12 @@ import java.lang.reflect.Type class WorldSerializer : DataSerializer { override val type: Type = World::class.java - override fun serialize(src: World?, typeOfSrc: Type?, context: JsonSerializationContext?): JsonElement { - return JsonPrimitive(src?.identifier ?: "") + override fun serialize(src: World, typeOfSrc: Type, context: JsonSerializationContext): JsonElement { + return JsonPrimitive(src.identifier) } - override fun deserialize(json: JsonElement?, typeOfT: Type?, context: JsonDeserializationContext?): World { - val world = json?.asString ?: "" + override fun deserialize(json: JsonElement, typeOfT: Type, context: JsonDeserializationContext): World { + val world = json.asString val bukkitWorld = server.getWorld(world) ?: server.worlds.firstOrNull { it.name.equals(world, true) } diff --git a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/AddPotionEffectActionEntry.kt b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/AddPotionEffectActionEntry.kt index 6d8a7302fd..736b11be33 100644 --- a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/AddPotionEffectActionEntry.kt +++ b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/AddPotionEffectActionEntry.kt @@ -9,6 +9,8 @@ import com.typewritermc.engine.paper.entry.Criteria import com.typewritermc.engine.paper.entry.Modifier import com.typewritermc.engine.paper.entry.TriggerableEntry import com.typewritermc.engine.paper.entry.entries.ActionEntry +import com.typewritermc.engine.paper.entry.entries.ConstVar +import com.typewritermc.engine.paper.entry.entries.Var import com.typewritermc.engine.paper.utils.ThreadType.SYNC import com.typewritermc.engine.paper.utils.toTicks import org.bukkit.entity.Player @@ -35,11 +37,11 @@ class AddPotionEffectActionEntry( override val criteria: List = emptyList(), override val modifiers: List = emptyList(), override val triggers: List> = emptyList(), - val potionEffect: PotionEffectType = PotionEffectType.SPEED, + val potionEffect: Var = ConstVar(PotionEffectType.SPEED), @Default("10000") - val duration: Duration = Duration.ofSeconds(10), + val duration: Var = ConstVar(Duration.ofSeconds(10)), @Default("1") - val amplifier: Int = 1, + val amplifier: Var = ConstVar(1), val ambient: Boolean = false, @Default("true") val particles: Boolean = true, @@ -50,7 +52,14 @@ class AddPotionEffectActionEntry( override fun execute(player: Player) { super.execute(player) - val potion = PotionEffect(potionEffect, duration.toTicks().toInt(), amplifier, ambient, particles, icon) + val potion = PotionEffect( + potionEffect.get(player), + duration.get(player).toTicks().toInt(), + amplifier.get(player), + ambient, + particles, + icon + ) SYNC.launch { player.addPotionEffect(potion) } diff --git a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/ApplyVelocityActionEntry.kt b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/ApplyVelocityActionEntry.kt index 1bf322791c..cfd3ebeead 100644 --- a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/ApplyVelocityActionEntry.kt +++ b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/ApplyVelocityActionEntry.kt @@ -8,6 +8,8 @@ import com.typewritermc.core.extension.annotations.Entry import com.typewritermc.core.utils.point.Vector import com.typewritermc.engine.paper.entry.Criteria import com.typewritermc.engine.paper.entry.entries.ActionEntry +import com.typewritermc.engine.paper.entry.entries.ConstVar +import com.typewritermc.engine.paper.entry.entries.Var import com.typewritermc.engine.paper.utils.toBukkitVector import org.bukkit.entity.Player @@ -25,11 +27,11 @@ class ApplyVelocityActionEntry( override val criteria: List = emptyList(), override val modifiers: List = emptyList(), override val triggers: List> = emptyList(), - val force: Vector = Vector(0.0, 0.0, 0.0), + val force: Var = ConstVar(Vector(0.0, 0.0, 0.0)), ) : ActionEntry { override fun execute(player: Player) { super.execute(player) - player.velocity = player.velocity.add(force.toBukkitVector()) + player.velocity = player.velocity.add(force.get(player).toBukkitVector()) } } \ No newline at end of file diff --git a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/ConsoleCommandActionEntry.kt b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/ConsoleCommandActionEntry.kt index d1745f75d0..8cceeeb762 100644 --- a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/ConsoleCommandActionEntry.kt +++ b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/ConsoleCommandActionEntry.kt @@ -10,6 +10,8 @@ import com.typewritermc.engine.paper.entry.Modifier import com.typewritermc.core.entries.Ref import com.typewritermc.engine.paper.entry.TriggerableEntry import com.typewritermc.engine.paper.entry.entries.ActionEntry +import com.typewritermc.engine.paper.entry.entries.ConstVar +import com.typewritermc.engine.paper.entry.entries.Var import com.typewritermc.engine.paper.extensions.placeholderapi.parsePlaceholders import com.typewritermc.engine.paper.utils.ThreadType.SYNC import lirand.api.extensions.server.server @@ -33,10 +35,11 @@ class ConsoleCommandActionEntry( @Placeholder @MultiLine @Help("Every line is a different command. Commands should not be prefixed with /.") - private val command: String = "", + private val command: Var = ConstVar(""), ) : ActionEntry { override fun execute(player: Player) { super.execute(player) + val command = command.get(player) // Run in the main thread if (command.isBlank()) return SYNC.launch { diff --git a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/DelayedActionEntry.kt b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/DelayedActionEntry.kt index 3043a32232..e90003166a 100644 --- a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/DelayedActionEntry.kt +++ b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/DelayedActionEntry.kt @@ -9,7 +9,9 @@ import com.typewritermc.engine.paper.entry.Criteria import com.typewritermc.engine.paper.entry.Modifier import com.typewritermc.core.entries.Ref import com.typewritermc.engine.paper.entry.TriggerableEntry +import com.typewritermc.engine.paper.entry.entries.ConstVar import com.typewritermc.engine.paper.entry.entries.CustomTriggeringActionEntry +import com.typewritermc.engine.paper.entry.entries.Var import com.typewritermc.engine.paper.utils.ThreadType.DISPATCHERS_ASYNC import org.bukkit.entity.Player import java.time.Duration @@ -31,12 +33,12 @@ class DelayedActionEntry( @SerializedName("triggers") override val customTriggers: List> = emptyList(), @Help("The duration before the next triggers are fired.") - private val duration: Duration = Duration.ZERO, + private val duration: Var = ConstVar(Duration.ZERO), ) : CustomTriggeringActionEntry { override fun execute(player: Player) { DISPATCHERS_ASYNC.launch { - delay(duration.toMillis()) + delay(duration.get(player).toMillis()) super.execute(player) player.triggerCustomTriggers() } diff --git a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/DropItemActionEntry.kt b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/DropItemActionEntry.kt index 73cdb8f42e..9b994d1c35 100644 --- a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/DropItemActionEntry.kt +++ b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/DropItemActionEntry.kt @@ -9,9 +9,12 @@ import com.typewritermc.core.extension.annotations.Entry import com.typewritermc.core.extension.annotations.Help import com.typewritermc.core.utils.point.Position import com.typewritermc.engine.paper.entry.entries.ActionEntry +import com.typewritermc.engine.paper.entry.entries.ConstVar +import com.typewritermc.engine.paper.entry.entries.Var import com.typewritermc.engine.paper.utils.item.Item import com.typewritermc.engine.paper.utils.ThreadType.SYNC import com.typewritermc.engine.paper.utils.toBukkitLocation +import io.github.retrooper.packetevents.util.SpigotConversionUtil.toBukkitLocation import org.bukkit.entity.Player import java.util.* @@ -32,9 +35,9 @@ class DropItemActionEntry( override val criteria: List = emptyList(), override val modifiers: List = emptyList(), override val triggers: List> = emptyList(), - val item: Item = Item.Empty, + val item: Var = ConstVar(Item.Empty), @Help("The location to drop the item. (Defaults to the player's location)") - private val location: Optional = Optional.empty(), + private val location: Optional> = Optional.empty(), ) : ActionEntry { override fun execute(player: Player) { super.execute(player) @@ -42,10 +45,10 @@ class DropItemActionEntry( SYNC.launch { if (location.isPresent) { val position = location.get() - val bukkitLocation = position.toBukkitLocation() - bukkitLocation.world.dropItem(bukkitLocation, item.build(player)) + val bukkitLocation = position.get(player).toBukkitLocation() + bukkitLocation.world.dropItem(bukkitLocation, item.get(player).build(player)) } else { - player.location.world.dropItem(player.location, item.build(player)) + player.location.world.dropItem(player.location, item.get(player).build(player)) } } } diff --git a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/FireworkActionEntry.kt b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/FireworkActionEntry.kt index b1e55e3954..78d473c05b 100644 --- a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/FireworkActionEntry.kt +++ b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/FireworkActionEntry.kt @@ -11,6 +11,8 @@ import com.typewritermc.core.entries.Ref import com.typewritermc.core.extension.annotations.Default import com.typewritermc.engine.paper.entry.TriggerableEntry import com.typewritermc.engine.paper.entry.entries.ActionEntry +import com.typewritermc.engine.paper.entry.entries.ConstVar +import com.typewritermc.engine.paper.entry.entries.Var import com.typewritermc.engine.paper.extensions.packetevents.sendPacketTo import com.typewritermc.engine.paper.extensions.packetevents.toPacketItem import com.typewritermc.engine.paper.utils.Color @@ -44,10 +46,10 @@ class FireworkActionEntry( override val triggers: List> = emptyList(), override val criteria: List = emptyList(), override val modifiers: List = emptyList(), - val location: Position = Position.ORIGIN, - val effects: List = emptyList(), + val location: Var = ConstVar(Position.ORIGIN), + val effects: List> = emptyList(), @Default("0") - val flightDuration: Duration = Duration.ZERO, + val flightDuration: Var = ConstVar(Duration.ZERO), ) : ActionEntry { override fun execute(player: Player) { super.execute(player) @@ -55,7 +57,7 @@ class FireworkActionEntry( val item = ItemStack(Material.FIREWORK_ROCKET) item.editMeta (FireworkMeta::class.java) { meta -> this@FireworkActionEntry.effects.forEach { effect -> - meta.addEffect(effect.toBukkitEffect()) + meta.addEffect(effect.get(player).toBukkitEffect()) } } @@ -66,7 +68,8 @@ class FireworkActionEntry( } val entity = WrapperEntity(entityId, uuid, EntityTypes.FIREWORK_ROCKET, meta) entity.addViewer(player.uniqueId) - entity.spawn(location.toPacketLocation()) + entity.spawn(location.get(player).toPacketLocation()) + val flightDuration = flightDuration.get(player) if (flightDuration.isZero) { WrapperPlayServerEntityStatus(entityId, FIREWORK_EXPLOSION_STATUS) sendPacketTo player entity.despawn() diff --git a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/GiveItemActionEntry.kt b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/GiveItemActionEntry.kt index 0271f213e4..7633ec0e14 100644 --- a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/GiveItemActionEntry.kt +++ b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/GiveItemActionEntry.kt @@ -7,6 +7,8 @@ import com.typewritermc.core.entries.Ref import com.typewritermc.engine.paper.entry.TriggerableEntry import com.typewritermc.core.extension.annotations.Entry import com.typewritermc.engine.paper.entry.entries.ActionEntry +import com.typewritermc.engine.paper.entry.entries.ConstVar +import com.typewritermc.engine.paper.entry.entries.Var import com.typewritermc.engine.paper.utils.item.Item import com.typewritermc.engine.paper.utils.ThreadType.SYNC import org.bukkit.entity.Player @@ -25,13 +27,13 @@ class GiveItemActionEntry( override val criteria: List = emptyList(), override val modifiers: List = emptyList(), override val triggers: List> = emptyList(), - val item: Item = Item.Empty, + val item: Var = ConstVar(Item.Empty), ) : ActionEntry { override fun execute(player: Player) { super.execute(player) SYNC.launch { - player.inventory.addItem(item.build(player)) + player.inventory.addItem(item.get(player).build(player)) } } } \ No newline at end of file diff --git a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/GroupTriggerActionEntry.kt b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/GroupTriggerActionEntry.kt index 69d63ae80f..38b03aecf8 100644 --- a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/GroupTriggerActionEntry.kt +++ b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/GroupTriggerActionEntry.kt @@ -12,6 +12,7 @@ import com.typewritermc.engine.paper.entry.TriggerableEntry import com.typewritermc.engine.paper.entry.entries.CustomTriggeringActionEntry import com.typewritermc.engine.paper.entry.entries.GroupEntry import com.typewritermc.engine.paper.entry.entries.GroupId +import com.typewritermc.engine.paper.entry.entries.Var import org.bukkit.entity.Player import java.util.* @@ -42,7 +43,7 @@ class GroupTriggerActionEntry( override val customTriggers: List> = emptyList(), val group: Ref = emptyRef(), @Help("The group to trigger the next entries for. If not set, the action will trigger for the group of the player that triggered the action.") - val forceGroup: Optional = Optional.empty(), + val forceGroup: Optional> = Optional.empty(), ) : CustomTriggeringActionEntry { override fun execute(player: Player) { super.execute(player) @@ -50,7 +51,7 @@ class GroupTriggerActionEntry( val groupEntry = group.get() ?: return val group = forceGroup - .map { groupEntry.group(GroupId(it)) } + .map { groupEntry.group(GroupId(it.get(player))) } .orElseGet { groupEntry.group(player) } ?: return group.players.forEach { diff --git a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/MessageActionEntry.kt b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/MessageActionEntry.kt index 0a360fef1a..3079ed70e5 100644 --- a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/MessageActionEntry.kt +++ b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/MessageActionEntry.kt @@ -11,7 +11,9 @@ import com.typewritermc.engine.paper.entry.Modifier import com.typewritermc.engine.paper.entry.TriggerableEntry import com.typewritermc.engine.paper.entry.dialogue.playSpeakerSound import com.typewritermc.engine.paper.entry.entries.ActionEntry +import com.typewritermc.engine.paper.entry.entries.ConstVar import com.typewritermc.engine.paper.entry.entries.SpeakerEntry +import com.typewritermc.engine.paper.entry.entries.Var import com.typewritermc.engine.paper.extensions.placeholderapi.parsePlaceholders import com.typewritermc.engine.paper.snippets.snippet import com.typewritermc.engine.paper.utils.sendMiniWithResolvers @@ -47,7 +49,7 @@ class MessageActionEntry( @Placeholder @Colored @MultiLine - val message: String = "", + val message: Var = ConstVar(""), ) : ActionEntry { override fun execute(player: Player) { super.execute(player) @@ -58,11 +60,11 @@ class MessageActionEntry( messageFormat, parsed( "speaker", - speakerEntry?.displayName ?: "" + speakerEntry?.displayName?.get(player) ?: "" ), parsed( "message", - message.parsePlaceholders(player).replace("\n", "\n ") + message.get(player).parsePlaceholders(player).replace("\n", "\n ") ) ) } diff --git a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/PlaySoundActionEntry.kt b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/PlaySoundActionEntry.kt index 91b85ece57..6406b017cb 100644 --- a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/PlaySoundActionEntry.kt +++ b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/PlaySoundActionEntry.kt @@ -7,6 +7,8 @@ import com.typewritermc.engine.paper.entry.Modifier import com.typewritermc.core.entries.Ref import com.typewritermc.engine.paper.entry.TriggerableEntry import com.typewritermc.engine.paper.entry.entries.ActionEntry +import com.typewritermc.engine.paper.entry.entries.ConstVar +import com.typewritermc.engine.paper.entry.entries.Var import com.typewritermc.engine.paper.utils.Sound import com.typewritermc.engine.paper.utils.playSound import org.bukkit.entity.Player @@ -25,11 +27,11 @@ class PlaySoundActionEntry( override val criteria: List = emptyList(), override val modifiers: List = emptyList(), override val triggers: List> = emptyList(), - val sound: Sound = Sound.EMPTY, + val sound: Var = ConstVar(Sound.EMPTY), ) : ActionEntry { override fun execute(player: Player) { super.execute(player) - player.playSound(sound) + player.playSound(sound.get(player)) } } \ No newline at end of file diff --git a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/PlayerCommandActionEntry.kt b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/PlayerCommandActionEntry.kt index aa5325aa15..511ed2dd15 100644 --- a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/PlayerCommandActionEntry.kt +++ b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/PlayerCommandActionEntry.kt @@ -10,6 +10,8 @@ import com.typewritermc.engine.paper.entry.Modifier import com.typewritermc.core.entries.Ref import com.typewritermc.engine.paper.entry.TriggerableEntry import com.typewritermc.engine.paper.entry.entries.ActionEntry +import com.typewritermc.engine.paper.entry.entries.ConstVar +import com.typewritermc.engine.paper.entry.entries.Var import com.typewritermc.engine.paper.extensions.placeholderapi.parsePlaceholders import com.typewritermc.engine.paper.utils.ThreadType.SYNC import lirand.api.extensions.server.server @@ -38,10 +40,11 @@ class PlayerCommandActionEntry( @Placeholder @MultiLine @Help("Every line is a different command. Commands should not be prefixed with /.") - private val command: String = "", + private val command: Var = ConstVar(""), ) : ActionEntry { override fun execute(player: Player) { super.execute(player) + val command = command.get(player) // Run in main thread if (command.isBlank()) return SYNC.launch { diff --git a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/RandomTriggerGateEntry.kt b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/RandomTriggerGateEntry.kt index 45af447eee..c1acb93414 100644 --- a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/RandomTriggerGateEntry.kt +++ b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/RandomTriggerGateEntry.kt @@ -9,7 +9,9 @@ import com.typewritermc.engine.paper.entry.TriggerableEntry import com.typewritermc.core.extension.annotations.Entry import com.typewritermc.core.extension.annotations.Help import com.typewritermc.engine.paper.entry.* +import com.typewritermc.engine.paper.entry.entries.ConstVar import com.typewritermc.engine.paper.entry.entries.CustomTriggeringActionEntry +import com.typewritermc.engine.paper.entry.entries.Var import org.bukkit.entity.Player @Entry("random_trigger", "Randomly selects its connected triggers", Colors.PINK, "mdi:clover") @@ -28,14 +30,14 @@ class RandomTriggerGateEntry( override val criteria: List = emptyList(), override val modifiers: List = emptyList(), @Help("The number of triggers to fire next.") - private val amount: Int = 1, + private val amount: Var = ConstVar(1), ) : CustomTriggeringActionEntry { override fun execute(player: Player) { val selectedTriggers = mutableListOf>() if (customTriggers.isNotEmpty()) { - val randomIndices = (customTriggers.indices).shuffled().take(amount) + val randomIndices = (customTriggers.indices).shuffled().take(amount.get(player)) for (index in randomIndices) { selectedTriggers.add(customTriggers[index]) } diff --git a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/RemoveItemActionEntry.kt b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/RemoveItemActionEntry.kt index c9d345c049..01d8ad6333 100644 --- a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/RemoveItemActionEntry.kt +++ b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/RemoveItemActionEntry.kt @@ -7,6 +7,8 @@ import com.typewritermc.engine.paper.entry.Criteria import com.typewritermc.engine.paper.entry.Modifier import com.typewritermc.engine.paper.entry.TriggerableEntry import com.typewritermc.engine.paper.entry.entries.ActionEntry +import com.typewritermc.engine.paper.entry.entries.ConstVar +import com.typewritermc.engine.paper.entry.entries.Var import com.typewritermc.engine.paper.utils.ThreadType import com.typewritermc.engine.paper.utils.item.Item import org.bukkit.entity.Player @@ -32,13 +34,13 @@ class RemoveItemActionEntry( override val criteria: List = emptyList(), override val modifiers: List = emptyList(), override val triggers: List> = emptyList(), - val item: Item = Item.Empty, + val item: Var = ConstVar(Item.Empty), ) : ActionEntry { override fun execute(player: Player) { super.execute(player) ThreadType.SYNC.launch { - player.inventory.removeItemAnySlot(item.build(player).clone()) + player.inventory.removeItemAnySlot(item.get(player).build(player).clone()) } } } \ No newline at end of file diff --git a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/RemovePotionEffectActionEntry.kt b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/RemovePotionEffectActionEntry.kt index 66a1586df6..710e8b96b4 100644 --- a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/RemovePotionEffectActionEntry.kt +++ b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/RemovePotionEffectActionEntry.kt @@ -7,6 +7,8 @@ import com.typewritermc.engine.paper.entry.Criteria import com.typewritermc.engine.paper.entry.Modifier import com.typewritermc.engine.paper.entry.TriggerableEntry import com.typewritermc.engine.paper.entry.entries.ActionEntry +import com.typewritermc.engine.paper.entry.entries.ConstVar +import com.typewritermc.engine.paper.entry.entries.Var import com.typewritermc.engine.paper.utils.ThreadType.SYNC import org.bukkit.entity.Player import org.bukkit.potion.PotionEffectType @@ -30,13 +32,13 @@ class RemovePotionEffectActionEntry( override val criteria: List = emptyList(), override val modifiers: List = emptyList(), override val triggers: List> = emptyList(), - val potionEffect: PotionEffectType = PotionEffectType.SPEED, + val potionEffect: Var = ConstVar(PotionEffectType.SPEED), ) : ActionEntry { override fun execute(player: Player) { super.execute(player) SYNC.launch { - player.removePotionEffect(potionEffect) + player.removePotionEffect(potionEffect.get(player)) } } } \ No newline at end of file diff --git a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/SetBlockActionEntry.kt b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/SetBlockActionEntry.kt index b6e90ce6fd..f89004b301 100644 --- a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/SetBlockActionEntry.kt +++ b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/SetBlockActionEntry.kt @@ -8,8 +8,11 @@ import com.typewritermc.engine.paper.entry.Modifier import com.typewritermc.core.entries.Ref import com.typewritermc.engine.paper.entry.TriggerableEntry import com.typewritermc.engine.paper.entry.entries.ActionEntry +import com.typewritermc.engine.paper.entry.entries.ConstVar +import com.typewritermc.engine.paper.entry.entries.Var import com.typewritermc.engine.paper.utils.ThreadType.SYNC import com.typewritermc.engine.paper.utils.toBukkitLocation +import io.github.retrooper.packetevents.util.SpigotConversionUtil.toBukkitLocation import org.bukkit.Material import org.bukkit.entity.Player @@ -32,15 +35,15 @@ class SetBlockActionEntry( override val criteria: List = emptyList(), override val modifiers: List = emptyList(), override val triggers: List> = emptyList(), - val material: Material = Material.AIR, - val location: Position = Position.ORIGIN, + val material: Var = ConstVar(Material.AIR), + val location: Var = ConstVar(Position.ORIGIN), ) : ActionEntry { override fun execute(player: Player) { super.execute(player) SYNC.launch { - val bukkitLocation = location.toBukkitLocation() - bukkitLocation.block.type = material + val bukkitLocation = location.get(player).toBukkitLocation() + bukkitLocation.block.type = material.get(player) } } } \ No newline at end of file diff --git a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/SetItemActionEntry.kt b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/SetItemActionEntry.kt index 51f782da04..a87ad8bb75 100644 --- a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/SetItemActionEntry.kt +++ b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/SetItemActionEntry.kt @@ -7,6 +7,8 @@ import com.typewritermc.engine.paper.entry.Modifier import com.typewritermc.core.entries.Ref import com.typewritermc.engine.paper.entry.TriggerableEntry import com.typewritermc.engine.paper.entry.entries.ActionEntry +import com.typewritermc.engine.paper.entry.entries.ConstVar +import com.typewritermc.engine.paper.entry.entries.Var import com.typewritermc.engine.paper.utils.item.Item import com.typewritermc.engine.paper.utils.ThreadType.SYNC import org.bukkit.entity.Player @@ -25,14 +27,14 @@ class SetItemActionEntry( override val criteria: List = emptyList(), override val modifiers: List = emptyList(), override val triggers: List> = emptyList(), - val item: Item = Item.Empty, - val slot: Int = 0, + val item: Var = ConstVar(Item.Empty), + val slot: Var = ConstVar(0), ) : ActionEntry { override fun execute(player: Player) { super.execute(player) SYNC.launch { - player.inventory.setItem(slot, item.build(player)) + player.inventory.setItem(slot.get(player), item.get(player).build(player)) } } } \ No newline at end of file diff --git a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/ShowTitleActionEntry.kt b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/ShowTitleActionEntry.kt index 0c87604328..927647df90 100644 --- a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/ShowTitleActionEntry.kt +++ b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/ShowTitleActionEntry.kt @@ -10,6 +10,8 @@ import com.typewritermc.engine.paper.entry.Modifier import com.typewritermc.core.entries.Ref import com.typewritermc.engine.paper.entry.TriggerableEntry import com.typewritermc.engine.paper.entry.entries.ActionEntry +import com.typewritermc.engine.paper.entry.entries.ConstVar +import com.typewritermc.engine.paper.entry.entries.Var import com.typewritermc.engine.paper.extensions.placeholderapi.parsePlaceholders import com.typewritermc.engine.paper.utils.asMini import net.kyori.adventure.title.Title @@ -33,10 +35,10 @@ class ShowTitleActionEntry( override val triggers: List> = emptyList(), @Placeholder @Colored - val title: String = "", + val title: Var = ConstVar(""), @Placeholder @Colored - val subtitle: String = "", + val subtitle: Var = ConstVar(""), @Help("Optional duration settings for the title. Duration of the title: Fade in, how long it stays, fade out.") val durations: Optional = Optional.empty(), ) : ActionEntry { @@ -45,8 +47,8 @@ class ShowTitleActionEntry( val adventureTitle: Title = durations.map { durations -> Title.title( - title.parsePlaceholders(player).asMini(), - subtitle.parsePlaceholders(player).asMini(), + title.get(player).parsePlaceholders(player).asMini(), + subtitle.get(player).parsePlaceholders(player).asMini(), Title.Times.times( Duration.ofMillis(durations.fadeIn.toMillis()), @@ -56,8 +58,8 @@ class ShowTitleActionEntry( ) }.orElseGet { Title.title( - title.parsePlaceholders(player).asMini(), - subtitle.parsePlaceholders(player).asMini(), + title.get(player).parsePlaceholders(player).asMini(), + subtitle.get(player).parsePlaceholders(player).asMini() ) } diff --git a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/SimpleMessageActionEntry.kt b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/SimpleMessageActionEntry.kt index 0c34205bc8..300ec4d62b 100644 --- a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/SimpleMessageActionEntry.kt +++ b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/SimpleMessageActionEntry.kt @@ -10,6 +10,8 @@ import com.typewritermc.engine.paper.entry.Criteria import com.typewritermc.engine.paper.entry.Modifier import com.typewritermc.engine.paper.entry.TriggerableEntry import com.typewritermc.engine.paper.entry.entries.ActionEntry +import com.typewritermc.engine.paper.entry.entries.ConstVar +import com.typewritermc.engine.paper.entry.entries.Var import com.typewritermc.engine.paper.extensions.placeholderapi.parsePlaceholders import com.typewritermc.engine.paper.snippets.snippet import com.typewritermc.engine.paper.utils.sendMiniWithResolvers @@ -35,11 +37,11 @@ class SimpleMessageActionEntry( @Placeholder @Colored @MultiLine - val message: String = "", + val message: Var = ConstVar(""), ) : ActionEntry { override fun execute(player: Player) { super.execute(player) - player.sendMiniWithResolvers(simpleMessageFormat, parsed("message", message.parsePlaceholders(player))) + player.sendMiniWithResolvers(simpleMessageFormat, parsed("message", message.get(player).parsePlaceholders(player))) } } \ No newline at end of file diff --git a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/SpawnParticleActionEntry.kt b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/SpawnParticleActionEntry.kt index 2e65ec1406..2be4c9db29 100644 --- a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/SpawnParticleActionEntry.kt +++ b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/SpawnParticleActionEntry.kt @@ -1,15 +1,17 @@ package com.typewritermc.basic.entries.action import com.typewritermc.core.books.pages.Colors +import com.typewritermc.core.entries.Ref import com.typewritermc.core.extension.annotations.Entry import com.typewritermc.core.extension.annotations.Help -import com.typewritermc.core.extension.annotations.Negative import com.typewritermc.core.utils.point.Position +import com.typewritermc.core.utils.point.Vector import com.typewritermc.engine.paper.entry.Criteria import com.typewritermc.engine.paper.entry.Modifier -import com.typewritermc.core.entries.Ref import com.typewritermc.engine.paper.entry.TriggerableEntry import com.typewritermc.engine.paper.entry.entries.ActionEntry +import com.typewritermc.engine.paper.entry.entries.ConstVar +import com.typewritermc.engine.paper.entry.entries.Var import com.typewritermc.engine.paper.utils.toBukkitLocation import org.bukkit.Particle import org.bukkit.entity.Player @@ -30,26 +32,37 @@ class SpawnParticleActionEntry( override val modifiers: List = emptyList(), override val triggers: List> = emptyList(), @Help("The location to spawn the particles at. (Defaults to player's location)") - val location: Optional = Optional.empty(), - val particle: Particle = Particle.FLAME, - val count: Int = 1, - @Negative - val offsetX: Double = 0.0, - @Negative - val offsetY: Double = 0.0, - @Negative - val offsetZ: Double = 0.0, + val location: Optional> = Optional.empty(), + val particle: Var = ConstVar(Particle.FLAME), + val count: Var = ConstVar(1), + val offset: Var = ConstVar(Vector.ZERO), @Help("The speed of the particles. For some particles, this is the \"extra\" data value to control particle behavior.") - val speed: Double = 0.0, + val speed: Var = ConstVar(0.0), ) : ActionEntry { override fun execute(player: Player) { super.execute(player) if (location.isPresent) { - val bukkitLocation = location.get().toBukkitLocation() - bukkitLocation.world?.spawnParticle(particle, bukkitLocation, count, offsetX, offsetY, offsetZ, speed) + val bukkitLocation = location.get().get(player).toBukkitLocation() + bukkitLocation.world?.spawnParticle( + particle.get(player), + bukkitLocation, + count.get(player), + offset.get(player).x, + offset.get(player).y, + offset.get(player).z, + speed.get(player) + ) } else { - player.world.spawnParticle(particle, player.location, count, offsetX, offsetY, offsetZ, speed) + player.world.spawnParticle( + particle.get(player), + player.location, + count.get(player), + offset.get(player).x, + offset.get(player).y, + offset.get(player).z, + speed.get(player) + ) } } } \ No newline at end of file diff --git a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/StopSoundActionEntry.kt b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/StopSoundActionEntry.kt index bfc5992538..020903c96b 100644 --- a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/StopSoundActionEntry.kt +++ b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/StopSoundActionEntry.kt @@ -8,6 +8,7 @@ import com.typewritermc.engine.paper.entry.Modifier import com.typewritermc.core.entries.Ref import com.typewritermc.engine.paper.entry.TriggerableEntry import com.typewritermc.engine.paper.entry.entries.ActionEntry +import com.typewritermc.engine.paper.entry.entries.Var import com.typewritermc.engine.paper.utils.SoundId import net.kyori.adventure.sound.SoundStop import org.bukkit.entity.Player @@ -29,13 +30,13 @@ class StopSoundActionEntry( override val modifiers: List = emptyList(), override val triggers: List> = emptyList(), @Help("The sound to stop. If this field is left blank, all sounds will be stopped.") - val sound: Optional = Optional.empty(), + val sound: Optional> = Optional.empty(), ) : ActionEntry { override fun execute(player: Player) { super.execute(player) if (sound.isPresent) { - val sound = sound.get() + val sound = sound.get().get(player) val soundStop = sound.namespacedKey?.let { SoundStop.named(it) } ?: return player.stopSound(soundStop) diff --git a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/SwitchServerActionEntry.kt b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/SwitchServerActionEntry.kt index 740982aea2..c5c56a9bb5 100644 --- a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/SwitchServerActionEntry.kt +++ b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/SwitchServerActionEntry.kt @@ -9,6 +9,8 @@ import com.typewritermc.engine.paper.entry.Modifier import com.typewritermc.core.entries.Ref import com.typewritermc.engine.paper.entry.TriggerableEntry import com.typewritermc.engine.paper.entry.entries.ActionEntry +import com.typewritermc.engine.paper.entry.entries.ConstVar +import com.typewritermc.engine.paper.entry.entries.Var import com.typewritermc.engine.paper.plugin import org.bukkit.entity.Player @@ -27,7 +29,7 @@ class SwitchServerActionEntry( override val modifiers: List = emptyList(), override val triggers: List> = emptyList(), @Help("The server the player will connect to.") - val server: String = "", + val server: Var = ConstVar(""), ): ActionEntry { override fun execute(player: Player) { super.execute(player) @@ -36,7 +38,7 @@ class SwitchServerActionEntry( val out = ByteStreams.newDataOutput() out.writeUTF("Connect") - out.writeUTF(server) + out.writeUTF(server.get(player)) player.sendPluginMessage(plugin, "BungeeCord", out.toByteArray()) plugin.server.messenger.unregisterOutgoingPluginChannel(plugin, "BungeeCord") diff --git a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/TeleportActionEntry.kt b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/TeleportActionEntry.kt index 6af13863a6..01edc87d72 100644 --- a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/TeleportActionEntry.kt +++ b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/TeleportActionEntry.kt @@ -9,9 +9,12 @@ import com.typewritermc.engine.paper.entry.Criteria import com.typewritermc.engine.paper.entry.Modifier import com.typewritermc.core.entries.Ref import com.typewritermc.engine.paper.entry.TriggerableEntry +import com.typewritermc.engine.paper.entry.entries.ConstVar import com.typewritermc.engine.paper.entry.entries.CustomTriggeringActionEntry +import com.typewritermc.engine.paper.entry.entries.Var import com.typewritermc.engine.paper.utils.ThreadType.SYNC import com.typewritermc.engine.paper.utils.toBukkitLocation +import io.github.retrooper.packetevents.util.SpigotConversionUtil.toBukkitLocation import org.bukkit.entity.Player @Entry("teleport", "Teleport a player", Colors.RED, "teenyicons:google-streetview-solid") @@ -30,11 +33,11 @@ class TeleportActionEntry( @SerializedName("triggers") override val customTriggers: List> = emptyList(), @WithRotation - val location: Position = Position.ORIGIN, + val location: Var = ConstVar(Position.ORIGIN), ) : CustomTriggeringActionEntry { override fun execute(player: Player) { SYNC.launch { - player.teleport(location.toBukkitLocation()) + player.teleport(location.get(player).toBukkitLocation()) super.execute(player) player.triggerCustomTriggers() } diff --git a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/audience/BossBarEntry.kt b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/audience/BossBarEntry.kt index 9f7fea8f1c..1845dd96a4 100644 --- a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/audience/BossBarEntry.kt +++ b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/audience/BossBarEntry.kt @@ -5,11 +5,10 @@ import com.typewritermc.core.extension.annotations.Entry import com.typewritermc.core.extension.annotations.Colored import com.typewritermc.core.extension.annotations.Help import com.typewritermc.core.extension.annotations.Placeholder -import com.typewritermc.engine.paper.entry.entries.AudienceDisplay -import com.typewritermc.engine.paper.entry.entries.AudienceEntry -import com.typewritermc.engine.paper.entry.entries.TickableDisplay +import com.typewritermc.engine.paper.entry.entries.* import com.typewritermc.engine.paper.extensions.placeholderapi.parsePlaceholders import com.typewritermc.engine.paper.utils.asMini +import lirand.api.extensions.server.server import net.kyori.adventure.bossbar.BossBar import org.bukkit.entity.Player import java.util.* @@ -28,13 +27,13 @@ class BossBarEntry( @Colored @Placeholder @Help("The title of the boss bar") - val title: String = "", + val title: Var = ConstVar(""), @Help("How filled up the bar is. 0.0 is empty, 1.0 is full.") - val progress: Double = 1.0, + val progress: Var = ConstVar(1.0), @Help("The color of the boss bar") - val color: BossBar.Color = BossBar.Color.WHITE, + val color: Var = ConstVar(BossBar.Color.WHITE), @Help("If the bossbar has notches") - val style: BossBar.Overlay = BossBar.Overlay.PROGRESS, + val style: Var = ConstVar(BossBar.Overlay.PROGRESS), @Help("Any flags to apply to the boss bar") val flags: List = emptyList(), ) : AudienceEntry { @@ -44,26 +43,30 @@ class BossBarEntry( } class BossBarDisplay( - private val title: String, - private val progress: Double, - private val color: BossBar.Color, - private val style: BossBar.Overlay, + private val title: Var, + private val progress: Var, + private val color: Var, + private val style: Var, private val flags: List, ) : AudienceDisplay(), TickableDisplay { private val bars = ConcurrentHashMap() override fun tick() { for ((id, bar) in bars) { - bar.name(title.parsePlaceholders(id).asMini()) + val player = server.getPlayer(id) ?: continue + bar.name(title.get(player).parsePlaceholders(id).asMini()) + bar.progress(progress.get(player).toFloat()) + bar.color(color.get(player)) + bar.overlay(style.get(player)) } } override fun onPlayerAdd(player: Player) { val bar = BossBar.bossBar( - title.parsePlaceholders(player).asMini(), - progress.toFloat(), - color, - style, + title.get(player).parsePlaceholders(player).asMini(), + progress.get(player).toFloat(), + color.get(player), + style.get(player), flags.toSet() ) bars[player.uniqueId] = bar diff --git a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/audience/DirectLocationPathStream.kt b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/audience/DirectLocationPathStream.kt index ad0882e16b..ff026a8281 100644 --- a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/audience/DirectLocationPathStream.kt +++ b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/audience/DirectLocationPathStream.kt @@ -5,11 +5,10 @@ import com.typewritermc.core.entries.Ref import com.typewritermc.core.entries.emptyRef import com.typewritermc.core.extension.annotations.Entry import com.typewritermc.core.utils.point.Position -import com.typewritermc.engine.paper.entry.entries.AudienceDisplay -import com.typewritermc.engine.paper.entry.entries.AudienceEntry -import com.typewritermc.engine.paper.entry.entries.RoadNetworkEntry +import com.typewritermc.engine.paper.entry.entries.* import com.typewritermc.engine.paper.entry.roadnetwork.gps.PathStreamDisplay import com.typewritermc.engine.paper.utils.toBukkitLocation +import io.github.retrooper.packetevents.util.SpigotConversionUtil.toBukkitLocation @Entry( "direct_location_path_stream", @@ -28,7 +27,7 @@ class DirectLocationPathStream( override val id: String = "", override val name: String = "", val road: Ref = emptyRef(), - val targetLocation: Position = Position.ORIGIN, + val targetLocation: Var = ConstVar(Position.ORIGIN), ) : AudienceEntry { - override fun display(): AudienceDisplay = PathStreamDisplay(road, endLocation = { targetLocation.toBukkitLocation() }) + override fun display(): AudienceDisplay = PathStreamDisplay(road, endLocation = { targetLocation.get(it).toBukkitLocation() }) } \ No newline at end of file diff --git a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/audience/GameTimeAudienceEntry.kt b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/audience/GameTimeAudienceEntry.kt index efe47677d2..54c6453cd6 100644 --- a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/audience/GameTimeAudienceEntry.kt +++ b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/audience/GameTimeAudienceEntry.kt @@ -6,6 +6,7 @@ import com.typewritermc.core.extension.annotations.Entry import com.typewritermc.core.entries.Ref import com.typewritermc.engine.paper.entry.entries.* import com.typewritermc.core.entries.ref +import com.typewritermc.core.utils.point.World import com.typewritermc.engine.paper.logger import org.bukkit.entity.Player import org.bukkit.event.EventHandler @@ -40,7 +41,7 @@ class GameTimeAudienceEntry( override val id: String = "", override val name: String = "", override val children: List> = emptyList(), - val world: String = "", + val world: Var = ConstVar(World.Empty), val activeTimes: List = emptyList(), override val inverted: Boolean = false, ) : AudienceFilterEntry, Invertible { @@ -49,11 +50,11 @@ class GameTimeAudienceEntry( class GameTimeAudienceFilter( val ref: Ref, - private val world: String, + private val world: Var, private val activeTimes: List, ) : AudienceFilter(ref), TickableDisplay { override fun filter(player: Player): Boolean { - if (player.world.name != world) return false + if (player.world.uid.toString() != world.get(player).identifier) return false val worldTime = player.world.time % 24000 return activeTimes.any { worldTime in it } } @@ -63,19 +64,16 @@ class GameTimeAudienceFilter( event.player.refresh() } - override fun tick() { - val world = server.getWorld(world) + override fun onPlayerAdd(player: Player) { + super.onPlayerAdd(player) + val world = server.getWorld(world.get(player).identifier) if (world == null) { logger.warning("World '${this.world}' does not exist, $ref will not work.") - return } + } - val isActive = activeTimes.any { world.time % 24000 in it } - if (isActive && consideredPlayers.isNotEmpty() && players.isEmpty()) { - consideredPlayers.forEach { it.refresh() } - } else if (!isActive && players.isNotEmpty()) { - players.forEach { it.updateFilter(false) } - } + override fun tick() { + consideredPlayers.forEach { it.refresh() } } } diff --git a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/audience/HoldingItemAudienceEntry.kt b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/audience/HoldingItemAudienceEntry.kt index 767a8180c8..1de0f24b7c 100644 --- a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/audience/HoldingItemAudienceEntry.kt +++ b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/audience/HoldingItemAudienceEntry.kt @@ -5,11 +5,8 @@ import com.typewritermc.core.books.pages.Colors import com.typewritermc.core.extension.annotations.Entry import com.typewritermc.core.extension.annotations.Help import com.typewritermc.core.entries.Ref -import com.typewritermc.engine.paper.entry.entries.AudienceEntry -import com.typewritermc.engine.paper.entry.entries.AudienceFilter -import com.typewritermc.engine.paper.entry.entries.AudienceFilterEntry -import com.typewritermc.engine.paper.entry.entries.Invertible import com.typewritermc.core.entries.ref +import com.typewritermc.engine.paper.entry.entries.* import com.typewritermc.engine.paper.utils.item.Item import org.bukkit.entity.Player import org.bukkit.event.EventHandler @@ -35,7 +32,7 @@ class HoldingItemAudienceEntry( override val name: String = "", override val children: List> = emptyList(), @Help("The item to check for.") - val item: Item = Item.Empty, + val item: Var = ConstVar(Item.Empty), override val inverted: Boolean = false, ) : AudienceFilterEntry, Invertible { override fun display(): AudienceFilter = HoldingItemAudienceFilter(ref(), item) @@ -43,18 +40,18 @@ class HoldingItemAudienceEntry( class HoldingItemAudienceFilter( ref: Ref, - private val item: Item, + private val item: Var, ) : AudienceFilter(ref) { override fun filter(player: Player): Boolean { val holdingItem = player.inventory.itemInMainHand - return item.isSameAs(player, holdingItem) + return item.get(player).isSameAs(player, holdingItem) } @EventHandler fun onPlayerItemHeld(event: PlayerItemHeldEvent) { val player = event.player val newHoldingItem = player.inventory.getItem(event.newSlot) - player.updateFilter(item.isSameAs(player, newHoldingItem)) + player.updateFilter(item.get(player).isSameAs(player, newHoldingItem)) } @EventHandler diff --git a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/audience/ItemInInventoryAudienceEntry.kt b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/audience/ItemInInventoryAudienceEntry.kt index fc008874f5..c6a4f30f72 100644 --- a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/audience/ItemInInventoryAudienceEntry.kt +++ b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/audience/ItemInInventoryAudienceEntry.kt @@ -24,7 +24,7 @@ class ItemInInventoryAudienceEntry( override val id: String = "", override val name: String = "", override val children: List> = emptyList(), - val item: Item = Item.Empty, + val item: Var = ConstVar(Item.Empty), override val inverted: Boolean = false, ) : AudienceFilterEntry, Invertible { override fun display(): AudienceFilter = ItemInInventoryAudienceFilter(ref(), item) @@ -32,9 +32,10 @@ class ItemInInventoryAudienceEntry( class ItemInInventoryAudienceFilter( ref: Ref, - private val item: Item, + private val item: Var, ) : AudienceFilter(ref), TickableDisplay { override fun filter(player: Player): Boolean { + val item = item.get(player) return player.inventory.contents.any { it != null && item.isSameAs(player, it) } || item.isSameAs(player, player.itemOnCursor) } diff --git a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/audience/ItemInSlotAudienceEntry.kt b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/audience/ItemInSlotAudienceEntry.kt index 520f1c9898..f1ed79ecc0 100644 --- a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/audience/ItemInSlotAudienceEntry.kt +++ b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/audience/ItemInSlotAudienceEntry.kt @@ -26,9 +26,9 @@ class ItemInSlotAudienceEntry( override val name: String = "", override val children: List> = emptyList(), @Help("The item to check for.") - val item: Item = Item.Empty, + val item: Var = ConstVar(Item.Empty), @Help("The slot to check.") - val slot: Int = 0, + val slot: Var = ConstVar(0), override val inverted: Boolean = false, ) : AudienceFilterEntry, Invertible { override fun display(): AudienceFilter = ItemInSlotAudienceFilter(ref(), item, slot) @@ -36,12 +36,12 @@ class ItemInSlotAudienceEntry( class ItemInSlotAudienceFilter( ref: Ref, - private val item: Item, - private val slot: Int, + private val item: Var, + private val slot: Var, ) : AudienceFilter(ref), TickableDisplay { override fun filter(player: Player): Boolean { - val itemInSlot = player.inventory.getItem(slot) ?: return false - return item.isSameAs(player, itemInSlot) + val itemInSlot = player.inventory.getItem(slot.get(player)) ?: return false + return item.get(player).isSameAs(player, itemInSlot) } override fun tick() { diff --git a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/audience/LocationObjectivesPathStream.kt b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/audience/LocationObjectivesPathStream.kt index cb969bb73c..a6cdd4834e 100644 --- a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/audience/LocationObjectivesPathStream.kt +++ b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/audience/LocationObjectivesPathStream.kt @@ -32,6 +32,6 @@ class LocationObjectivesPathStream( ) : AudienceEntry { override fun display(): AudienceDisplay = MultiPathStreamDisplay(road, endLocations = { player -> player.trackedShowingObjectives().filterIsInstance() - .map { it.targetLocation.toBukkitLocation() }.toList() + .map { it.targetLocation.get(player).toBukkitLocation() }.toList() }) } \ No newline at end of file diff --git a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/audience/SidebarEntry.kt b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/audience/SidebarEntry.kt index cc7c5855b9..b12bb90fb1 100644 --- a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/audience/SidebarEntry.kt +++ b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/audience/SidebarEntry.kt @@ -4,7 +4,9 @@ import com.typewritermc.core.books.pages.Colors import com.typewritermc.core.extension.annotations.Entry import com.typewritermc.core.entries.Ref import com.typewritermc.engine.paper.entry.entries.AudienceEntry +import com.typewritermc.engine.paper.entry.entries.ConstVar import com.typewritermc.engine.paper.entry.entries.SidebarEntry +import com.typewritermc.engine.paper.entry.entries.Var import java.util.* @Entry("sidebar", "Display a sidebar for players", Colors.DARK_ORANGE, "mdi:page-layout-sidebar-right") @@ -20,6 +22,6 @@ class SimpleSidebarEntry( override val id: String = "", override val name: String = "", override val children: List> = emptyList(), - override val title: String = "", + override val title: Var = ConstVar(""), override val priorityOverride: Optional = Optional.empty(), ) : SidebarEntry \ No newline at end of file diff --git a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/audience/SimpleLinesEntry.kt b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/audience/SimpleLinesEntry.kt index 71f7c26bbe..a9c0f07c5e 100644 --- a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/audience/SimpleLinesEntry.kt +++ b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/audience/SimpleLinesEntry.kt @@ -6,7 +6,9 @@ import com.typewritermc.core.extension.annotations.Colored import com.typewritermc.core.extension.annotations.Help import com.typewritermc.core.extension.annotations.MultiLine import com.typewritermc.core.extension.annotations.Placeholder +import com.typewritermc.engine.paper.entry.entries.ConstVar import com.typewritermc.engine.paper.entry.entries.LinesEntry +import com.typewritermc.engine.paper.entry.entries.Var import org.bukkit.entity.Player import java.util.* @@ -26,8 +28,8 @@ class SimpleLinesEntry( @Colored @Placeholder @MultiLine - val lines: String = "", + val lines: Var = ConstVar(""), override val priorityOverride: Optional = Optional.empty(), ) : LinesEntry { - override fun lines(player: Player): String = lines + override fun lines(player: Player): String = lines.get(player) } \ No newline at end of file diff --git a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/audience/TimerAudienceEntry.kt b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/audience/TimerAudienceEntry.kt index 21e276b96f..89b0893d62 100644 --- a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/audience/TimerAudienceEntry.kt +++ b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/audience/TimerAudienceEntry.kt @@ -9,6 +9,8 @@ import com.typewritermc.engine.paper.entry.TriggerableEntry import com.typewritermc.core.entries.emptyRef import com.typewritermc.engine.paper.entry.entries.AudienceDisplay import com.typewritermc.engine.paper.entry.entries.AudienceEntry +import com.typewritermc.engine.paper.entry.entries.ConstVar +import com.typewritermc.engine.paper.entry.entries.Var import com.typewritermc.engine.paper.entry.triggerFor import com.typewritermc.engine.paper.logger import com.typewritermc.engine.paper.utils.ThreadType @@ -35,19 +37,20 @@ import java.util.* class TimerAudienceEntry( override val id: String = "", override val name: String = "", - val duration: Duration = Duration.ofSeconds(1), + val duration: Var = ConstVar(Duration.ofSeconds(1)), val onTimer: Ref = emptyRef(), ) : AudienceEntry { override fun display(): AudienceDisplay = TimerAudienceDisplay(duration, onTimer) } class TimerAudienceDisplay( - private val duration: Duration, + private val duration: Var, private val onTimer: Ref, ) : AudienceDisplay() { private val jobs = mutableMapOf() override fun onPlayerAdd(player: Player) { + val duration = duration.get(player) if (duration.isZero || duration.isNegative) { logger.warning("Timer duration must be positive, otherwise it will infinitely trigger.") return diff --git a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/audience/WeatherAudienceEntry.kt b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/audience/WeatherAudienceEntry.kt index 00269684ec..431c3ac55e 100644 --- a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/audience/WeatherAudienceEntry.kt +++ b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/audience/WeatherAudienceEntry.kt @@ -4,6 +4,8 @@ import com.typewritermc.core.books.pages.Colors import com.typewritermc.core.extension.annotations.Entry import com.typewritermc.engine.paper.entry.entries.AudienceDisplay import com.typewritermc.engine.paper.entry.entries.AudienceEntry +import com.typewritermc.engine.paper.entry.entries.ConstVar +import com.typewritermc.engine.paper.entry.entries.Var import org.bukkit.WeatherType import org.bukkit.entity.Player import org.bukkit.event.EventHandler @@ -19,22 +21,22 @@ import org.bukkit.event.player.PlayerChangedWorldEvent class WeatherAudienceEntry( override val id: String = "", override val name: String = "", - val weather: WeatherType = WeatherType.DOWNFALL, + val weather: Var = ConstVar(WeatherType.DOWNFALL), ) : AudienceEntry { override fun display(): AudienceDisplay = WeatherAudienceDisplay(weather) } class WeatherAudienceDisplay( - private val weather: WeatherType, + private val weather: Var, ) : AudienceDisplay() { override fun onPlayerAdd(player: Player) { - player.setPlayerWeather(weather) + player.setPlayerWeather(weather.get(player)) } @EventHandler fun onWorldChange(event: PlayerChangedWorldEvent) { if (event.player !in this) return - event.player.setPlayerWeather(weather) + event.player.setPlayerWeather(weather.get(event.player)) } override fun onPlayerRemove(player: Player) { diff --git a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/cinematic/DisplayDialogueCinematicAction.kt b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/cinematic/DisplayDialogueCinematicAction.kt index 744defab5c..4f3f4740ef 100644 --- a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/cinematic/DisplayDialogueCinematicAction.kt +++ b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/cinematic/DisplayDialogueCinematicAction.kt @@ -18,21 +18,21 @@ import org.bukkit.entity.Player data class SingleLineDisplayDialogueSegment( override val startFrame: Int = 0, override val endFrame: Int = 0, - override val text: String = "", + override val text: Var = ConstVar(""), ) : DisplayDialogueSegment data class MultiLineDisplayDialogueSegment( override val startFrame: Int = 0, override val endFrame: Int = 0, @MultiLine - override val text: String = "", + override val text: Var = ConstVar(""), ) : DisplayDialogueSegment interface DisplayDialogueSegment : Segment { @Placeholder @Colored @Help("The text to display to the player.") - val text: String + val text: Var } @Deprecated("Replaced with RandomVariable") @@ -40,9 +40,9 @@ data class SingleLineRandomDisplayDialogueSegment( override val startFrame: Int = 0, override val endFrame: Int = 0, override val texts: List = emptyList(), -): RandomDisplayDialogueSegment { +) : RandomDisplayDialogueSegment { override fun toDisplaySegment(): DisplayDialogueSegment { - return SingleLineDisplayDialogueSegment(startFrame, endFrame, texts.random()) + return SingleLineDisplayDialogueSegment(startFrame, endFrame, ConstVar(texts.random())) } } @@ -52,9 +52,9 @@ data class MultiLineRandomDisplayDialogueSegment( override val endFrame: Int = 0, @MultiLine override val texts: List = emptyList(), -): RandomDisplayDialogueSegment { +) : RandomDisplayDialogueSegment { override fun toDisplaySegment(): DisplayDialogueSegment { - return MultiLineDisplayDialogueSegment(startFrame, endFrame, texts.random()) + return MultiLineDisplayDialogueSegment(startFrame, endFrame, ConstVar(texts.random())) } } @@ -83,6 +83,7 @@ class DisplayDialogueCinematicAction( ) : CinematicAction { private var previousSegment: DisplayDialogueSegment? = null private var state: PlayerState? = null + private var displayText = "" override suspend fun setup() { super.setup() @@ -101,6 +102,7 @@ class DisplayDialogueCinematicAction( player.exp = 0f player.level = 0 reset?.invoke(player) + displayText = "" previousSegment = null } return @@ -110,6 +112,7 @@ class DisplayDialogueCinematicAction( player.exp = 1f player.playSpeakerSound(speaker) previousSegment = segment + displayText = segment.text.get(player).parsePlaceholders(player) } val percentage = segment percentageAt frame @@ -125,9 +128,7 @@ class DisplayDialogueCinematicAction( if (!needsDisplay) return } - val text = segment.text.parsePlaceholders(player) - - display(player, speaker?.displayName?.parsePlaceholders(player) ?: "", text, displayPercentage) + display(player, speaker?.displayName?.get(player)?.parsePlaceholders(player) ?: "", displayText, displayPercentage) } override suspend fun teardown() { diff --git a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/cinematic/ParticleCinematicEntry.kt b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/cinematic/ParticleCinematicEntry.kt index 76f15ceec7..d778c75e09 100644 --- a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/cinematic/ParticleCinematicEntry.kt +++ b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/cinematic/ParticleCinematicEntry.kt @@ -3,9 +3,9 @@ package com.typewritermc.basic.entries.cinematic import com.typewritermc.core.books.pages.Colors import com.typewritermc.core.extension.annotations.Entry import com.typewritermc.core.extension.annotations.Help -import com.typewritermc.core.extension.annotations.Negative import com.typewritermc.core.extension.annotations.Segments import com.typewritermc.core.utils.point.Position +import com.typewritermc.core.utils.point.Vector import com.typewritermc.engine.paper.entry.Criteria import com.typewritermc.engine.paper.entry.entries.* import com.typewritermc.engine.paper.utils.toBukkitLocation @@ -26,18 +26,13 @@ class ParticleCinematicEntry( override val id: String = "", override val name: String = "", override val criteria: List = emptyList(), - val location: Position = Position.ORIGIN, - val particle: Particle = Particle.FLAME, + val location: Var = ConstVar(Position.ORIGIN), + val particle: Var = ConstVar(Particle.FLAME), @Help("The amount of particles to spawn every tick.") - val count: Int = 1, - @Negative - val offsetX: Double = 0.0, - @Negative - val offsetY: Double = 0.0, - @Negative - val offsetZ: Double = 0.0, + val count: Var = ConstVar(1), + val offset: Var = ConstVar(Vector.ZERO), @Help("The speed of the particles. For some particles, this is the \"extra\" data value to control particle behavior.") - val speed: Double = 0.0, + val speed: Var = ConstVar(0.0), @Segments(icon = "fa6-solid:fire-flame-simple") val segments: List = emptyList(), ) : CinematicEntry { @@ -64,13 +59,13 @@ class ParticleCinematicAction( (entry.segments activeSegmentAt frame) ?: return player.spawnParticle( - entry.particle, - entry.location.toBukkitLocation(), - entry.count, - entry.offsetX, - entry.offsetY, - entry.offsetZ, - entry.speed + entry.particle.get(player), + entry.location.get(player).toBukkitLocation(), + entry.count.get(player), + entry.offset.get(player).x, + entry.offset.get(player).y, + entry.offset.get(player).z, + entry.speed.get(player), ) } diff --git a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/cinematic/PotionEffectCinematicEntry.kt b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/cinematic/PotionEffectCinematicEntry.kt index 2af30bf115..017d8e4e2b 100644 --- a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/cinematic/PotionEffectCinematicEntry.kt +++ b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/cinematic/PotionEffectCinematicEntry.kt @@ -7,9 +7,7 @@ import com.typewritermc.core.extension.annotations.Help import com.typewritermc.core.extension.annotations.Segments import com.typewritermc.engine.paper.entry.Criteria import com.typewritermc.engine.paper.entry.cinematic.SimpleCinematicAction -import com.typewritermc.engine.paper.entry.entries.CinematicAction -import com.typewritermc.engine.paper.entry.entries.PrimaryCinematicEntry -import com.typewritermc.engine.paper.entry.entries.Segment +import com.typewritermc.engine.paper.entry.entries.* import com.typewritermc.engine.paper.utils.EffectStateProvider import com.typewritermc.engine.paper.utils.PlayerState import com.typewritermc.engine.paper.utils.ThreadType.SYNC @@ -51,9 +49,9 @@ class PotionEffectCinematicEntry( data class PotionEffectSegment( override val startFrame: Int = 0, override val endFrame: Int = 0, - val potionEffectType: PotionEffectType = PotionEffectType.BLINDNESS, + val potionEffectType: Var = ConstVar(PotionEffectType.BLINDNESS), @Default("1") - val strength: Int = 1, + val strength: Var = ConstVar(1), val ambient: Boolean = false, val particles: Boolean = false, @Help("Whether the icon should be displayed in the top left corner of the screen.") @@ -71,14 +69,15 @@ class PotionEffectCinematicAction( override suspend fun startSegment(segment: PotionEffectSegment) { super.startSegment(segment) - state = player.state(EffectStateProvider(segment.potionEffectType)) + val potionEffectType = segment.potionEffectType.get(player) + state = player.state(EffectStateProvider(potionEffectType)) SYNC.switchContext { player.addPotionEffect( PotionEffect( - segment.potionEffectType, + potionEffectType, 10000000, - segment.strength, + segment.strength.get(player), segment.ambient, segment.particles, segment.icon diff --git a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/cinematic/SetFakeBlockCinematicEntry.kt b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/cinematic/SetFakeBlockCinematicEntry.kt index 0e42e00475..bb57d620c2 100644 --- a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/cinematic/SetFakeBlockCinematicEntry.kt +++ b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/cinematic/SetFakeBlockCinematicEntry.kt @@ -8,9 +8,7 @@ import com.typewritermc.core.extension.annotations.Segments import com.typewritermc.core.utils.point.Position import com.typewritermc.engine.paper.entry.Criteria import com.typewritermc.engine.paper.entry.cinematic.SimpleCinematicAction -import com.typewritermc.engine.paper.entry.entries.CinematicAction -import com.typewritermc.engine.paper.entry.entries.CinematicEntry -import com.typewritermc.engine.paper.entry.entries.Segment +import com.typewritermc.engine.paper.entry.entries.* import com.typewritermc.engine.paper.extensions.packetevents.sendPacketTo import com.typewritermc.engine.paper.utils.toBukkitLocation import com.typewritermc.engine.paper.utils.toPacketVector3i @@ -35,8 +33,8 @@ class SetFakeBlockCinematicEntry( data class SetFakeBlockSegment( override val startFrame: Int = 0, override val endFrame: Int = 0, - val location: Position = Position.ORIGIN, - val block: Material = Material.AIR, + val location: Var = ConstVar(Position.ORIGIN), + val block: Var = ConstVar(Material.AIR), ) : Segment class SetFakeBlockCinematicAction( @@ -44,19 +42,21 @@ class SetFakeBlockCinematicAction( entry: SetFakeBlockCinematicEntry, ) : SimpleCinematicAction() { override val segments: List = entry.segments + private var lastLocation: Position? = null override suspend fun startSegment(segment: SetFakeBlockSegment) { super.startSegment(segment) - val state = SpigotConversionUtil.fromBukkitBlockData(segment.block.createBlockData()) - val packet = WrapperPlayServerBlockChange(segment.location.toPacketVector3i(), state.globalId) + lastLocation = segment.location.get(player) + val state = SpigotConversionUtil.fromBukkitBlockData(segment.block.get(player).createBlockData()) + val packet = WrapperPlayServerBlockChange(lastLocation!!.toPacketVector3i(), state.globalId) packet.sendPacketTo(player) } override suspend fun stopSegment(segment: SetFakeBlockSegment) { super.stopSegment(segment) - val bukkitLocation = segment.location.toBukkitLocation() + val bukkitLocation = lastLocation?.toBukkitLocation() ?: return player.sendBlockChange(bukkitLocation, bukkitLocation.block.blockData) } } diff --git a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/cinematic/SoundCinematicEntry.kt b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/cinematic/SoundCinematicEntry.kt index 47b5e39b59..5778e9b44b 100644 --- a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/cinematic/SoundCinematicEntry.kt +++ b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/cinematic/SoundCinematicEntry.kt @@ -5,9 +5,7 @@ import com.typewritermc.engine.paper.entry.Criteria import com.typewritermc.core.extension.annotations.Entry import com.typewritermc.core.extension.annotations.Segments import com.typewritermc.engine.paper.entry.cinematic.SimpleCinematicAction -import com.typewritermc.engine.paper.entry.entries.CinematicAction -import com.typewritermc.engine.paper.entry.entries.CinematicEntry -import com.typewritermc.engine.paper.entry.entries.Segment +import com.typewritermc.engine.paper.entry.entries.* import com.typewritermc.engine.paper.utils.* import org.bukkit.entity.Player @@ -35,24 +33,26 @@ class SoundCinematicEntry( } data class SoundSegment( - override val startFrame: Int, - override val endFrame: Int, - val sound: Sound, + override val startFrame: Int = 0, + override val endFrame: Int = 0, + val sound: Var = ConstVar(Sound.EMPTY), ) : Segment class SoundCinematicAction( private val player: Player, - private val entry: SoundCinematicEntry, + entry: SoundCinematicEntry, ) : SimpleCinematicAction() { override val segments: List = entry.segments + private var previousSound: Sound? = null override suspend fun startSegment(segment: SoundSegment) { super.startSegment(segment) - player.playSound(segment.sound) + previousSound = segment.sound.get(player) + player.playSound(previousSound!!) } override suspend fun stopSegment(segment: SoundSegment) { super.stopSegment(segment) - player.stopSound(segment.sound) + previousSound?.let { player.stopSound(it) } } } \ No newline at end of file diff --git a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/cinematic/TitleCinematicEntry.kt b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/cinematic/TitleCinematicEntry.kt index 000745ff7f..0c0510890c 100644 --- a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/cinematic/TitleCinematicEntry.kt +++ b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/cinematic/TitleCinematicEntry.kt @@ -2,13 +2,12 @@ package com.typewritermc.basic.entries.cinematic import io.papermc.paper.util.Tick import com.typewritermc.core.books.pages.Colors +import com.typewritermc.core.extension.annotations.Default import com.typewritermc.core.extension.annotations.Entry import com.typewritermc.core.extension.annotations.Segments import com.typewritermc.engine.paper.entry.Criteria import com.typewritermc.engine.paper.entry.cinematic.SimpleCinematicAction -import com.typewritermc.engine.paper.entry.entries.CinematicAction -import com.typewritermc.engine.paper.entry.entries.PrimaryCinematicEntry -import com.typewritermc.engine.paper.entry.entries.Segment +import com.typewritermc.engine.paper.entry.entries.* import com.typewritermc.engine.paper.extensions.placeholderapi.parsePlaceholders import com.typewritermc.engine.paper.utils.asMini import net.kyori.adventure.title.Title @@ -41,9 +40,11 @@ class TitleCinematicEntry( data class TitleSegment( override val startFrame: Int = 0, override val endFrame: Int = 0, - val title: String = "", - val subtitle: String = "", + val title: Var = ConstVar(""), + val subtitle: Var = ConstVar(""), + @Default("20") val fadeIn: Long = 20, + @Default("20") val fadeOut: Long = 20, ) : Segment @@ -67,8 +68,8 @@ class TitleCinematicAction( ) val title: Title = Title.title( - segment.title.parsePlaceholders(player).asMini(), - segment.subtitle.parsePlaceholders(player).asMini(), + segment.title.get(player).parsePlaceholders(player).asMini(), + segment.subtitle.get(player).parsePlaceholders(player).asMini(), times ) diff --git a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/dialogue/ActionBarDialogueEntry.kt b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/dialogue/ActionBarDialogueEntry.kt index d871f0daa2..bf056c1dd3 100644 --- a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/dialogue/ActionBarDialogueEntry.kt +++ b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/dialogue/ActionBarDialogueEntry.kt @@ -9,8 +9,10 @@ import com.typewritermc.core.extension.annotations.Placeholder import com.typewritermc.engine.paper.entry.Criteria import com.typewritermc.engine.paper.entry.Modifier import com.typewritermc.engine.paper.entry.TriggerableEntry +import com.typewritermc.engine.paper.entry.entries.ConstVar import com.typewritermc.engine.paper.entry.entries.DialogueEntry import com.typewritermc.engine.paper.entry.entries.SpeakerEntry +import com.typewritermc.engine.paper.entry.entries.Var import java.time.Duration @Entry("action_bar_dialogue", "An action bar dialogue", "#1E88E5", "fa6-solid:xmarks-lines") @@ -30,7 +32,7 @@ class ActionBarDialogueEntry( override val speaker: Ref = emptyRef(), @Colored @Placeholder - val text: String = "", + val text: Var = ConstVar(""), @Help("The duration it takes to type out the message.") - val duration: Duration = Duration.ZERO, + val duration: Var = ConstVar(Duration.ZERO), ) : DialogueEntry \ No newline at end of file diff --git a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/dialogue/MessageDialogue.kt b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/dialogue/MessageDialogue.kt index 0b3f893c6f..9d918d5031 100644 --- a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/dialogue/MessageDialogue.kt +++ b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/dialogue/MessageDialogue.kt @@ -8,8 +8,10 @@ import com.typewritermc.core.extension.annotations.Placeholder import com.typewritermc.engine.paper.entry.Criteria import com.typewritermc.engine.paper.entry.Modifier import com.typewritermc.engine.paper.entry.TriggerableEntry +import com.typewritermc.engine.paper.entry.entries.ConstVar import com.typewritermc.engine.paper.entry.entries.DialogueEntry import com.typewritermc.engine.paper.entry.entries.SpeakerEntry +import com.typewritermc.engine.paper.entry.entries.Var @Entry("message", "Display a single message to the player", "#1c4da3", "ic:baseline-comment-bank") /** @@ -29,5 +31,5 @@ class MessageDialogueEntry( @MultiLine @Placeholder @Colored - val text: String = "", + val text: Var = ConstVar(""), ) : DialogueEntry \ No newline at end of file diff --git a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/dialogue/OptionDialogueEntry.kt b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/dialogue/OptionDialogueEntry.kt index 8618d630f0..9edac05f6e 100644 --- a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/dialogue/OptionDialogueEntry.kt +++ b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/dialogue/OptionDialogueEntry.kt @@ -8,8 +8,10 @@ import com.typewritermc.core.extension.annotations.Placeholder import com.typewritermc.engine.paper.entry.Criteria import com.typewritermc.engine.paper.entry.Modifier import com.typewritermc.engine.paper.entry.TriggerableEntry +import com.typewritermc.engine.paper.entry.entries.ConstVar import com.typewritermc.engine.paper.entry.entries.DialogueEntry import com.typewritermc.engine.paper.entry.entries.SpeakerEntry +import com.typewritermc.engine.paper.entry.entries.Var import java.time.Duration @Entry("option", "Display a list of options to the player", "#4CAF50", "fa6-solid:list") @@ -29,15 +31,15 @@ class OptionDialogueEntry( override val speaker: Ref = emptyRef(), @Placeholder @Colored - val text: String = "", + val text: Var = ConstVar(""), val options: List