Skip to content

Commit

Permalink
Execute each server command on subsequent ticks
Browse files Browse the repository at this point in the history
  • Loading branch information
4Ply committed Jul 12, 2024
1 parent aea4851 commit e3eb602
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/main/kotlin/org/trackedout/citadel/ScheduledTaskRunner.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class ScheduledTaskRunner(
}

"execute-command" -> {
runCommandsOnSubsequentTicks(ArrayDeque(task.arguments!!))
task.arguments?.forEach {
plugin.logger.info("Executing command from dunga-dunga: $it")
plugin.server.dispatchCommand(plugin.server.consoleSender, it)
Expand Down Expand Up @@ -91,6 +92,28 @@ class ScheduledTaskRunner(
}
}.runTask(plugin)
}

private fun runCommandsOnSubsequentTicks(commands: ArrayDeque<String>) {
object : BukkitRunnable() {
override fun run() {
if (commands.isEmpty()) {
return
}

val command = commands.removeFirst()
try {
plugin.logger.info("Running command: $command")
plugin.server.dispatchCommand(plugin.server.consoleSender, command)
plugin.logger.info("Successfully executed command: $command")

runCommandsOnSubsequentTicks(commands)
} catch (e: Exception) {
plugin.logger.severe("Failed to execute command: $command")
e.printStackTrace()
}
}
}.runTask(plugin)
}
}

fun Task.updateState(api: TasksApi, state: String) {
Expand Down

0 comments on commit e3eb602

Please sign in to comment.