Code Patterns

Copy-paste examples for common plugin tasks. Commands, events, ECS, GUI, and more.

Command Patterns

60
Add Spawn Point Command

/add command using AbstractAsyncCommand

Async Command with GUI

Create async commands that open custom GUIs. Use CompletableFuture.runAsync with world executor.

Async Command with World Access

Pattern for async commands that need to access the world/ECS. Based on working AdminUI code.

Auto Save Interval Command

/autosave command using AbstractCommand

Change World Command

/changeworld command using CommandBase

Command

/admin command using AbstractAsyncCommand

Command Permissions

Control who can use commands with setPermissionGroup() using GameMode enum.

Command with All Argument Types

Use various argument types: STRING, INTEGER, DOUBLE, BOOLEAN, PLAYER_REF, WORLD, ITEM_ASSET, BLOCK_TYPE_KEY, GAME_MODE, etc.

Command with Arguments

Create a command with required and optional arguments using ArgTypes.

CommandContext Helpers

Useful helper methods on CommandContext for player commands.

Config Command

/config command using AbstractCommand

Debug Command

/debug command using AbstractCommand

Example Command

/test command using CommandBase

Finish Current Map Command

/finish command using AbstractAsyncCommand

Hide All Poi Command

/hidepois command using AbstractCommand

Hide Other Warps Command

/hidewarps command using AbstractCommand

Hide Players Command

/hideplayers command using AbstractCommand

Hide Unexplored Poi Command

/hideunexploredpoi command using AbstractCommand

Hide Unexplored Warps Command

/hideunexploredwarps command using AbstractCommand

Loot Command

/loot command using AbstractCommand

Loot Show Spawn Points Command

/show command using AbstractAsyncCommand

Loot Spawn Command

/spawn command using AbstractCommand

Map Command

/map command using AbstractCommand

Map Exploration Radius Command

/radius command using AbstractCommand

Map Max Scale Command

/maxscale command using AbstractCommand

Map Min Scale Command

/minscale command using AbstractCommand

Map Quality Command

/quality command using AbstractCommand

Map Vote Command

/vote command using CommandBase

Marker Teleport Command

/markerteleport command using AbstractCommand

Max Chunks To Load Command

/maxchunks command using AbstractCommand

Memory Debug Command

/memory command using CommandBase

Menu Command

/menu command using AbstractPlayerCommand

Player Command

Create a command that requires a player context. Extends AbstractPlayerCommand for automatic ECS parameter injection.

Player Location Command

/location command using AbstractCommand

Player Max Scale Command

/maxscale command using AbstractCommand

Player Min Scale Command

/minscale command using AbstractCommand

Radar Range Command

/radarrange command using AbstractCommand

Radar Toggle Command

/radar command using AbstractCommand

Register Command

Register a command in the plugin setup() method.

Reload Command

/reload command using AbstractCommand

Share All Exploration Command

/shareallexploration command using AbstractCommand

Shop

/shop command using CommandBase

Shortcut Command

/adminshortcut command using AbstractAsyncCommand

Show Spawn Points

/show command using AbstractAsyncCommand

Simple Command

Create a simple command using AbstractCommand. Best for server-wide commands or when you dont need ECS/player access. Supports async execution via CompletableFuture.

Spawn Command

/spawn command using AbstractCommand

Spectator Mode

/spectator command using CommandBase

Sync Command

Create a synchronous command using CommandBase. Runs on main thread, good for simple commands that need immediate world access.

Toggle Flight Command

Enable/disable player flight using MovementManager and MovementSettings. Based on working Simple Fly mod by davidhenk.

Track World Command

/track command using AbstractCommand

Traitor Chat Command

/t command using AbstractAsyncCommand

Untrack World Command

/untrack command using AbstractCommand

Waypoint Add Command

/add command using AbstractPlayerCommand

Waypoint Command

/waypoint command using AbstractCommand

Waypoint Delete Command

/remove command using AbstractPlayerCommand

Waypoint Delete Global Command

/removeglobal command using AbstractPlayerCommand

Waypoint Id Command

/id command using AbstractPlayerCommand

Waypoint List Command

/list command using AbstractPlayerCommand

Waypoint Teleport Command

/waypointteleport command using AbstractCommand

Waypoint Update Command

