Skip to content

Commit

Permalink
Move fire command to extension & allow for dialogue continuation
Browse files Browse the repository at this point in the history
  • Loading branch information
gabber235 committed Dec 22, 2024
1 parent 0fa5a5b commit dc02fb8
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import com.typewritermc.core.entries.Entry
import com.typewritermc.core.entries.Page
import com.typewritermc.core.entries.Query
import com.typewritermc.core.entries.formattedName
import com.typewritermc.core.interaction.context
import com.typewritermc.engine.paper.entry.TriggerableEntry
import com.typewritermc.engine.paper.entry.audienceState
import com.typewritermc.engine.paper.entry.entries.*
import com.typewritermc.engine.paper.entry.inAudience
import com.typewritermc.engine.paper.entry.temporal.temporalCommands
import com.typewritermc.engine.paper.entry.triggerFor
import com.typewritermc.engine.paper.interaction.chatHistory
import com.typewritermc.core.interaction.context
import com.typewritermc.engine.paper.ui.CommunicationHandler
import com.typewritermc.engine.paper.utils.ThreadType
import com.typewritermc.engine.paper.utils.asMini
Expand Down Expand Up @@ -43,7 +43,6 @@ fun typeWriterCommand() = commandTree("typewriter") {
clearChatCommand()
connectCommand()
triggerCommand()
fireCommand()
manifestCommands()
temporalCommands()

Expand Down Expand Up @@ -258,21 +257,6 @@ private fun CommandTree.triggerCommand() = literalArgument("trigger") {
}
}

private fun CommandTree.fireCommand() = literalArgument("fire") {
withPermission("typewriter.fire")

argument(entryArgument<FireTriggerEventEntry>("entry")) {
optionalTarget {
anyExecutor { sender, args ->
val target = args.targetOrSelfPlayer(sender) ?: return@anyExecutor
val entry = args["entry"] as FireTriggerEventEntry
entry.eventTriggers.triggerFor(target, context())
}
}
}
}


private fun CommandTree.manifestCommands() = literalArgument("manifest") {
literalArgument("inspect") {
withPermission("typewriter.manifest.inspect")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ interface CustomCommandEntry : EventEntry {
companion object
}

interface FireTriggerEventEntry : EventEntry

class Event(val player: Player, val context: InteractionContext, val triggers: List<EventTrigger>) {
constructor(player: Player, context: InteractionContext, vararg triggers: EventTrigger) : this(
player,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,66 @@
package com.typewritermc.basic.entries.event

import com.typewritermc.core.books.pages.Colors
import com.typewritermc.core.extension.annotations.Entry
import com.typewritermc.core.entries.Ref
import com.typewritermc.core.extension.annotations.Entry
import com.typewritermc.core.extension.annotations.TypewriterCommand
import com.typewritermc.core.interaction.context
import com.typewritermc.engine.paper.entry.TriggerableEntry
import com.typewritermc.engine.paper.entry.entries.FireTriggerEventEntry
import com.typewritermc.engine.paper.entry.entries.EventEntry
import com.typewritermc.engine.paper.entry.startDialogueWithOrNextDialogue
import com.typewritermc.engine.paper.entry.triggerFor
import com.typewritermc.engine.paper.entryArgument
import com.typewritermc.engine.paper.optionalTarget
import com.typewritermc.engine.paper.targetOrSelfPlayer
import dev.jorel.commandapi.CommandTree
import dev.jorel.commandapi.kotlindsl.anyExecutor
import dev.jorel.commandapi.kotlindsl.argument
import dev.jorel.commandapi.kotlindsl.literalArgument

@Entry("fire_trigger_event", "Trigger the event when a player runs `/tw fire <entry id/name> [player]`", Colors.YELLOW, "mingcute:firework-fill")
@Entry(
"fire_trigger_event",
"Trigger the event when a player runs `/tw fire <entry id/name> [player]`",
Colors.YELLOW,
"mingcute:firework-fill"
)
/**
* The `FireTriggerEventEntry` is an event that fires its triggers when the player runs `/tw fire <entry id/name> [player]`
* The `FireTriggerEventEntry` is an event that fires its triggers when the player runs `/tw fire <entry id/name> [force] [player]`
*
* By default, the event will only trigger if the player is not in a dialogue.
* If they are in a dialogue, the event will trigger the next dialogue.
* This is to allow things like npcs to trigger this event and still continue the conversation.
*
* If you want to force the event to trigger, you can use `/tw fire <entry id/name> force [player]`
*
* ## How could this be used?
* This could be used to trigger an event when a player runs `/tw fire <entry id/name> [player]`
* This could be used to trigger an event when a player runs `/tw fire <entry id/name> [force] [player]`
*/
class FireTriggerEventEntry(
override val id: String = "",
override val name: String = "",
override val triggers: List<Ref<TriggerableEntry>> = emptyList(),
) : FireTriggerEventEntry
) : EventEntry

@TypewriterCommand
fun CommandTree.fireCommand() = literalArgument("fire") {
withPermission("typewriter.fire")

argument(entryArgument<FireTriggerEventEntry>("entry")) {
optionalTarget {
anyExecutor { sender, args ->
val target = args.targetOrSelfPlayer(sender) ?: return@anyExecutor
val entry = args["entry"] as FireTriggerEventEntry
listOf(entry).startDialogueWithOrNextDialogue(target, context())
}
}
literalArgument("force") {
optionalTarget {
anyExecutor { sender, args ->
val target = args.targetOrSelfPlayer(sender) ?: return@anyExecutor
val entry = args["entry"] as FireTriggerEventEntry
entry.eventTriggers.triggerFor(target, context())
}
}
}
}
}

0 comments on commit dc02fb8

Please sign in to comment.