Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ loader_version=0.19.3
fabric_version=0.141.4+1.21.11
loom_version=1.17.8

mod_version=1.6.5
mod_version=1.6.6
maven_group=tel.eden
archives_base_name=edenmod
modmenu_version=17.0.0
Expand Down
145 changes: 119 additions & 26 deletions src/tel/eden/mod/EdenModClient.java

Large diffs are not rendered by default.

46 changes: 40 additions & 6 deletions src/tel/eden/mod/chat/ChatReplyManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Manages active and pending Discord reply state for the in-game chat UI and bridge.
*/
public final class ChatReplyManager {
public record ReplyInfo(String messageId, String author, String excerpt) {
public record ReplyInfo(String messageId, String author, String excerpt, boolean traveler) {
}

private static final int MAX_CACHE_SIZE = 100;
Expand Down Expand Up @@ -59,14 +59,23 @@ public static synchronized void ensureGuildPrefix() {

/** Record a received Discord message so it can be replied to by ID. */
public static synchronized void recordDiscordMessage(String messageId, String author, String content) {
record(messageId, author, content, false);
}

/** Record a received traveler-chat message so it can be replied to by ID. */
public static synchronized void recordTravelerMessage(String messageId, String author, String content) {
record(messageId, author, content, true);
}

private static void record(String messageId, String author, String content, boolean traveler) {
if (messageId == null || messageId.isEmpty() || author == null) {
return;
}
String excerpt = content != null ? content.strip() : "";
if (excerpt.length() > 60) {
excerpt = excerpt.substring(0, 57).strip() + "...";
}
RECENT_MESSAGES.put(messageId, new ReplyInfo(messageId, author, excerpt));
RECENT_MESSAGES.put(messageId, new ReplyInfo(messageId, author, excerpt, traveler));
}

/** Retrieve cached message metadata by Discord message ID. */
Expand All @@ -76,12 +85,37 @@ static synchronized ReplyInfo getRecent(String messageId) {

/** Set active reply context looking up cached metadata. */
public static synchronized void setActiveReply(String messageId) {
setActiveReply(messageId, false);
}

/** As {@link #setActiveReply(String)} for a traveler-chat message; an unknown id is still a traveler reply. */
public static synchronized void setActiveTravelerReply(String messageId) {
setActiveReply(messageId, true);
}

private static void setActiveReply(String messageId, boolean traveler) {
ReplyInfo info = RECENT_MESSAGES.get(messageId);
if (info != null) {
activeReply = info;
} else {
activeReply = new ReplyInfo(messageId, "Discord", "");
activeReply = info != null ? new ReplyInfo(messageId, info.author(), info.excerpt(), traveler) : new ReplyInfo(messageId, "Discord", "", traveler);
}

/** Whether the active reply targets a traveler-chat message. */
public static synchronized boolean isActiveReplyTraveler() {
return activeReply != null && activeReply.traveler();
}

/** Chat prefix that routes a message to the active reply's channel: /e for traveler chat, /g otherwise. */
public static synchronized String activeReplyPrefix() {
return isActiveReplyTraveler() ? "/e " : "/g ";
}

/** If the active reply is a traveler one, return its message ID and clear it; otherwise null, state untouched. */
public static synchronized String takeTravelerReply() {
if (!isActiveReplyTraveler()) {
return null;
}
String id = activeReply.messageId();
activeReply = null;
return id;
}

/** Currently active reply context in the chat UI. */
Expand Down
54 changes: 47 additions & 7 deletions src/tel/eden/mod/chat/DiscordChatFormatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -225,12 +225,40 @@ public static Component format(String author, String content, String replyTo, St
body.append(authorComp);

if (replyTo != null && !replyTo.isEmpty()) {
body.append(Component.literal(" replied to ").withStyle(ChatFormatting.GRAY)).append(replyTarget(replyTo, replyExcerpt)).append(Component.literal(": ").withStyle(ChatFormatting.GREEN));
body.append(Component.literal(" replied to ").withStyle(ChatFormatting.GRAY)).append(replyTarget(replyTo, replyExcerpt, Style.EMPTY.withColor(ChatFormatting.GREEN))).append(Component.literal(": ").withStyle(ChatFormatting.GREEN));
}
body.append(linkify(content, replyStyle));
return withGuildPrefix(body);
}

// Traveler chat's own color, lavender, so it never reads as guild (aqua) or Discord (green) chat.
private static final int TRAVELER_RGB = 0xB388FF;
// The message text is a lighter shade than the tag and name so the name stands out.
private static final int TRAVELER_TEXT_RGB = 0xD8C2FF;

// Invisible line markers a Wynntils chat-tab regex can match: one zero-width
// non-joiner on every line this mod draws, two on traveler chat so it can be
// routed to (or kept out of) its own tab.
private static final String LINE_MARKER = "\u200C";
private static final String TRAVELER_MARKER = "\u200C\u200C";

/** A traveler-chat line; links, images, GIFs, stickers and emotes render as in bridge chat. */
public static Component travelerChat(String author, String content, String replyTo, String replyExcerpt, String messageId) {
boolean hasId = messageId != null && !messageId.isEmpty();
if (hasId) {
ChatReplyManager.recordTravelerMessage(messageId, author, content);
}
Style color = Style.EMPTY.withColor(TRAVELER_RGB);
Style click = hasId ? color.withClickEvent(new ClickEvent.RunCommand("/eden treply " + messageId)).withHoverEvent(new HoverEvent.ShowText(Component.literal("Click to reply to @" + author).withStyle(ChatFormatting.GRAY))) : color;
boolean reply = replyTo != null && !replyTo.isEmpty();
MutableComponent body = Component.empty().append(Component.literal(pillLabel("traveler")).withStyle(click.withFont(PILL_FONT))).append(Component.literal(reply ? " " + author : " " + author + ": ").withStyle(click));
if (reply) {
body.append(Component.literal(" replied to ").withStyle(ChatFormatting.GRAY)).append(replyTarget(replyTo, replyExcerpt, color)).append(Component.literal(": ").withStyle(color));
}
body.append(linkify(content, hasId ? click : null, Style.EMPTY.withColor(TRAVELER_TEXT_RGB)));
return withGuildPrefix(body, TRAVELER_MARKER);
}

/**
* Build a gold-pill bridge line (Quick Reactions, {@code /eden cf}/{@code diceroll}):
* a gold pill labelled {@code label}, then the {@code content} in gold. Mirrors
Expand Down Expand Up @@ -265,8 +293,8 @@ public static Component pill(String label, String content, Integer colorRgb, boo
}

/** The "replyTo (excerpt)" segment: name in green, inline quote gray, full quote on hover. */
private static MutableComponent replyTarget(String replyTo, String replyExcerpt) {
MutableComponent segment = Component.literal(replyTo).withStyle(ChatFormatting.GREEN);
private static MutableComponent replyTarget(String replyTo, String replyExcerpt, Style nameStyle) {
MutableComponent segment = Component.literal(replyTo).withStyle(nameStyle);
String quote = replyExcerpt == null ? "" : ChatText.normalizeWhitespace(replyExcerpt);
if (!quote.isEmpty()) {
String shown = quote.length() > EXCERPT_MAX ? quote.substring(0, EXCERPT_MAX).strip() + "…" : quote;
Expand All @@ -288,13 +316,17 @@ private static MutableComponent linkify(String content) {
}

private static MutableComponent linkify(String content, Style replyStyle) {
return linkify(content, replyStyle, Style.EMPTY.withColor(ChatFormatting.GREEN));
}

private static MutableComponent linkify(String content, Style replyStyle, Style textStyle) {
MutableComponent out = Component.empty();
Matcher matcher = TOKEN_PATTERN.matcher(content);
int last = 0;
// Click event for the text body (without hover popup so reading isn't obstructed)
ClickEvent textClick = replyStyle != null ? replyStyle.getClickEvent() : null;
java.util.function.Consumer<String> appendText = text -> {
MutableComponent comp = Component.literal(text).withStyle(ChatFormatting.GREEN);
MutableComponent comp = Component.literal(text).withStyle(textStyle);
if (textClick != null) {
comp.setStyle(comp.getStyle().withClickEvent(textClick));
}
Expand Down Expand Up @@ -407,8 +439,12 @@ public static Component processEmotes(Component message) {

/** Wrap the body to chat width, prefixing line 1 with the shield and the rest with bars. */
private static Component withGuildPrefix(Component body) {
Component shield = prefix(SHIELD);
Component continuation = prefix(CONTINUATION);
return withGuildPrefix(body, LINE_MARKER);
}

private static Component withGuildPrefix(Component body, String marker) {
Component shield = prefix(SHIELD, marker);
Component continuation = prefix(CONTINUATION, marker);
Minecraft mc = Minecraft.getInstance();
Font font = mc.font;
int reserve = font.width(continuation);
Expand Down Expand Up @@ -440,8 +476,12 @@ private static int chatWidth(Minecraft mc) {
}

private static Component prefix(int[] glyphs) {
return prefix(glyphs, LINE_MARKER);
}

private static Component prefix(int[] glyphs, String marker) {
StringBuilder out = new StringBuilder();
out.append('\u200C');
out.append(marker);
for (int glyph : glyphs) {
out.appendCodePoint(glyph);
}
Expand Down
27 changes: 27 additions & 0 deletions src/tel/eden/mod/config/BridgeConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,19 @@ public String label() {
/** Play a short chime when Eden mail arrives. On by default. */
public boolean mailSound = true;

/** Show traveler chat (non-guild players and members talking together). On by default. */
public boolean travelerChat = true;

public enum MemberGames {
GUILD, ALL, OFF
}

/** Members: which game lines to show: guild games only (default), all, or none. */
public MemberGames memberGames = MemberGames.GUILD;

/** Travelers: show game lines at all ("all") or none ("off"). On by default. */
public boolean travelerGames = true;

/**
* Whether open/full raid parties are auto-announced in chat with a clickable
* {@code [JOIN #id]} feed. When false, parties are only shown on demand via
Expand Down Expand Up @@ -243,6 +256,17 @@ public void sanitize() {
/** Master toggle for the Territory Preset Helper Wynntils add-on. On by default. */
public boolean territoryMenuSuite = true;

/**
* Last standing the backend reported: true = guild member. Null (older configs) counts as a
* member so presets do not vanish for members before their first connect after updating.
*/
public Boolean wasMember = null;

/** Preset UI is for guild members only; wasMember is refreshed on every authOk, so it also covers an outage. */
public boolean presetsEnabled() {
return territoryMenuSuite && (wasMember == null || wasMember);
}

/** Active territory preset encoded Base64 or JSON string, or empty. */
public String territoryActivePreset = "";

Expand Down Expand Up @@ -477,6 +501,9 @@ static void migrateLegacyFields(BridgeConfig config) {
if (config.loginLogoutMode == null) {
config.loginLogoutMode = LoginLogoutMode.ALL;
}
if (config.memberGames == null) {
config.memberGames = MemberGames.GUILD;
}
}

/** Load the config from disk, or return defaults (and write them) if absent. */
Expand Down
Loading
Loading