/update command using AbstractPlayerCommand

Ecs Patterns

27
archetypes-pattern

Archetypes group entities with the same component signature for cache-efficient iteration. Entities with components [A,B] are stored together, separate from [A,B,C]. This enables fast system processing.

Break Block Listener

EntityEventSystem implementation

Component Iteration

Efficiently iterate over all entities with a specific component using forEachChunk for cache-friendly access.

component-type-pattern

ComponentType<T> provides type-safe access to components. Every component class has a static getComponentType() method that returns its ComponentType for Store operations.

Confirmed Death

Custom EntityStore component

Custom Component

Create custom ECS components with data and clone support.

Custom Component Definition

Define custom ECS components with proper clone support and optional serialization.

ECS Event Handler

Handle ECS events like crafting, block breaking, damage using EntityEventSystem.

ecs-overview

Entity Component System (ECS) architecture overview for Hytale modding. ECS separates data (Components) from logic (Systems), with Entities being just IDs that group components together.

ecs-vs-oop

Understanding why Hytale uses ECS instead of traditional OOP. ECS avoids inheritance problems and enables better performance through data-oriented design.

Entity Creation

Create new entities using Holder blueprint pattern. Collect all components first, then add to store.

entity-ticking-system-pattern

EntityTickingSystem processes entities every tick (frame). It receives an index into an ArchetypeChunk for efficient iteration. Use for per-entity per-frame logic like movement, AI, or HUD updates.

Exploration Component

Custom EntityStore component

Exploration Player Setup System

RefSystem implementation

holder-pattern

Holder<EntityStore> wraps an entity reference with convenient component access methods. Created from ArchetypeChunk index using EntityUtils.toHolder().

Hud System

EntityTickingSystem implementation

Location System

EntityTickingSystem implementation

Lost In Combat

Custom EntityStore component

Marker Component

Create marker components (boolean flags) using singleton pattern for entities without data.

Place Block Listener

EntityEventSystem implementation

Player Game Mode Info

Custom EntityStore component

Player Hud Update System

EntityTickingSystem implementation

Ref Validation

Always validate entity references before use since entities can be deleted at any time.

RefSystem - Entity Lifecycle

React to entity creation and removal events.

store-ref-pattern

The Store<EntityStore> and Ref<EntityStore> pattern is the core way to access entity components in Hytale ECS. Store is your accessor, Ref identifies which entity.

Ticking System

Create systems that run every game tick with query filtering.

universe-world-hierarchy

Hytale world structure: Universe contains multiple Worlds, each World has an EntityStore. The Universe represents the entire game session, Worlds are individual dimensions/areas.

Gui Patterns

75
Custom Button Styling

Create custom styled buttons in native .ui files with different colors for default, hovered, and pressed states.

Custom UI Page

Create custom UI pages by extending InteractiveCustomUIPage. Define data codec for event handling.

Grave Plate Page

InteractiveCustomUIPage implementation

hytale-argumenttypeitem

Official Hytale UI: ArgumentTypeItem with text elements

hytale-bartergridspacer

Official Hytale UI: BarterGridSpacer

hytale-barterpage

Official Hytale UI: BarterPage - Container layout with buttons with text elements

hytale-bartertraderow

Official Hytale UI: BarterTradeRow - Container layout with buttons with text elements

hytale-basictextbutton

Official Hytale UI: BasicTextButton with buttons with text elements

hytale-bulletpoint

Official Hytale UI: BulletPoint with text elements

hytale-changemodelpage

Official Hytale UI: ChangeModelPage - Container layout with buttons with text elements

hytale-chestmarker

Official Hytale UI: ChestMarker - Container layout with text elements

hytale-commandlistpage

Official Hytale UI: CommandListPage - Container layout with buttons with text elements

hytale-configureinstanceblockpage

Official Hytale UI: ConfigureInstanceBlockPage - Container layout with buttons with text elements

hytale-droppeditemslot

Official Hytale UI: DroppedItemSlot with text elements

hytale-entityspawnpage

Official Hytale UI: EntitySpawnPage - Container layout with buttons with text elements with item grid

hytale-imageimportpage

Official Hytale UI: ImageImportPage - Container layout with buttons with text elements

hytale-instancelistpage

