Skip to main content
Hytale ships with a GameMode enum (Adventure, Creative) and a GameModeType asset system that defines permissions and interactions for each mode. If your mod changes behavior based on the current game mode - disabling PvP in Creative, unlocking build tools, restricting commands - you need to verify that mode detection and mode switching work correctly. The ChangeGameModeEvent fires when a player’s mode changes. Mods that react to mode switches (enabling fly in Creative, locking inventory in Adventure) should capture this event and verify the new mode value.

Complete Example Suite

package com.example.tests;

import com.frotty27.hrtk.api.annotation.HytaleSuite;
import com.frotty27.hrtk.api.annotation.HytaleTest;
import com.frotty27.hrtk.api.annotation.Tag;
import com.frotty27.hrtk.api.annotation.DisplayName;
import com.frotty27.hrtk.api.annotation.Order;
import com.frotty27.hrtk.api.assert_.EventAssert;
import com.frotty27.hrtk.api.assert_.HytaleAssert;
import com.frotty27.hrtk.api.assert_.PlayerAssert;
import com.frotty27.hrtk.api.context.HytaleTestContext;
import com.frotty27.hrtk.api.lifecycle.IsolationStrategy;

@HytaleSuite(value = "Game Mode Tests", isolation = IsolationStrategy.NONE)
@Tag("gamemode")
public class GameModeSurfaceTests {

    @HytaleTest
    @Order(1)
    @DisplayName("GameMode enum has Adventure and Creative values")
    void gameModeEnumValues() {
        // The GameMode enum is the core mode identifier.
        // Your mod branches on this to enable/disable features.
        HytaleAssert.assertNotNull(GameMode.Adventure);
        HytaleAssert.assertNotNull(GameMode.Creative);
        HytaleAssert.assertEquals(2, GameMode.values().length);
    }

    @HytaleTest
    @Order(2)
    @DisplayName("GameModeType resolves from GameMode enum")
    void gameModeTypeResolvable() {
        // GameModeType is the asset that defines permissions and interactions
        // for each mode. fromGameMode() links the enum to the asset.
        var adventureType = GameModeType.fromGameMode(GameMode.Adventure);
        HytaleAssert.assertNotNull("Adventure GameModeType should resolve", adventureType);

        var creativeType = GameModeType.fromGameMode(GameMode.Creative);
        HytaleAssert.assertNotNull("Creative GameModeType should resolve", creativeType);
    }

    @HytaleTest
    @Order(3)
    @DisplayName("ChangeGameModeEvent carries the new mode")
    void gameModeChangeEventCarriesMode(HytaleTestContext ctx) {
        // Capture the event before triggering the mode change.
        var capture = ctx.captureEvent(ChangeGameModeEvent.class);

        ctx.simulateGameModeChange(GameMode.Creative);

        EventAssert.assertEventFired(capture);
        HytaleAssert.assertEquals(GameMode.Creative, capture.getFirst().getGameMode());
    }

    @HytaleTest
    @Order(4)
    @DisplayName("ChangeGameModeEvent can be cancelled")
    void gameModeChangeCanBeCancelled(HytaleTestContext ctx) {
        // Cancelling the event prevents the mode switch.
        // Protection plugins use this to block unauthorized mode changes.
        var capture = ctx.captureEvent(ChangeGameModeEvent.class);

        ctx.simulateGameModeChange(GameMode.Creative);

        EventAssert.assertEventFired(capture);
        var event = capture.getFirst();
        event.setCancelled(true);
        HytaleAssert.assertTrue("Event should be cancellable", event.isCancelled());
    }
}

GameMode Enum

ValueDescription
GameMode.AdventureStandard gameplay with survival mechanics
GameMode.CreativeUnrestricted building and flying

GameModeType Asset

GameModeType is the content asset tied to each GameMode. It defines what the mode allows:
MethodReturnsDescription
fromGameMode(GameMode)GameModeTypeResolve the asset for a mode
getPermissionGroups()String[]Permission groups active in this mode
getInteractionsOnEnter()StringInteractions triggered when entering the mode

ChangeGameModeEvent

Fires when a player’s game mode changes. Key methods:
MethodReturnsDescription
getGameMode()GameModeThe new game mode being switched to
setGameMode(GameMode)voidOverride the target mode
setCancelled(boolean)voidCancel the mode switch
isCancelled()booleanCheck if the switch was cancelled

When to Test Game Modes

  • Mode-gated features - your mod enables/disables systems per mode
  • Permission checks - Creative players get different permissions than Adventure
  • Event listeners - your mod reacts to ChangeGameModeEvent
  • UI changes - different HUD elements per mode

Isolation Recommendation

Game mode tests are read-only enum and asset lookups. IsolationStrategy.NONE is sufficient unless you are modifying player state:
@HytaleSuite(value = "Game Mode Tests", isolation = IsolationStrategy.NONE)
@Tag("gamemode")
public class GameModeTests { }

Next Steps

  • Players - mock player creation and game mode assignment
  • Events - event capture and cancellation patterns
  • Permissions - permission checks per game mode