Messages
Dokumentace k Message API v Hytale - zprávy, překlady, formátování.
Obsah
| Soubor | Popis |
|--------|-------|
| MESSAGE_TYPES.md | Typy zpráv (raw, translation, empty, join) |
| COLORS_FORMATTING.md | Barvy a formátování (bold, italic, links) |
| TRANSLATIONS.md | Překladový systém (.lang soubory, i18n) |
---
Rychlý Přehled
| Metoda | Popis |
|--------|-------|
| Message.raw(text) | Prostý text |
| Message.translation(key) | Přeložitelná zpráva |
| Message.empty() | Prázdná zpráva (kontejner) |
| Message.join(msgs...) | Spojení více zpráv |
| .param(key, value) | Přidání parametru |
| .color(hex) | Nastavení barvy |
| .bold(true) | Tučné písmo |
| .italic(true) | Kurzíva |
| .link(url) | Klikatelný odkaz |
| .insert(msg) | Přidání child zprávy |
---
Message API
Základní Zprávy
// Jednoduchá textová zpráva
Message msg = Message.raw("Hello World!");
player.sendMessage(msg);// Zkrácená verze
player.sendMessage(Message.raw("Hello!"));
Překlady (Translations)
// Zpráva s překladem
Message msg = Message.translation("server.commands.spawn.teleported");
player.sendMessage(msg);// S parametry
Message msg = Message.translation("server.commands.spawn.teleported")
.param("x", position.getX())
.param("y", position.getY())
.param("z", position.getZ());
player.sendMessage(msg);
Barvy
// Hex barva
Message msg = Message.raw("Úspěch!")
.color("#00FF00");// Více barev
Message warning = Message.translation("server.warning")
.color("#F2D729"); // Žlutá
Message error = Message.translation("server.error")
.color("#FF0000"); // Červená
---
Parametry
Základní Parametry
Message msg = Message.translation("server.commands.teleport.success")
.param("username", targetPlayer.getUsername())
.param("x", position.getX())
.param("y", position.getY())
.param("z", position.getZ());
Číselné Parametry
Message msg = Message.translation("server.stats.kills")
.param("count", 42)
.param("ratio", 3.14);
Řetězení Parametrů
Message msg = Message.translation("server.welcome")
.param("player", playerName)
.param("server", serverName)
.param("online", onlineCount)
.color("#00FF00");
---
Příklady z Dekompilovaného Kódu
SpawnCommand
// Úspěšná teleportace
context.sendMessage(
Message.translation("server.commands.spawn.teleported")
.param("x", position.getX())
.param("y", position.getY())
.param("z", position.getZ())
);// Teleportace jiného hráče
context.sendMessage(
Message.translation("server.commands.spawn.teleportedOther")
.param("username", targetPlayerRef.getUsername())
.param("x", position.getX())
.param("y", position.getY())
.param("z", position.getZ())
);
// Chyba - index mimo rozsah
throw new GeneralCommandException(
Message.translation("server.commands.errors.spawnIndexOutOfRange")
.param("index", spawnIndex)
.param("maxIndex", maxIndex)
);
EnterBedSystem
// Zpráva s časem
Message msg = Message.translation("server.interactions.sleep.sleepAtTheseHours")
.param("time", formatTime(startTime))
.param("until", formatDuration(untilSleep));
player.sendMessage(msg.color("#F2D729"));
---
Odesílání Zpráv
Hráči
// Přes Player objekt
player.sendMessage(Message.raw("Zpráva"));// Přes PlayerRef
playerRef.sendMessage(Message.raw("Zpráva"));
// Přes CommandContext
context.sendMessage(Message.raw("Zpráva"));
Všem Hráčům
// Broadcast (závisí na implementaci)
Universe.get().getPlayers().forEach(player -> {
player.sendMessage(Message.raw("Broadcast!"));
});
---
Statické Zprávy
Pro často používané zprávy je efektivnější vytvořit statickou instanci:
public class MyMessages {
// Statická zpráva - vytvoří se jednou
public static final Message PLAYER_NOT_FOUND =
Message.translation("server.commands.errors.playerNotFound"); public static final Message PLAYER_NOT_IN_WORLD =
Message.translation("server.commands.errors.playerNotInWorld");
public static final Message SUCCESS =
Message.raw("Úspěch!").color("#00FF00");
}
// Použití
context.sendMessage(MyMessages.PLAYER_NOT_FOUND);
Z dekompilovaného kódu:
private static final Message MESSAGE_COMMANDS_ERRORS_PLAYER_NOT_IN_WORLD =
Message.translation("server.commands.errors.playerNotInWorld");
---
Formátování Času
Z EnterBedSystem:
private static Message formatTime(LocalTime time) {
int hour = time.getHour();
int minute = time.getMinute();
boolean isPM = hour >= 12;
int displayHour = hour % 12;
if (displayHour == 0) {
displayHour = 12;
} String msgKey = isPM
? "server.interactions.sleep.timePM"
: "server.interactions.sleep.timeAM";
return Message.translation(msgKey)
.param("h", displayHour)
.param("m", String.format("%02d", minute));
}
private static Message formatDuration(@Nonnull Duration duration) {
long totalMinutes = duration.toMinutes();
long hours = totalMinutes / 60L;
long minutes = totalMinutes % 60L;
String msgKey = hours > 0L
? "server.interactions.sleep.durationHours"
: "server.interactions.sleep.durationMins";
return Message.translation(msgKey)
.param("hours", hours)
.param("mins", hours == 0L
? String.valueOf(minutes)
: String.format("%02d", minutes));
}
---
Command Exceptions
Pro chybové zprávy v příkazech:
// Vyhoď výjimku se zprávou
throw new GeneralCommandException(
Message.translation("server.commands.errors.invalidArgument")
.param("arg", argumentName)
);// S více parametry
throw new GeneralCommandException(
Message.translation("server.commands.errors.outOfRange")
.param("value", value)
.param("min", minValue)
.param("max", maxValue)
);
---
Shrnutí
| Metoda | Popis |
|--------|-------|
| Message.raw(text) | Prostý text |
| Message.translation(key) | Přeložitelná zpráva |
| .param(key, value) | Přidání parametru |
| .color(hex) | Nastavení barvy |
| player.sendMessage(msg) | Odeslání hráči |
| context.sendMessage(msg) | Odeslání přes kontext |
Barevné Kódy
| Barva | Hex |
|-------|-----|
| Červená | #FF0000 |
| Zelená | #00FF00 |
| Modrá | #0000FF |
| Žlutá | #F2D729 |
| Oranžová | #FFA500 |
| Bílá | #FFFFFF |