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
12 changes: 11 additions & 1 deletion src/tel/eden/mod/EdenModClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ public final class EdenModClient implements ClientModInitializer {
// Invalidates delayed party commands when the client changes server/world, so invites
// queued for one session can never be delivered to the next connection.
private final java.util.concurrent.atomic.AtomicInteger partyCommandGeneration = new java.util.concurrent.atomic.AtomicInteger();
private final java.util.concurrent.atomic.AtomicLong allyViewRequestId = new java.util.concurrent.atomic.AtomicLong();
private final java.util.concurrent.atomic.AtomicLong allyViewPendingId = new java.util.concurrent.atomic.AtomicLong();
// Deterministic per-occurrence index so rapid identical bank events stay distinct.
// Short window: only the current burst counts, so stale earlier deposits can't
// make different clients assign divergent seqs (which duplicated Discord posts).
Expand Down Expand Up @@ -1124,6 +1126,7 @@ public void onGameFeedback(String message, String color) {

@Override
public void onAllyActivity(java.util.List<AllyActivityEntry> entries) {
allyViewPendingId.set(0);
boolean canManage = isChiefOwnerOrStrategist();
display(() -> DiscordChatFormatter.allyActivity(entries, canManage));
}
Expand Down Expand Up @@ -1363,10 +1366,17 @@ private LiteralArgumentBuilder<FabricClientCommandSource> buildAllyCommand() {
private void requestAllyView(FabricClientCommandSource source) {
BridgeWebSocketClient current = socket;
if (current == null) {
source.sendFeedback(notConnected());
source.sendFeedback(DiscordChatFormatter.systemLine("Unable to fetch ally info, try again later.", ChatFormatting.RED));
return;
}
long id = allyViewRequestId.incrementAndGet();
allyViewPendingId.set(id);
current.sendAllyActivityRequest();
partyCommandExecutor.schedule(() -> {
if (allyViewPendingId.compareAndSet(id, 0)) {
display(() -> DiscordChatFormatter.systemLine("Unable to fetch ally info, try again later.", ChatFormatting.RED));
}
}, 5, TimeUnit.SECONDS);
}

private CompletableFuture<Suggestions> suggestMembers(CommandContext<FabricClientCommandSource> context, SuggestionsBuilder builder) {
Expand Down
4 changes: 2 additions & 2 deletions src/tel/eden/mod/chat/DiscordChatFormatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ public static Component warCounts(int days, java.util.List<tel.eden.mod.net.WarC
*/
public static Component allyActivity(java.util.List<tel.eden.mod.net.AllyActivityEntry> entries, boolean canManage) {
MutableComponent out = Component.empty().append(prefix(SHIELD));
if (entries.isEmpty()) {
return out.append(Component.literal("No guild allies currently found.").withStyle(ChatFormatting.GOLD));
if (entries == null || entries.isEmpty()) {
return out.append(Component.literal("Unable to fetch ally info, try again later.").withStyle(ChatFormatting.RED));
}
out.append(Component.literal("Guild Allies (by inactivity):").withStyle(ChatFormatting.GREEN));
for (tel.eden.mod.net.AllyActivityEntry entry : entries) {
Expand Down
8 changes: 8 additions & 0 deletions test/tel/eden/mod/chat/DiscordChatFormatterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,12 @@ void allyActivityFormatsCleanlyWhenTagUnknown() {

org.junit.jupiter.api.Assertions.assertTrue(text.contains("Unknown Guild — 10m ago"));
}

@Test
void allyActivityReturnsErrorWhenEmpty() {
Component component = DiscordChatFormatter.allyActivity(List.of(), false);
String text = component.getString();

org.junit.jupiter.api.Assertions.assertTrue(text.contains("Unable to fetch ally info, try again later."));
}
}
Loading