Skip to content

Commit

Permalink
Allow multiple commands in a single entry
Browse files Browse the repository at this point in the history
  • Loading branch information
gabber235 committed Nov 26, 2023
1 parent f9ac967 commit 2a2a644
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import lirand.api.extensions.server.commands.dispatchCommand
import me.gabber235.typewriter.adapters.Colors
import me.gabber235.typewriter.adapters.Entry
import me.gabber235.typewriter.adapters.modifiers.Help
import me.gabber235.typewriter.adapters.modifiers.MultiLine
import me.gabber235.typewriter.adapters.modifiers.Placeholder
import me.gabber235.typewriter.entry.Criteria
import me.gabber235.typewriter.entry.Modifier
Expand All @@ -30,15 +31,19 @@ class ConsoleCommandActionEntry(
override val modifiers: List<Modifier> = emptyList(),
override val triggers: List<String> = emptyList(),
@Placeholder
@Help("The command to run. (Use %player_name% for the player's name)")
// The command that the console will run.
@MultiLine
@Help("The command(s) to run.")
// Every line is a different command. Commands should not be prefixed with <code>/</code>.
private val command: String = "",
) : ActionEntry {
override fun execute(player: Player) {
super.execute(player)
// Run in the main thread
plugin.launch {
Bukkit.getConsoleSender().dispatchCommand(command.parsePlaceholders(player))
val commands = command.parsePlaceholders(player).lines()
for (cmd in commands) {
Bukkit.getConsoleSender().dispatchCommand(cmd)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import lirand.api.extensions.server.commands.dispatchCommand
import me.gabber235.typewriter.adapters.Colors
import me.gabber235.typewriter.adapters.Entry
import me.gabber235.typewriter.adapters.modifiers.Help
import me.gabber235.typewriter.adapters.modifiers.MultiLine
import me.gabber235.typewriter.adapters.modifiers.Placeholder
import me.gabber235.typewriter.entry.Criteria
import me.gabber235.typewriter.entry.Modifier
Expand Down Expand Up @@ -35,15 +36,19 @@ class PlayerCommandActionEntry(
override val modifiers: List<Modifier> = emptyList(),
override val triggers: List<String> = emptyList(),
@Placeholder
@Help("The command to run. (Use %player_name% for the player's name)")
// The command that the player will run.
@MultiLine
@Help("The command(s) to run.")
// Every line is a different command. Commands should not be prefixed with <code>/</code>.
private val command: String = "",
) : ActionEntry {
override fun execute(player: Player) {
super.execute(player)
// Run in main thread
plugin.launch {
player.dispatchCommand(command.parsePlaceholders(player))
val commands = command.parsePlaceholders(player).lines()
for (cmd in commands) {
player.dispatchCommand(cmd)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,10 @@ class CinematicPlayerCommandEntry(
data class CommandSegment(
override val startFrame: Int,
override val endFrame: Int,
@Help("The command to run")
@Help("The command(s) to run.")
@Placeholder
@MultiLine
// Every line is a different command. Commands should not be prefixed with <code>/</code>.
val command: String,
) : Segment

Expand All @@ -91,7 +93,8 @@ class CommandAction(
override suspend fun startSegment(segment: CommandSegment) {
super.startSegment(segment)
withContext(plugin.minecraftDispatcher) {
run(segment.command.parsePlaceholders(player))
val commands = segment.command.parsePlaceholders(player).lines()
commands.forEach(run)
}
}
}

0 comments on commit 2a2a644

Please sign in to comment.