Code Patterns

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

← Back to Patterns
gui

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.

Example Code

java
// Directory structure in your plugin:
// src/main/resources/
//   ├── manifest.json          (with "IncludesAssetPack": true)
//   └── Common/
//       └── UI/
//           └── Custom/
//               └── Pages/
//                   └── MyPage.ui

// In your Java code, reference as:
uiCommandBuilder.append("Pages/MyPage.ui");

// Basic .ui file structure (MyPage.ui):
$C = "../Common.ui";

$C.@PageOverlay {
    $C.@DecoratedContainer {
        Anchor: (Width: 400, Height: 200);

        #Title {
            Group {
                $C.@Title {
                    @Text = "MY TITLE";
                }
            }
        }

        #Content {
            LayoutMode: Top;
            Padding: (Left: 20, Right: 20, Top: 10, Bottom: 10);

            Label #MyLabel {
                Anchor: ();
                Style: (
                    FontSize: 18,
                    TextColor: #ffffff,
                    HorizontalAlignment: Center,
                    VerticalAlignment: Center
                );
                Text: "Hello World!";
            }
        }
    }
}

Thread Safety

UI build() runs on world thread.

Common Mistakes

Using Alignment: MiddleCenter instead of HorizontalAlignment/VerticalAlignment. Forgetting IncludesAssetPack in manifest. Wrong directory structure (must be Common/UI/Custom/Pages/ in JAR). Not adding Common/**/* to pom.xml resources.