FormattedMessage
Text in Hytale uses FormattedMessage objects for rich formatting. The constructor has many parameters for styling.
1FormattedMessage message = new FormattedMessage(2 "Hello World", // text content3 null, // click action4 null, // hover text5 null, // insertion6 null, // font7 "#00FF88", // color (hex string)8 MaybeBool.True, // bold9 MaybeBool.False, // italic10 MaybeBool.False, // underline11 MaybeBool.False, // strikethrough12 null, // obfuscated13 false // reset14);maybebool enum
Use
MaybeBool.True and MaybeBool.False (PascalCase), not TRUE/FALSE.ShowEventTitle Packet
Display large text on the player's screen:
1private void showTitle(Player player, String titleText, String subtitleText) {2 // Create title message (big text)3 FormattedMessage title = new FormattedMessage(4 titleText,5 null, null, null, null,6 "#FFFFFF", // white7 MaybeBool.True, // bold8 MaybeBool.False,9 MaybeBool.False,10 MaybeBool.False,11 null, false12 );13 14 // Create subtitle message (smaller text below)15 FormattedMessage subtitle = null;16 if (subtitleText != null) {17 subtitle = new FormattedMessage(18 subtitleText,19 null, null, null, null,20 "#AAAAAA", // gray21 MaybeBool.False,22 MaybeBool.True, // italic23 MaybeBool.False,24 MaybeBool.False,25 null, false26 );27 }28 29 // Create and send packet30 ShowEventTitle packet = new ShowEventTitle(31 0.5f, // fadeIn (seconds)32 0.5f, // fadeOut (seconds)33 3.0f, // duration (seconds)34 null, // event ID35 true, // show (true to display, false to hide)36 title,37 subtitle38 );39 40 player.getPlayerConnection().write(packet);41}Title Timing
| parameter | type | description |
|---|---|---|
| fadeIn | float | Seconds to fade in (0.5 = smooth) |
| fadeOut | float | Seconds to fade out |
| duration | float | Seconds to display at full opacity |
| show | boolean | true = show, false = hide immediately |
Message Builder Helper
MessageBuilder.javajava
1public class MessageBuilder {2 3 private String text;4 private String color = "#FFFFFF";5 private boolean bold = false;6 private boolean italic = false;7 private boolean underline = false;8 private boolean strikethrough = false;9 10 public MessageBuilder(String text) {11 this.text = text;12 }13 14 public static MessageBuilder of(String text) {15 return new MessageBuilder(text);16 }17 18 public MessageBuilder color(String hex) {19 this.color = hex;20 return this;21 }22 23 public MessageBuilder bold() {24 this.bold = true;25 return this;26 }27 28 public MessageBuilder italic() {29 this.italic = true;30 return this;31 }32 33 public MessageBuilder underline() {34 this.underline = true;35 return this;36 }37 38 public MessageBuilder strikethrough() {39 this.strikethrough = true;40 return this;41 }42 43 public FormattedMessage build() {44 return new FormattedMessage(45 text,46 null, null, null, null,47 color,48 bold ? MaybeBool.True : MaybeBool.False,49 italic ? MaybeBool.True : MaybeBool.False,50 underline ? MaybeBool.True : MaybeBool.False,51 strikethrough ? MaybeBool.True : MaybeBool.False,52 null, false53 );54 }55}Usage
1// Create styled messages easily2FormattedMessage title = MessageBuilder.of("VICTORY")3 .color("#00FF88")4 .bold()5 .build();67FormattedMessage subtitle = MessageBuilder.of("You won the game!")8 .color("#AAAAAA")9 .italic()10 .build();Title Presets
TitlePresets.javajava
1public class TitlePresets {2 3 public static void success(Player player, String text) {4 showTitle(player, text, null, "#00FF88", 0.3f, 0.3f, 2.0f);5 }6 7 public static void error(Player player, String text) {8 showTitle(player, text, null, "#FF4444", 0.1f, 0.1f, 2.0f);9 }10 11 public static void warning(Player player, String text) {12 showTitle(player, text, null, "#FFAA00", 0.2f, 0.2f, 2.5f);13 }14 15 public static void info(Player player, String text, String subtitle) {16 showTitle(player, text, subtitle, "#00AAFF", 0.5f, 0.5f, 3.0f);17 }18 19 public static void announcement(Player player, String text, String subtitle) {20 showTitle(player, text, subtitle, "#FFFFFF", 1.0f, 1.0f, 5.0f);21 }22 23 private static void showTitle(24 Player player, 25 String text, 26 String subtitle,27 String color,28 float fadeIn,29 float fadeOut,30 float duration31 ) {32 FormattedMessage titleMsg = MessageBuilder.of(text)33 .color(color)34 .bold()35 .build();36 37 FormattedMessage subtitleMsg = subtitle != null 38 ? MessageBuilder.of(subtitle).color("#888888").italic().build()39 : null;40 41 ShowEventTitle packet = new ShowEventTitle(42 fadeIn, fadeOut, duration, null, true, titleMsg, subtitleMsg43 );44 45 player.getPlayerConnection().write(packet);46 }47}Hide Title
1private void hideTitle(Player player) {2 // Send packet with show=false to immediately hide3 ShowEventTitle packet = new ShowEventTitle(4 0f, 0f, 0f, null, 5 false, // hide6 null, null7 );8 player.getPlayerConnection().write(packet);9}Common Colors
| name | hex | usage |
|---|---|---|
| White | #FFFFFF | Default, important text |
| Gray | #AAAAAA | Subtitles, secondary |
| Green | #00FF88 | Success, positive |
| Red | #FF4444 | Error, danger |
| Yellow | #FFAA00 | Warning, caution |
| Blue | #00AAFF | Info, neutral |
| Purple | #AA00FF | Special, rare |
| Gold | #FFD700 | Premium, achievement |