HyCodeYourTale

Colors & Formatting

Colors & Formatting

Dokumentace k barvám a formátování zpráv v Hytale.

---

Barvy

Hex Barvy (String)

Nejčastější způsob nastavení barvy:

// Základní hex barva
Message msg = Message.raw("Úspěch!").color("#00FF00");

// S průhledností (RGBA)
Message msg = Message.raw("Text").color("#ea4fa46b");

java.awt.Color

Lze použít také java.awt.Color:

import java.awt.Color;

// Předdefinované barvy
Message success = Message.translation("server.success").color(Color.GREEN);
Message error = Message.translation("server.error").color(Color.RED);

// Vlastní barva
Color customColor = new Color(255, 128, 0); // Oranžová
Message msg = Message.raw("Custom").color(customColor);

Interní Konverze

// Z Message.java
@Nonnull
public Message color(@Nonnull Color color) {
this.message.color = ColorParseUtil.colorToHex(color);
return this;
}

---

Barevné Kódy z Dekompilovaného Kódu

Používané Barvy

| Barva | Hex | Použití |
|-------|-----|---------|
| Zelená | #00FF00 / Color.GREEN | Úspěch, povoleno |
| Červená | #FF0000 / Color.RED | Chyba, zakázáno |
| Žlutá | #F2D729 | Varování, čas |
| Růžová | #d955ef | Speciální zprávy |
| Šedá | #6b6b6b6b | Sekundární text |
| Oranžová | #FFA500 | Upozornění |
| Asset růžová | #FF3874 | Asset změny |
| Asset zelená | #A7AfA7 | Asset reload |
| Zlatá | #f9cb13 | Časový limit |

Příklady z Kódu

// RecipeCommand.java - úspěch/chyba
Message.translation("server.commands.recipe.forgotten")
.param("id", itemId)
.color(Color.GREEN);

Message.translation("server.commands.recipe.alreadyNotKnown")
.param("id", itemId)
.color(Color.RED);

// EnterBedSystem.java - varování
playerRef.sendMessage(msg.color("#F2D729"));

// LeaveCommand.java - speciální zpráva
private static final Message MESSAGE_COMMANDS_LEAVE_UNCURSED_TEMP =
Message.translation("server.commands.leave.uncursedTemp").color("#d955ef");

// PortalDeviceActivePage.java - s průhledností
Message.raw(playerCount + "!").color(pinkEnoughColor)
Message.raw("- ").color("#6b6b6b6b")

// CommonAssetModule.java - asset změny
Message.translation("server.general.assetstore.removedAssets")
.param("class", "Common")
.color("#FF3874");

---

Textové Formátování

Bold (Tučné)

Message msg = Message.raw("Důležité!")
.bold(true);

Italic (Kurzíva)

Message msg = Message.raw("Poznámka")
.italic(true);

Monospace

Message msg = Message.raw("kód")
.monospace(true);

Underline (Podtržení)

// Z Message.java - CODEC
// "Underline": true/false/null

Kombinace Formátování

Message msg = Message.raw("Důležitá poznámka!")
.bold(true)
.italic(true)
.color("#FF0000");

---

Odkazy (Links)

// Klikatelný odkaz
Message msg = Message.raw("Klikni zde")
.link("https://example.com");

// S formátováním
Message msg = Message.translation("server.help.documentation")
.link("https://docs.example.com")
.color("#0066FF");

---

Chain Pattern

Všechny metody vrací Message, takže lze řetězit:

Message msg = Message.translation("server.welcome")
.param("player", playerName)
.param("server", serverName)
.color("#00FF00")
.bold(true);

---

MessageFormat Utility

Z MessageFormat.java - utility metody pro formátování:

enabled() - Povoleno/Zakázáno

// MessageFormat.java
private static final Message ENABLED =
Message.translation("server.general.enabled").color(Color.GREEN);
private static final Message DISABLED =
Message.translation("server.general.disabled").color(Color.RED);

@Nonnull
public static Message enabled(boolean b) {
return b ? ENABLED : DISABLED;
}

// Použití
player.sendMessage(MessageFormat.enabled(isFeatureEnabled));

list() - Formátovaný Seznam

