Code Patterns

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

← Back to Patterns
ui

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.

Example Code

java
// HelloWorldPage.ui - The UI layout file
Group {
    Anchor: (Width: 400, Height: 250);
    Background: #1a1a2e(0.95);
    LayoutMode: Top;
    Padding: (Full: 20);

    Label #Title {
        Text: "Hello World";
        Anchor: (Height: 40);
        Style: (FontSize: 24, TextColor: #ffffff, Alignment: Center);
    }
}

// HelloWorldPage.java - The page class
public class HelloWorldPage extends BasicCustomUIPage {

    public HelloWorldPage(@Nonnull PlayerRef playerRef, @Nonnull CustomPageLifetime lifetime) {
        super(playerRef, lifetime);
    }

    @Override
    public void build(UICommandBuilder uiCommandBuilder) {
        // Load the UI layout from resources
        uiCommandBuilder.append("Pages/HelloWorldPage.ui");
    }
}

// Opening the page from a command:
Player player = store.getComponent(ref, Player.getComponentType());
player.getPageManager().setPage(ref, store,
    new HelloWorldPage(playerRef, CustomPageLifetime.CanDismissOrCloseThroughInteraction));

Thread Safety

BasicCustomUIPage is safe for single-player UI operations

Common Mistakes

Using BasicCustomUIPage for interactive UIs - use InteractiveCustomUIPage instead when you need button clicks or input handling