Official Hytale UI: InstanceListPage - Container layout with buttons with text elements

hytale-itemrepairelement

Official Hytale UI: ItemRepairElement with buttons with text elements

hytale-itemrepairpage

Official Hytale UI: ItemRepairPage - Container layout with buttons with text elements

hytale-launchpadsettingspage

Official Hytale UI: LaunchPadSettingsPage - Container layout with buttons with text elements

hytale-memoriescategory

Official Hytale UI: MemoriesCategory with buttons with text elements

hytale-memoriescategorypanel

Official Hytale UI: MemoriesCategoryPanel - Container layout with buttons with text elements

hytale-memoriespanel

Official Hytale UI: MemoriesPanel - Container layout with buttons with text elements

hytale-memoriesunlocked

Official Hytale UI: MemoriesUnlocked with buttons with text elements

hytale-memory

Official Hytale UI: Memory with buttons with text elements

hytale-namerespawnpointpage

Official Hytale UI: NameRespawnPointPage - Container layout with buttons with text elements

hytale-objimportpage

Official Hytale UI: ObjImportPage - Container layout with buttons with text elements

hytale-overridenearbyrespawnpointpage

Official Hytale UI: OverrideNearbyRespawnPointPage - Container layout with buttons with text elements

hytale-overriderespawnpointbutton

Official Hytale UI: OverrideRespawnPointButton with buttons with text elements

hytale-parameteritem

Official Hytale UI: ParameterItem with text elements

hytale-particlespawnpage

Official Hytale UI: ParticleSpawnPage - Container layout with buttons with text elements

hytale-pill

Official Hytale UI: Pill with text elements

hytale-playsoundpage

Official Hytale UI: PlaySoundPage - Container layout with buttons with text elements

hytale-pluginlistbutton

Official Hytale UI: PluginListButton with buttons with text elements

hytale-pluginlistpage

Official Hytale UI: PluginListPage - Container layout with buttons with text elements

hytale-portaldeviceactive

Official Hytale UI: PortalDeviceActive - Container layout with buttons with text elements

hytale-portaldeviceerror

Official Hytale UI: PortalDeviceError - Container layout with buttons with text elements

hytale-portaldevicesummon

Official Hytale UI: PortalDeviceSummon - Container layout with buttons with text elements

hytale-portals

Official Hytale UI: Portals with text elements

hytale-prefabbrowser

Official Hytale UI: PrefabBrowser with text elements

hytale-prefabeditorexitconfirm

Official Hytale UI: PrefabEditorExitConfirm - Container layout with buttons with text elements

hytale-prefabeditorsavesettings

Official Hytale UI: PrefabEditorSaveSettings - Container layout with buttons with text elements

hytale-prefabeditorsettings

Official Hytale UI: PrefabEditorSettings - Container layout with buttons with text elements

hytale-prefablistpage

Official Hytale UI: PrefabListPage - Container layout with buttons with text elements

hytale-prefabsavepage

Official Hytale UI: PrefabSavePage - Container layout with buttons with text elements

hytale-prefabspawnersettingspage

Official Hytale UI: PrefabSpawnerSettingsPage - Container layout with buttons with text elements

hytale-prefabteleportpage

Official Hytale UI: PrefabTeleportPage - Container layout with buttons with text elements

hytale-respawnpage

Official Hytale UI: RespawnPage - Container layout with buttons with text elements

hytale-scriptedbrushlistpage

Official Hytale UI: ScriptedBrushListPage - Container layout with buttons with text elements

hytale-selectoverriderespawnpointpage

Official Hytale UI: SelectOverrideRespawnPointPage - Container layout with buttons with text elements

hytale-shopelementbutton

Official Hytale UI: ShopElementButton with buttons

hytale-shoppage

Official Hytale UI: ShopPage - Container layout with buttons with text elements

hytale-subcommandcard

Official Hytale UI: SubcommandCard with buttons with text elements

hytale-teleporter

Official Hytale UI: Teleporter - Container layout with buttons with text elements

hytale-tintchunkpage

Official Hytale UI: TintChunkPage - Container layout with buttons with text elements

hytale-variantcard

Official Hytale UI: VariantCard with buttons with text elements

hytale-warpentrybutton

Official Hytale UI: WarpEntryButton with buttons with text elements