// MessageFormat.java
@Nonnull
public static Message list(@Nullable Message header, @Nonnull Collection values) {
Message msg = Message.empty();

if (header != null) {
msg.insert(Message.translation("server.formatting.list.header")
.param("header", header)
.param("count", values.size()));
if (values.size() <= 4) {
msg.insert(Message.translation("server.formatting.list.inlineHeaderSuffix"));
}
}

if (values.isEmpty()) {
msg.insert(Message.translation("server.formatting.list.empty"));
return msg;
}

if (values.size() <= 4) {
// Inline: item1, item2, item3
Message separator = Message.translation("server.formatting.list.itemSeparator");
Message[] array = values.toArray(Message[]::new);
for (int i = 0; i < array.length; i++) {
msg.insert(array[i]);
if (i < array.length - 1) {
msg.insert(separator);
}
}
} else {
// Víceřádkový seznam
Message delim = Message.raw("\n");
for (Message value : values) {
msg.insert(delim);
msg.insert(Message.translation("server.formatting.list.row")
.param("value", value));
}
}

return msg;
}

---

ANSI Konzole

Pro výstup do konzole server používá ANSI formátování:

// MessageUtil.java
public static AttributedString toAnsiString(@Nonnull Message message) {
AttributedStyle style = AttributedStyle.DEFAULT;
String color = message.getColor();
if (color != null) {
style = hexToStyle(color);
}

AttributedStringBuilder sb = new AttributedStringBuilder();
sb.style(style).append(message.getAnsiMessage());

for (Message child : message.getChildren()) {
sb.append(toAnsiString(child));
}

return sb.toAttributedString();
}

public static AttributedStyle hexToStyle(@Nonnull String str) {
Color color = ColorParseUtil.parseColor(str);
if (color == null) {
return AttributedStyle.DEFAULT;
}
int colorId = Colors.roundRgbColor(
color.red & 255,
color.green & 255,
color.blue & 255,
256
);
return AttributedStyle.DEFAULT.foreground(colorId);
}

---

MaybeBool (Interní)

Pro boolean vlastnosti (bold, italic, atd.) se interně používá MaybeBool:

// Tři stavy:
// - MaybeBool.True - explicitně zapnuto
// - MaybeBool.False - explicitně vypnuto
// - MaybeBool.Null - nenastaveno (dědí z parent)

// Z Message.java
@Nonnull
public Message bold(boolean bold) {
this.message.bold = bold ? MaybeBool.True : MaybeBool.False;
return this;
}

---

Příklady Komplexních Zpráv

Zpráva s Více Barvami

Message msg = Message.empty()
.insert(Message.raw("[").color("#888888"))
.insert(Message.raw("INFO").color("#00FF00").bold(true))
.insert(Message.raw("] ").color("#888888"))
.insert(Message.raw("Server started!"));

player.sendMessage(msg);

Chybová Zpráva s Detailem

Message error = Message.empty()
.insert(Message.translation("server.error.prefix").color(Color.RED).bold(true))
.insert(Message.raw(" "))
.insert(Message.translation("server.commands.errors.playerNotFound")
.param("name", playerName));

context.sendMessage(error);

Seznam s Barvami

List items = warps.stream()
.map(warp -> Message.raw(warp.getName())
.color(warp.isActive() ? "#00FF00" : "#888888"))
.collect(Collectors.toList());

Message list = MessageFormat.list(
Message.translation("server.warps.header"),
items
);

---

Shrnutí

| Metoda | Popis |
|--------|-------|
| .color(String hex) | Hex barva (#RRGGBB nebo #RRGGBBAA) |
| .color(Color) | java.awt.Color |
| .bold(boolean) | Tučné písmo |
| .italic(boolean) | Kurzíva |
| .monospace(boolean) | Monospace font |
| .link(String url) | Klikatelný odkaz |

| Běžné Barvy | Hex | Význam |
|-------------|-----|--------|
| Zelená | #00FF00 | Úspěch |
| Červená | #FF0000 | Chyba |
| Žlutá | #F2D729 | Varování |
| Šedá | #888888 | Sekundární |
| Modrá | #0066FF | Odkazy |

Last updated: 20. ledna 2026