CommandRunner

Runs a Minecraft command on the server thread and captures its chat feedback, for the run_command MCP tool. Vanilla mechanism throughout: a custom CommandSource collects the feedback the command would normally print, attached to a server-level (OP) CommandSourceStack, executed via Commands#performPrefixedCommand.

CommandSource.acceptsSuccess and acceptsFailure must both return true: sendSuccess/sendFailure check them first and silently drop the message otherwise, so feedback would never reach the sink method (sendSystemMessage, or sendMessage on 1.18.2). Returning true also bypasses the sendCommandFeedback gamerule (our source decides, not the world).

Every other CommandSource method goes to a real RconConsoleSource behind ours. A hybrid server is why: it adds a method asking the source for its Bukkit sender, and a plugin command checks permissions on that sender and prints to it. The RCON source's sender is an op, as the console is, and keeps what it is sent in the RCON buffer, which run returns exactly as it stands.

Types

Link copied to clipboard
private class Console(val server: MinecraftServer)

The console behind our source: the server's remote console, which on a hybrid hands plugins a Bukkit sender that keeps what they print. Built on first use — on a plain server a command rarely asks it anything. Its fields are written on the server thread and read after run's get(), which orders the two.

Link copied to clipboard
private class Line(val cmd: String, val feedback: List<String>, val console: CommandRunner.Console, val failure: String?)

One command line's outcome. console may still be collecting a plugin's answer until render reads it.

Properties

Link copied to clipboard
private const val BUKKIT_SENDER: String

What a hybrid's added method returns: a call asking for one means a plugin took the command.

Link copied to clipboard
private const val CAPTURE_WINDOW_MS: Long = 500

How long a batch a plugin took keeps collecting after it ran: a plugin may answer from its own thread (LuckPerms does). PaperCommandRunner's window, for the same reason.

Link copied to clipboard
private const val NOT_FOUND: String
Link copied to clipboard
private const val NOTE: String

Prefix on every line THIS class inserts, as ClientCommandRunner does for the client path, so a reader (the LLM) can tell our notes from real command feedback, which is never prefixed.

Functions

Link copied to clipboard
private fun capture(server: MinecraftServer, cmds: List<String>): List<CommandRunner.Line>?

Runs ON the server thread. All lines run in this single task, so they share one tick snapshot. A line that throws costs only itself, noted in its own output, as in PaperCommandRunner. Null where this runtime has no method to run commands with.

Link copied to clipboard
private fun feedbackSource(feedback: Set<String>, accepts: Set<String>, inform: String, sink: MutableList<Component>, console: CommandRunner.Console): CommandSource

A CommandSource proxy that appends every feedback Component to sink; the three name sets decide which reflected method is which on this runtime. Whatever else it is asked goes to console.

Link copied to clipboard
private fun render(lines: List<CommandRunner.Line>): String

Each line's output: what our source collected, then the RCON buffer exactly as it stands, then the line's failure. Called once the window has passed, so a plugin's late answer is in.

Link copied to clipboard
fun run(serverObj: Any?, command: String): String

Schedule command on the server thread (commands touch game state and Brigadier asserts the server thread) and block until its captured output arrives. Never throws — returns an explanatory string on any failure.