Skip to main content
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.

MockCommandSender

A fake command sender that captures messages and has configurable permissions. Create one via TestContext.
@HytaleTest
void testCommandSender(TestContext ctx) {
    MockCommandSender sender = ctx.createCommandSender();
    HytaleAssert.assertNotNull(sender);
    HytaleAssert.assertNotNull(sender.getName());
}

With permissions

MockCommandSender admin = ctx.createCommandSender("hrtk.admin", "mymod.manage");
HytaleAssert.assertTrue(admin.hasPermission("hrtk.admin"));
HytaleAssert.assertFalse(admin.hasPermission("ungranted.perm"));

MockCommandSender Methods

MethodDescription
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

MethodDescription
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

@RequiresPlayer

Annotate a test with @RequiresPlayer to indicate it needs player-like context. This is a marker for tests that exercise command logic requiring a player sender.
import com.frotty27.hrtk.api.annotation.RequiresPlayer;

@HytaleTest
@RequiresPlayer
void testPlayerCommand(TestContext ctx) {
    MockCommandSender sender = ctx.createCommandSender("mymod.use");
    CommandAssert.assertCommandSucceeds(ctx, sender, "/mymod info");
}

Examples

@HytaleTest
@RequiresPlayer
void listCommandWorks(TestContext ctx) {
    MockCommandSender sender = ctx.createCommandSender("hrtk.admin");
    CommandAssert.assertCommandSucceeds(ctx, sender, "/hrtk list");
    HytaleAssert.assertNotEmpty(sender.getMessages());
}
@HytaleTest
@RequiresPlayer
void commandFailsWithoutPermission(TestContext ctx) {
    MockCommandSender sender = ctx.createCommandSender(); // no permissions
    CommandAssert.assertCommandFails(ctx, sender, "/hrtk run");
}
@HytaleTest
@RequiresPlayer
void commandOutputContainsExpectedText(TestContext ctx) {
    MockCommandSender sender = ctx.createCommandSender("hrtk.admin");
    ctx.executeCommand("/hrtk list", sender);

    CommandAssert.assertSenderReceivedMessage(sender, "Plugin:");
    CommandAssert.assertSenderReceivedMessage(sender, "Suite:");
}
@HytaleTest
@RequiresPlayer
void permissionCanBeAddedAndRemoved(TestContext ctx) {
    MockCommandSender sender = ctx.createCommandSender();

    sender.addPermission("test.perm");
    HytaleAssert.assertTrue(sender.hasPermission("test.perm"));

    sender.removePermission("test.perm");
    HytaleAssert.assertFalse(sender.hasPermission("test.perm"));
}

Executing Commands

Besides using CommandAssert, you can execute commands directly through the context:
ctx.executeCommand("/mymod give diamond_sword 1", sender);
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