Code Patterns
Copy-paste examples for common plugin tasks. Commands, events, ECS, GUI, and more.
All
225
Command
60
Damage
2
Ecs
27
Entity
5
Gui
75
Interaction
2
Inventory
4
Moderation
3
Permission
2
Player
9
Plugin
4
Storage
2
Teleport
3
Ui
22
Util
5
← Back to Patterns
java
gui
Custom Button Styling
Create custom styled buttons in native .ui files with different colors for default, hovered, and pressed states.
Example Code
// In your .ui file:
$C = "../Common.ui";
$C.@PageOverlay {
$C.@DecoratedContainer {
Anchor: (Width: 420, Height: 180);
#Content {
LayoutMode: Top;
Padding: (Left: 20, Right: 20, Top: 10, Bottom: 10);
Group #ButtonRow {
LayoutMode: Left;
// Green "Accept" button
$C.@TextButton #AcceptButton {
Anchor: (Width: 100, Height: 36);
Text: "YES";
Style: TextButtonStyle(
Default: (Background: #2d8a2d, LabelStyle: (FontSize: 16, TextColor: #ffffff, RenderBold: true)),
Hovered: (Background: #3da83d, LabelStyle: (FontSize: 16, TextColor: #ffffff, RenderBold: true)),
Pressed: (Background: #1d6a1d, LabelStyle: (FontSize: 16, TextColor: #ffffff, RenderBold: true)),
Sounds: $C.@ButtonSounds,
);
}
// Red "Decline" button with spacing
$C.@TextButton #DeclineButton {
Anchor: (Left: 30, Width: 100, Height: 36);
Text: "NO";
Style: TextButtonStyle(
Default: (Background: #8a2d2d, LabelStyle: (FontSize: 16, TextColor: #ffffff, RenderBold: true)),
Hovered: (Background: #a83d3d, LabelStyle: (FontSize: 16, TextColor: #ffffff, RenderBold: true)),
Pressed: (Background: #6a1d1d, LabelStyle: (FontSize: 16, TextColor: #ffffff, RenderBold: true)),
Sounds: $C.@ButtonSounds,
);
}
}
}
}
}
// In Java, bind button events:
uiEventBuilder.addEventBinding(
CustomUIEventBindingType.Activating,
"#AcceptButton",
EventData.of("Button", "Accept"),
false
);
Common Mistakes
Using Anchor: (Left: 30) for button spacing, not margin. Background colors use hex format #RRGGBB. Must include Sounds: $C.@ButtonSounds for click sounds.