package com.spigotchatsync; import java.time.Instant; import java.time.LocalTime; import java.time.ZoneId; import java.time.format.DateTimeFormatter; public final class MessageFormatter { private static final DateTimeFormatter TIME_FORMAT = DateTimeFormatter.ofPattern("HH:mm"); private MessageFormatter() { } public static String format(String template, ChatSyncMessage message) { String output = template; output = output.replace("{server}", nullSafe(message.getServer())); output = output.replace("{player}", nullSafe(message.getPlayerName())); output = output.replace("{message}", nullSafe(message.getMessage())); output = output.replace("{time}", formatTime(message.getTimestamp())); return output; } private static String nullSafe(String value) { return value == null ? "" : value; } private static String formatTime(long epochSeconds) { if (epochSeconds <= 0) { return ""; } LocalTime time = Instant.ofEpochSecond(epochSeconds).atZone(ZoneId.systemDefault()).toLocalTime(); return TIME_FORMAT.format(time); } }