diff --git a/src/main/java/com/zenith/network/client/handler/incoming/DisguisedChatHandler.java b/src/main/java/com/zenith/network/client/handler/incoming/DisguisedChatHandler.java index bf68c2ce..acb467c9 100644 --- a/src/main/java/com/zenith/network/client/handler/incoming/DisguisedChatHandler.java +++ b/src/main/java/com/zenith/network/client/handler/incoming/DisguisedChatHandler.java @@ -14,6 +14,7 @@ import static com.zenith.Shared.*; public class DisguisedChatHandler implements PacketHandler { + @Override public ClientboundDisguisedChatPacket apply(final ClientboundDisguisedChatPacket packet, final ClientSession session) { var senderPlayerEntry = CACHE.getTabListCache().getFromName(ComponentSerializer.serializePlain(packet.getName())); diff --git a/src/main/java/com/zenith/network/client/handler/incoming/PlayerChatHandler.java b/src/main/java/com/zenith/network/client/handler/incoming/PlayerChatHandler.java index eb7ce4b6..bcbc5a60 100644 --- a/src/main/java/com/zenith/network/client/handler/incoming/PlayerChatHandler.java +++ b/src/main/java/com/zenith/network/client/handler/incoming/PlayerChatHandler.java @@ -16,9 +16,6 @@ public class PlayerChatHandler implements PacketHandler[").append(CONFIG.authentication.username).append("] - "); - if (Proxy.getInstance().isConnected()) { - sb - .append(getMotdStatus()) - .append("\nOnline for: [").append(Proxy.getInstance().getOnlineTimeString()).append("]"); - } else sb.append("Disconnected"); - return ComponentSerializer.minimessage(sb.toString()); - } + private static final String motdMM = """ + [] - + """; + private static final String motdDisconnectedBody = "Disconnected"; + private static final String motdConnectedBody = """ + + Online for: [] + """; + private static final String motdStatusInGame = "In Game"; + private static final String motdStatusInQueue = """ + [] + """; + private static final String motdInPrioQueue = "In Prio Queue"; + private static final String motdInQueue = "In Queue"; + private static final String motdQueuePosGeneric = "Queueing"; + private static final String motdQueueEta = "- ETA []"; - private String getMotdStatus() { // in minedown formatted string - var proxy = Proxy.getInstance(); - if (proxy.isInQueue()) { - var sb = new StringBuilder(100); - var prio = proxy.isPrio(); - if (prio) sb.append("In Prio Queue"); - else sb.append("In Queue"); - sb.append(" ["); - var qPos = proxy.getQueuePosition(); - var qUndefined = qPos == Integer.MAX_VALUE; - if (!qUndefined) { - sb.append(qPos).append(" / "); - sb.append(prio ? Queue.getQueueStatus().prio() : Queue.getQueueStatus().regular()); - } else sb.append("Queueing"); - sb.append("]"); - if (!qUndefined) - sb.append(" - ETA [").append(Queue.getQueueEta(qPos)).append("]"); - return sb.toString(); - } else { - return "In Game"; - } + public Component getMotd() { + var prio = Proxy.getInstance().isPrio(); + var qPos = Proxy.getInstance().getQueuePosition(); + var qUndefined = qPos == Integer.MAX_VALUE; + return ComponentSerializer.minimessage( + motdMM, + Placeholder.unparsed("username", CONFIG.authentication.username), + Placeholder.parsed("motd_body", Proxy.getInstance().isConnected() ? motdConnectedBody : motdDisconnectedBody), + Placeholder.parsed("motd_status", Proxy.getInstance().isInQueue() ? motdStatusInQueue : motdStatusInGame), + Placeholder.unparsed("online_time", Proxy.getInstance().getOnlineTimeString()), + Placeholder.parsed("in_queue", prio ? motdInPrioQueue : motdInQueue), + Placeholder.unparsed("queue_pos", qUndefined ? motdQueuePosGeneric : qPos + " / " + (prio ? Queue.getQueueStatus().prio() : Queue.getQueueStatus().regular())), + Placeholder.unparsed("queue_eta", qUndefined ? "" : motdQueueEta), + Placeholder.parsed("eta", Queue.getQueueEta(qPos)) + ); } } diff --git a/src/main/java/com/zenith/network/server/handler/shared/outgoing/ServerTablistDataOutgoingHandler.java b/src/main/java/com/zenith/network/server/handler/shared/outgoing/ServerTablistDataOutgoingHandler.java index b42c94b9..033635b8 100644 --- a/src/main/java/com/zenith/network/server/handler/shared/outgoing/ServerTablistDataOutgoingHandler.java +++ b/src/main/java/com/zenith/network/server/handler/shared/outgoing/ServerTablistDataOutgoingHandler.java @@ -5,11 +5,19 @@ import com.zenith.network.server.ServerSession; import com.zenith.util.ComponentSerializer; import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.ClientboundTabListPacket; import static com.zenith.Shared.*; public class ServerTablistDataOutgoingHandler implements PacketHandler { + // todo: allow users to configure the contents of this + private static final String footerMinimessage = """ + + ZenithProxy + [ms] -> [ms] + Online: - TPS: + """; @Override public ClientboundTabListPacket apply(ClientboundTabListPacket packet, ServerSession session) { @@ -23,21 +31,16 @@ public Component insertProxyDataIntoFooter(final Component footer, final ServerS var clientProfile = CACHE.getProfileCache().getProfile(); var sessionProfileName = sessionProfile == null ? "Unknown" : sessionProfile.getName(); var clientProfileName = clientProfile == null ? "Unknown" : clientProfile.getName(); - return footer.append(Component.text().appendNewline().append(ComponentSerializer.minimessage("ZenithProxy")).build()) - .append(Component.text() - .appendNewline() - .append(ComponentSerializer.minimessage( - " " + sessionProfileName - + " [" + session.getPing() + "ms]" - + " -> " + clientProfileName - + " [" + Proxy.getInstance().getClient().getPing() + "ms]" - )).build()) - .append(Component.text() - .appendNewline() - .append(ComponentSerializer.minimessage( - "Online: " + Proxy.getInstance().getOnlineTimeString() - + " - TPS: " + TPS.getTPS())) - .build()); + var injectedFooter = ComponentSerializer.minimessage( + footerMinimessage, + Placeholder.unparsed("session_profile_name", sessionProfileName), + Placeholder.unparsed("session_ping", String.valueOf(session.getPing())), + Placeholder.unparsed("client_profile_name", clientProfileName), + Placeholder.unparsed("client_ping", String.valueOf(Proxy.getInstance().getClient().getPing())), + Placeholder.unparsed("online_time", Proxy.getInstance().getOnlineTimeString()), + Placeholder.unparsed("tps", TPS.getTPS()) + ); + return footer.append(injectedFooter); } catch (final Exception e) { SERVER_LOG.warn("Failed injecting proxy info to tablist footer", e); return footer; diff --git a/src/main/java/com/zenith/util/ComponentSerializer.java b/src/main/java/com/zenith/util/ComponentSerializer.java index 45ba4817..458d2cb0 100644 --- a/src/main/java/com/zenith/util/ComponentSerializer.java +++ b/src/main/java/com/zenith/util/ComponentSerializer.java @@ -9,6 +9,7 @@ import net.kyori.adventure.text.event.ClickEvent; import net.kyori.adventure.text.flattener.ComponentFlattener; import net.kyori.adventure.text.minimessage.MiniMessage; +import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver; import net.kyori.adventure.text.serializer.ansi.ANSIComponentSerializer; import net.kyori.adventure.translation.GlobalTranslator; import net.kyori.adventure.translation.TranslationRegistry; @@ -77,6 +78,10 @@ public static Component minimessage(String message) { return MiniMessage.miniMessage().deserialize(message); } + public static Component minimessage(String message, TagResolver... resolvers) { + return MiniMessage.miniMessage().deserialize(message, resolvers); + } + public static Component deserializeEmbed(final Embed embed) { return EmbedSerializer.serialize(embed); }