Most Hytale plugins register custom commands. HRTK lets you execute commands programmatically with a MockCommandSender, inspect the output messages, and assert on success or failure - all without a real player connection.
The MockCommandSender is the key tool here. It acts as a fake player or console sender that captures every message the command sends back. You can configure its permissions to test both authorized and unauthorized access, and you can inspect the captured messages to verify the command produced the right output.
How MockCommandSender Message Capture Works
When a command handler calls sender.sendMessage("some text"), the real server sends that message over the network to the client. With a MockCommandSender, the message is instead stored in an internal list. After the command executes, you can read sender.getMessages() to see everything the command sent, sender.getLastMessage() for the most recent output, or sender.hasReceivedMessage("substring") to search through all captured messages.
This approach lets you test command output without parsing network packets or connecting a real client.
Complete Example Suite
MockCommandSender Methods
| Method | Description |
|---|
getMessages() | All messages sent to this sender, in order |
getLastMessage() | Last message sent, or null |
hasReceivedMessage(substring) | Check if any message contains the substring |
clearMessages() | Clear all captured messages |
getPermissions() | Get the set of granted permissions |
hasPermission(perm) | Check for a specific permission |
addPermission(perm) | Grant a permission |
removePermission(perm) | Revoke a permission |
getName() | Display name of the sender |
CommandAssert Methods
| Method | Description |
|---|
assertCommandSucceeds(ctx, sender, cmd) | Execute command and assert no exception |
assertCommandFails(ctx, sender, cmd) | Execute command and assert it throws |
assertCommandFailsWithMessage(ctx, sender, cmd, msg) | Assert failure contains expected message |
assertSenderReceivedMessage(sender, substring) | Assert sender got a message containing text |
assertSenderReceivedMessageCount(sender, count) | Assert sender received exactly N messages |
Executing Commands
Besides using CommandAssert, you can execute commands directly through the context:
The command string is dispatched through the server’s command system. The sender receives any output messages that the command sends.
executeCommand() dispatches through the real Hytale command system. If the command is not registered or the sender lacks permission, the behavior matches what would happen in production.
Next Steps