package io.gitlab.jfronny.googlechat.server; import io.gitlab.jfronny.googlechat.*; import net.minecraft.text.Text; import java.util.concurrent.CompletableFuture; import static io.gitlab.jfronny.libjf.LibJf.LOGGER; public sealed interface TranslatableContainer> { S translate(TranslationDirection direction); record Sync(Text text) implements TranslatableContainer { @Override public Sync translate(TranslationDirection direction) { return new Sync(translateAndLog(text, direction)); } } record Async(CompletableFuture text) implements TranslatableContainer, Async> { @Override public Async translate(TranslationDirection direction) { return new Async(text.thenApplyAsync(msg -> translateAndLog(msg, direction))); } } static Text translateAndLog(final Text source, final TranslationDirection direction) { var translated = GoogleChat.translateIfNeeded(source, direction, true); if (GoogleChatConfig.Advanced.debugLogs) LOGGER.info("Applied C2S translation from " + source + " to " + translated); return translated; } }