From 3aa732debc045fd7a9ca5b4de5426a9134c9daf1 Mon Sep 17 00:00:00 2001 From: Netherite <88792142+NetheriteMiner@users.noreply.github.com> Date: Tue, 30 Jul 2024 13:05:26 -0400 Subject: [PATCH 1/2] Fix: Discord RPC dynamic off-by-one --- .../skyhanni/features/misc/discordrpc/DiscordStatus.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/discordrpc/DiscordStatus.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/discordrpc/DiscordStatus.kt index 0944ca9ad2fa..a2a4c53b1386 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/discordrpc/DiscordStatus.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/discordrpc/DiscordStatus.kt @@ -239,9 +239,9 @@ enum class DiscordStatus(private val displayMessageSupplier: (() -> String?)) { } } if (autoReturn == "") { // if we didn't find any useful information, display the fallback - val statusNoAuto = DiscordStatus.entries.toMutableList() - statusNoAuto.remove(AUTO) - autoReturn = statusNoAuto[DiscordRPCManager.config.auto.get().ordinal].getDisplayString() + val fallbackID = DiscordRPCManager.config.auto.get().ordinal + if (fallbackID == 10) autoReturn = NONE.getDisplayString() // 10 is this (DiscordStatus.AUTO); prevents an infinite loop + else autoReturn = DiscordStatus.entries[DiscordRPCManager.config.auto.get().ordinal].getDisplayString() } autoReturn }), From 401c32eecd32cc85ddd38600a2634e034d27c1e2 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Thu, 1 Aug 2024 00:01:33 +0200 Subject: [PATCH 2/2] code cleanup --- .../features/misc/discordrpc/DiscordStatus.kt | 41 +++++++++++-------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/discordrpc/DiscordStatus.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/discordrpc/DiscordStatus.kt index a2a4c53b1386..0094787870d8 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/discordrpc/DiscordStatus.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/discordrpc/DiscordStatus.kt @@ -226,25 +226,30 @@ enum class DiscordStatus(private val displayMessageSupplier: (() -> String?)) { DiscordRPCManager.config.customText.get() // custom field in the config }), - AUTO({ - var autoReturn = "" - for (statusID in DiscordRPCManager.config.autoPriority) { // for every dynamic that the user wants to see... - // TODO, change functionality to use enum rather than ordinals - val autoStatus = AutoStatus.entries[statusID.ordinal] - val result = - autoStatus.correspondingDiscordStatus.getDisplayString() // get what would happen if we were to display it - if (result != autoStatus.placeholderText) { // if that value is useful, display it - autoReturn = result - break + AUTO( + { + var autoReturn = "" + for (statusID in DiscordRPCManager.config.autoPriority) { // for every dynamic that the user wants to see... + // TODO, change functionality to use enum rather than ordinals + val autoStatus = AutoStatus.entries[statusID.ordinal] + val result = + autoStatus.correspondingDiscordStatus.getDisplayString() // get what would happen if we were to display it + if (result != autoStatus.placeholderText) { // if that value is useful, display it + autoReturn = result + break + } } - } - if (autoReturn == "") { // if we didn't find any useful information, display the fallback - val fallbackID = DiscordRPCManager.config.auto.get().ordinal - if (fallbackID == 10) autoReturn = NONE.getDisplayString() // 10 is this (DiscordStatus.AUTO); prevents an infinite loop - else autoReturn = DiscordStatus.entries[DiscordRPCManager.config.auto.get().ordinal].getDisplayString() - } - autoReturn - }), + if (autoReturn == "") { // if we didn't find any useful information, display the fallback + val fallbackID = DiscordRPCManager.config.auto.get().ordinal + autoReturn = if (fallbackID == 10) { + NONE.getDisplayString() // 10 is this (DiscordStatus.AUTO); prevents an infinite loop + } else { + DiscordStatus.entries[fallbackID].getDisplayString() + } + } + autoReturn + }, + ), CROP_MILESTONES({ getCropMilestoneDisplay() }),