Code Patterns

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

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.