Files
spigot-chat-sync/src/main/java/com/spigotchatsync/MessageFormatter.java
T
dmg bdd9b4bb8b
Build / build (push) Failing after 57s
feat: add NATS chat sync plugin
2026-01-29 21:24:23 -05:00

35 lines
1.1 KiB
Java

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);
}
}