From fe59112091a4b18de61e3a1e8bbca8661583402d Mon Sep 17 00:00:00 2001 From: NetheriteMiner <88792142+NetheriteMiner@users.noreply.github.com> Date: Wed, 31 Jul 2024 18:02:34 -0400 Subject: Fix: Discord RPC dynamic off-by-one (#2279) Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> --- .../features/misc/discordrpc/DiscordStatus.kt | 41 ++++++++++++---------- 1 file changed, 23 insertions(+), 18 deletions(-) (limited to 'src/main/java/at') 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 0944ca9ad..009478787 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 statusNoAuto = DiscordStatus.entries.toMutableList() - statusNoAuto.remove(AUTO) - autoReturn = statusNoAuto[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() }), -- cgit