Events are a core communication mechanism in Hytale server plugins. When an NPC takes damage, a player joins, or a block breaks, the server fires events that plugins can listen to. HRTK lets you capture events fired during a test and assert on their occurrence, count, and contents usingDocumentation Index
Fetch the complete documentation index at: https://docs.hrtk.frotty27.com/llms.txt
Use this file to discover all available pages before exploring further.
EventAssert and EventCapture.
Testing events is essential because many mod features are event-driven. If your damage handler listens for DamageEvent but the event stops firing after a server update, your mod silently breaks. Event tests catch these regressions by verifying that the right events fire at the right times with the right data.
Event Capture Lifecycle
The capture lifecycle is straightforward:- Start - Call
ctx.captureEvent(EventType.class)to begin recording. HRTK registers a server-level listener that collects every matching event. - Trigger - Perform the action that should fire the event (spawn an entity, deal damage, send a command).
- Assert - Check that the expected events were captured with the correct count and data.
- Close - Call
capture.close()to unregister the listener. HRTK also auto-unregisters all listeners when the test or suite finishes, so listeners never leak even if you forget to close them.
Complete Example Suite
EventCapture Interface
| Method | Description |
|---|---|
getEvents() | Get all captured events in order |
getCount() | Number of captured events |
wasFired() | True if at least one event was captured |
anyMatch(predicate) | True if any event matches the predicate |
getFirst() | First captured event (or null) |
getLast() | Last captured event (or null) |
clear() | Clear all captured events |
close() | Stop capturing and unregister the listener |
EventAssert Methods
| Method | Description |
|---|---|
assertEventFired(capture) | Assert at least one event was captured |
assertEventFired(capture, count) | Assert exactly N events were captured |
assertEventNotFired(capture) | Assert no events were captured |
assertEventFiredWith(capture, predicate) | Assert at least one event matches |
Event Priority and Cancellation
HRTK’s event capture system registers listeners at the server level. This means:- Captured events include both cancelled and non-cancelled events (depending on listener priority)
- Your test can observe events that other plugins may cancel
- The capture does not interfere with normal event processing
Built-in Hytale Event Types
The Hytale server JAR includes many specific event types you can capture directly:Block Events (cancellable)
BreakBlockEvent- fires when a block is broken. HasgetBlockType(),getTargetBlock(),getItemInHand().PlaceBlockEvent- fires when a block is placed. HasgetTargetBlock(),getItemInHand(),getRotation().DamageBlockEvent- fires when a block takes mining damage. HasgetDamage(),getCurrentDamage(),setDamage().
Player Events
PlayerChatEvent(async, cancellable) - chat messages. HasgetContent(),setContent(),getSender(),getTargets().PlayerConnectEvent- player joins. HasgetWorld(),setWorld(),getPlayerRef(),getPlayer().PlayerDisconnectEvent- player leaves. HasgetPlayerRef(),getDisconnectReason().PlayerInteractEvent(cancellable) - right-click. HasgetActionType(),getItemInHand(),getTargetBlock(),getTargetEntity().PlayerCraftEvent- crafting. HasgetCraftedRecipe(),getQuantity().PlayerMouseButtonEvent(cancellable) - mouse clicks. HasgetMouseButton(),getTargetBlock(),getTargetEntity().
Entity Events
EntityRemoveEvent- entity despawns. HasgetEntity().LivingEntityInventoryChangeEvent- inventory modified. HasgetItemContainer(),getTransaction().
ECS Events (cancellable)
ChangeGameModeEvent- game mode change. HasgetGameMode(),setGameMode().SwitchActiveSlotEvent- hotbar switch. HasgetPreviousSlot(),getNewSlot(),isClientRequest().CraftRecipeEvent- crafting. HasgetCraftedRecipe(),getQuantity().DropItemEvent- item dropped.InteractivelyPickupItemEvent- item picked up. HasgetItemStack(),setItemStack().
Lifecycle Events
BootEvent- server started.ShutdownEvent- server shutting down. Has phase constants:DISCONNECT_PLAYERS,UNBIND_LISTENERS,SHUTDOWN_WORLDS.PrepareUniverseEvent- worlds being set up. HasgetWorldConfigProvider().
Permission Events
PlayerPermissionChangeEvent- user permission changed. HasgetPlayerUuid().GroupPermissionChangeEvent- group permission changed. HasgetGroupName().
Event Priority
UseEventPriority to control when your listener runs: FIRST, EARLY, NORMAL, LATE, LAST. Register with priority via eventRegistry.register(EventPriority.FIRST, EventClass.class, handler).
When to Use Event Testing
Event tests are most valuable when:- Your mod’s core logic is event-driven (damage handlers, join handlers, custom triggers)
- You need to verify that events carry the correct data after a refactor
- You want to confirm that an action does NOT fire an event (negative testing)
- You are testing cross-plugin communication where one plugin fires events that another consumes
Next Steps
- Command Testing - test commands with mock senders
- ECS Testing - entity and component assertions
- Async & Tick Waiting - wait for events to fire