hytale-warplistpage

Official Hytale UI: WarpListPage - Container layout with buttons with text elements

Index Dialog

InteractiveCustomUIPage implementation

Location HUD

CustomUIHud implementation

Map Vote Page

InteractiveCustomUIPage implementation

Mute Dialog

InteractiveCustomUIPage implementation

Native UI File Setup

Set up native .ui files for custom UI pages. Files must be in Common/UI/Custom/Pages/ in JAR but referenced as Pages/ in Java code. Requires IncludesAssetPack in manifest.

Player Current Role HUD

CustomUIHud implementation

Player Dialog

InteractiveCustomUIPage implementation

Score Board Page

BasicCustomUIPage implementation

Shop Page

InteractiveCustomUIPage implementation

Stats Dialog

InteractiveCustomUIPage implementation

Stick Dialog

InteractiveCustomUIPage implementation

UI Common Components

Reference built-in Hytale UI components from Common.ui in your custom .ui files.

UI Dropdown

Create dropdown menus in custom UI with selectable options.

UI Label Styling

Style labels in native .ui files with custom fonts, colors, and alignment.

Warp Dialog

InteractiveCustomUIPage implementation

Waypoint Edit Page

InteractiveCustomUIPage implementation

Whitelist Dialog

InteractiveCustomUIPage implementation

Ui Patterns

22
Color Constants

Use java.awt.Color for message colors. Available constants: RED, GREEN, BLUE, YELLOW, CYAN (not AQUA!), MAGENTA, WHITE, BLACK, GRAY, DARK_GRAY, LIGHT_GRAY, ORANGE, PINK.

hytale-actionbutton

Official Hytale UI: ActionButton - Container layout with buttons with text elements

hytale-common

Official Hytale UI: Common - Container layout with buttons with text elements

hytale-sounds

Official Hytale UI: Sounds with buttons

hytale-textbutton

Official Hytale UI: TextButton with buttons with text elements

hytale-timeleft

Official Hytale UI: TimeLeft

Navigation Bar Setup

Helper for setting up navigation bar in custom UI pages with permission-filtered entries

Play Sound

Play sounds to players using SoundUtil.

Send Notification

Send item pickup-style notifications to players.

Server Stats Display

Display server statistics (CPU, RAM, uptime) in custom UI with auto-refresh

UI List with Search and Delete Confirmation

Searchable list UI with delete confirmation on hover pattern

UI Registry Pattern

Singleton registry for registering UI pages with navigation bar and command shortcuts

ui-basic-page

Simplest Custom UI Page pattern using BasicCustomUIPage. Use this for static, non-interactive UI displays that just show information without any buttons or inputs.

ui-button-styles

Define reusable button styles with hover and pressed states using TextButtonStyle. Styles are defined at the top of .ui files with @ prefix and referenced in TextButton elements.

ui-colors-styling

Color formats and common styling properties for Hytale UI elements. Colors use hex format with optional alpha. Style properties control text appearance, alignment, and formatting.

ui-dashboard-layout

Two-panel layout with sidebar navigation and main content area. Uses LayoutMode: Left for horizontal arrangement and FlexWeight for flexible sizing. Great for settings pages, dashboards, or info panels.

ui-dynamic-values

Pattern for passing dynamic data from Java to UI elements using cmd.set(). Pass data through constructor, store as fields, then use cmd.set("#ElementId.Property", value) in build() method.

ui-event-binding

Different event binding types for UI interactions. Activating is most common (button clicks), but other types exist for hover, focus changes, and value changes.

ui-form-inputs

Form pattern with TextField, NumberField, and CheckBox inputs. Shows how to read input values using the @-prefix in EventData codec and binding input values to events.

ui-interactive-dialog

Dialog pattern using InteractiveCustomUIPage with button click event handling. Demonstrates event binding, dynamic text setting with cmd.set(), and closing the page programmatically.

ui-layout-modes

Understanding LayoutMode options for arranging child elements. Top = vertical stack, Left = horizontal row, Center = centered, Right = right-aligned. Combine with FlexWeight for responsive layouts.

ui-page-lifetime

CustomPageLifetime options control when and how a UI page can be closed. Choose based on whether the UI should be dismissible by ESC key, clicking outside, or only through explicit code.