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
8 changes: 7 additions & 1 deletion src/tel/eden/mod/EdenModClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -1051,11 +1051,17 @@ public void onDiscordMessage(String author, String content, String replyTo, Stri

@Override
public void onLoginNotice(String username, String color) {
if (config.loginLogoutMode == BridgeConfig.LoginLogoutMode.HIDE_ALL) {
return;
}
displayColored(color, () -> DiscordChatFormatter.loginNotice(username));
}

@Override
public void onLogoutNotice(String username, String color) {
if (config.loginLogoutMode == BridgeConfig.LoginLogoutMode.HIDE_ALL) {
return;
}
displayColored(color, () -> DiscordChatFormatter.logoutNotice(username));
}

Expand Down Expand Up @@ -2823,7 +2829,7 @@ private void onBridgeConnected() {
// backend pairs the logout to this, so skipping it keeps both quiet.
// Presence is always sent — it drives the online/dormant state, not a
// chat notice.
if (config.announceSelfPresence) {
if (config.loginLogoutMode == BridgeConfig.LoginLogoutMode.ALL) {
current.sendLogin();
}
current.sendPresence(inGameWorld); // send whatever state we already detected
Expand Down
47 changes: 38 additions & 9 deletions src/tel/eden/mod/config/BridgeConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,37 @@ private static Path resolveConfigPath() {
/** Whether the bridge should connect while on Wynncraft. */
public boolean enabled = true;

public enum LoginLogoutMode {
ALL("All"), HIDE_MINE("Hide Mine"), HIDE_ALL("Hide All");

private final String label;

LoginLogoutMode(String label) {
this.label = label;
}

public String label() {
return label;
}
}

/** Legacy toggle kept only to migrate older configs into {@link #loginLogoutMode}. */
@Deprecated
public Boolean announceSelfPresence = null;

/**
* Whether messages relayed from Discord by other members are shown in your
* in-game client chat. On by default.
*/
public boolean discordBridgeMessages = true;

/**
* Whether your own login/logout is announced to the guild bridge (both in-game
* and in the Discord bridge chat). On by default; turn it off to keep your own
* comings and goings quiet. Other members' presence notices are unaffected, and
* you still appear in {@code /eden online} either way.
* Visibility of login/logout and streak notices:
* ALL: broadcast own login/logout and streaks, and display others'.
* HIDE_MINE: keep own login/logout and streaks quiet, and display others'.
* HIDE_ALL: keep own login/logout and streaks quiet, and hide others'.
*/
public boolean announceSelfPresence = true;
public LoginLogoutMode loginLogoutMode = LoginLogoutMode.ALL;

/** Play a short chime when Eden mail arrives. On by default. */
public boolean mailSound = true;
Expand Down Expand Up @@ -433,17 +451,28 @@ public CommandKeybind(String input, String command) {
}
}

static void migrateLegacyFields(BridgeConfig config) {
if (config.showGameMessages != null) {
config.gameDisplayMode = config.showGameMessages ? GameDisplayMode.ALL : GameDisplayMode.NONE;
config.showGameMessages = null;
}
if (config.announceSelfPresence != null) {
config.loginLogoutMode = config.announceSelfPresence ? LoginLogoutMode.ALL : LoginLogoutMode.HIDE_MINE;
config.announceSelfPresence = null;
}
if (config.loginLogoutMode == null) {
config.loginLogoutMode = LoginLogoutMode.ALL;
}
}

/** Load the config from disk, or return defaults (and write them) if absent. */
public static BridgeConfig load() {
if (Files.isRegularFile(PATH)) {
try {
String json = Files.readString(PATH, StandardCharsets.UTF_8);
BridgeConfig config = GSON.fromJson(json, BridgeConfig.class);
if (config != null) {
if (config.showGameMessages != null) {
config.gameDisplayMode = config.showGameMessages ? GameDisplayMode.ALL : GameDisplayMode.NONE;
config.showGameMessages = null;
}
migrateLegacyFields(config);
if (config.commandAliases == null) {
config.commandAliases = new ArrayList<>();
}
Expand Down
8 changes: 7 additions & 1 deletion src/tel/eden/mod/gui/BridgeConfigScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ protected void init() {
// General
addToggleRow(Category.GENERAL, "Bridge", () -> config.enabled, v -> config.enabled = v, "Enabled", "Disabled", true);
addToggleRow(Category.GENERAL, "Discord Bridge Messages", () -> config.discordBridgeMessages, v -> config.discordBridgeMessages = v, "On", "Off", true);
addToggleRow(Category.GENERAL, "My login/logout messages", () -> config.announceSelfPresence, v -> config.announceSelfPresence = v, "On", "Off", true);
addCycleRow(Category.GENERAL, "Login/logout messages", () -> config.loginLogoutMode.label(), () -> config.loginLogoutMode = nextLoginLogoutMode(config.loginLogoutMode), () -> config.loginLogoutMode = BridgeConfig.LoginLogoutMode.ALL);
addToggleRow(Category.GENERAL, "Mail sound", () -> config.mailSound, v -> config.mailSound = v, "On", "Off", true);
addToggleRow(Category.GENERAL, "Party feed", () -> config.partyAnnounce, v -> config.partyAnnounce = v, "On", "Off", true);
addToggleRow(Category.GENERAL, "Event announcements", () -> config.eventAnnouncements, v -> config.eventAnnouncements = v, "On", "Off", true);
Expand Down Expand Up @@ -285,6 +285,12 @@ private void startLinkFlow() {
mod.startLinkFlow(() -> this.minecraft.execute(() -> this.minecraft.setScreen(BridgeConfigScreen.create(parent, mod))));
}

private BridgeConfig.LoginLogoutMode nextLoginLogoutMode(BridgeConfig.LoginLogoutMode current) {
BridgeConfig.LoginLogoutMode safe = current != null ? current : BridgeConfig.LoginLogoutMode.ALL;
BridgeConfig.LoginLogoutMode[] values = BridgeConfig.LoginLogoutMode.values();
return values[(safe.ordinal() + 1) % values.length];
}

private BridgeConfig.GameDisplayMode nextGameMode(BridgeConfig.GameDisplayMode current) {
BridgeConfig.GameDisplayMode[] values = BridgeConfig.GameDisplayMode.values();
return values[(current.ordinal() + 1) % values.length];
Expand Down
33 changes: 33 additions & 0 deletions test/tel/eden/mod/config/BridgeConfigTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package tel.eden.mod.config;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

Expand Down Expand Up @@ -34,4 +35,36 @@ void defaultsToTrueWhenOmittedFromSerializedJson() {

assertTrue(loaded.discordBridgeMessages);
}

@Test
void defaultsLoginLogoutModeToAll() {
BridgeConfig config = new BridgeConfig();
assertEquals(BridgeConfig.LoginLogoutMode.ALL, config.loginLogoutMode);
}

@Test
void preservesLoginLogoutModeAcrossSerialization() {
Gson gson = new Gson();
BridgeConfig config = new BridgeConfig();
config.loginLogoutMode = BridgeConfig.LoginLogoutMode.HIDE_ALL;

String json = gson.toJson(config);
BridgeConfig loaded = gson.fromJson(json, BridgeConfig.class);

assertEquals(BridgeConfig.LoginLogoutMode.HIDE_ALL, loaded.loginLogoutMode);
}

@Test
void migratesLegacyAnnounceSelfPresenceWhenPresent() {
Gson gson = new Gson();
String falseJson = "{\"announceSelfPresence\":false}";
BridgeConfig loadedFalse = gson.fromJson(falseJson, BridgeConfig.class);
BridgeConfig.migrateLegacyFields(loadedFalse);
assertEquals(BridgeConfig.LoginLogoutMode.HIDE_MINE, loadedFalse.loginLogoutMode);

String trueJson = "{\"announceSelfPresence\":true}";
BridgeConfig loadedTrue = gson.fromJson(trueJson, BridgeConfig.class);
BridgeConfig.migrateLegacyFields(loadedTrue);
assertEquals(BridgeConfig.LoginLogoutMode.ALL, loadedTrue.loginLogoutMode);
}
}
Loading