aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/features/misc
diff options
context:
space:
mode:
authorWalker Selby <git@walkerselby.com>2023-10-11 11:24:39 +0100
committerGitHub <noreply@github.com>2023-10-11 12:24:39 +0200
commit4f9fe89aac7b97741f7079ab1ad5f7051e0fa7f7 (patch)
tree80d0ba5a1fa2893c0529f0382a99d6a044bc905c /src/main/java/at/hannibal2/skyhanni/features/misc
parent8527d7555ea16becbcfe949413eabfd41c8400c4 (diff)
downloadskyhanni-4f9fe89aac7b97741f7079ab1ad5f7051e0fa7f7.tar.gz
skyhanni-4f9fe89aac7b97741f7079ab1ad5f7051e0fa7f7.tar.bz2
skyhanni-4f9fe89aac7b97741f7079ab1ad5f7051e0fa7f7.zip
More Code Cleanup - When (#531)
code cleanup #531
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features/misc')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/misc/TpsCounter.kt16
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/misc/discordrpc/DiscordStatus.kt88
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/misc/ghostcounter/GhostUtil.kt38
3 files changed, 80 insertions, 62 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/TpsCounter.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/TpsCounter.kt
index 375238dc3..5fa005021 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/misc/TpsCounter.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/misc/TpsCounter.kt
@@ -98,16 +98,12 @@ class TpsCounter {
}
private fun getColor(tps: Double): String {
- return if (tps > 19.8) {
- "§2"
- } else if (tps > 19) {
- "§a"
- } else if (tps > 17.5) {
- "§6"
- } else if (tps > 12) {
- "§c"
- } else {
- "§4"
+ return when {
+ tps > 19.8 -> "§2"
+ tps > 19 -> "§a"
+ tps > 17.5 -> "§6"
+ tps > 12 -> "§c"
+ else -> "§4"
}
}
}
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 6e0f6acf0..9ec187ca8 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
@@ -100,21 +100,25 @@ enum class DiscordStatus(private val displayMessageSupplier: Supplier<String>?)
val island = LorenzUtils.skyBlockIsland
if (location == "Your Island") location = "Private Island"
- if (island == IslandType.PRIVATE_ISLAND_GUEST) lastKnownDisplayStrings[LOCATION] =
- "${getVisitingName()}'s Island"
- else if (island == IslandType.GARDEN) {
- if (location.startsWith("Plot: ")) {
- lastKnownDisplayStrings[LOCATION] = "Personal Garden ($location)" // Personal Garden (Plot: 8)
- } else {
- lastKnownDisplayStrings[LOCATION] = "Personal Garden"
+ when {
+ island == IslandType.PRIVATE_ISLAND_GUEST -> lastKnownDisplayStrings[LOCATION] =
+ "${getVisitingName()}'s Island"
+ island == IslandType.GARDEN -> {
+ if (location.startsWith("Plot: ")) {
+ lastKnownDisplayStrings[LOCATION] = "Personal Garden ($location)" // Personal Garden (Plot: 8)
+ } else {
+ lastKnownDisplayStrings[LOCATION] = "Personal Garden"
+ }
+ }
+ island == IslandType.GARDEN_GUEST -> {
+ lastKnownDisplayStrings[LOCATION] = "${getVisitingName()}'s Garden"
+ if (location.startsWith("Plot: ")) {
+ lastKnownDisplayStrings[LOCATION] = "${lastKnownDisplayStrings[LOCATION]} ($location)"
+ } // "MelonKingDe's Garden (Plot: 8)"
+ }
+ location != "None" && location != "invalid" -> {
+ lastKnownDisplayStrings[LOCATION] = location
}
- } else if (island == IslandType.GARDEN_GUEST) {
- lastKnownDisplayStrings[LOCATION] = "${getVisitingName()}'s Garden"
- if (location.startsWith("Plot: ")) {
- lastKnownDisplayStrings[LOCATION] = "${lastKnownDisplayStrings[LOCATION]} ($location)"
- } // "MelonKingDe's Garden (Plot: 8)"
- } else if (location != "None" && location != "invalid") {
- lastKnownDisplayStrings[LOCATION] = location
}
lastKnownDisplayStrings[LOCATION] ?: "None"// only display None if we don't have a last known area
}),
@@ -128,14 +132,19 @@ enum class DiscordStatus(private val displayMessageSupplier: Supplier<String>?)
val motes = scoreboard.firstOrNull { motesRegex.matches(it.removeColor()) }?.let {
motesRegex.find(it.removeColor())?.groupValues?.get(1) ?: ""
}
- if (coins == "1") {
- lastKnownDisplayStrings[PURSE] = "1 Coin"
- } else if (coins != "" && coins != null) {
- lastKnownDisplayStrings[PURSE] = "$coins Coins"
- } else if (motes == "1") {
- lastKnownDisplayStrings[PURSE] = "1 Mote"
- } else if (motes != "" && motes != null) {
- lastKnownDisplayStrings[PURSE] = "$motes Motes"
+ when {
+ coins == "1" -> {
+ lastKnownDisplayStrings[PURSE] = "1 Coin"
+ }
+ coins != "" && coins != null -> {
+ lastKnownDisplayStrings[PURSE] = "$coins Coins"
+ }
+ motes == "1" -> {
+ lastKnownDisplayStrings[PURSE] = "1 Mote"
+ }
+ motes != "" && motes != null -> {
+ lastKnownDisplayStrings[PURSE] = "$motes Motes"
+ }
}
lastKnownDisplayStrings[PURSE] ?: ""
}),
@@ -210,10 +219,12 @@ enum class DiscordStatus(private val displayMessageSupplier: Supplier<String>?)
var profile = "SkyBlock Level: [$sbLevel] on "
profile += (
- if (HypixelData.ironman) "♲"
- else if (HypixelData.bingo) "Ⓑ"
- else if (HypixelData.stranded) "☀"
- else ""
+ when {
+ HypixelData.ironman -> "♲"
+ HypixelData.bingo -> "Ⓑ"
+ HypixelData.stranded -> "☀"
+ else -> ""
+ }
)
val fruit = HypixelData.profileName.firstLetterUppercase()
@@ -235,18 +246,23 @@ enum class DiscordStatus(private val displayMessageSupplier: Supplier<String>?)
for (line in ScoreboardData.sidebarLinesFormatted) {
val noColorLine = line.removeColor()
val match = slayerRegex.matcher(noColorLine)
- if (match.matches()) {
- slayerName = match.group("name")
- slayerLevel = match.group("level")
- } else if (noColorLine == "Slay the boss!") bossAlive = "slaying"
- else if (noColorLine == "Boss slain!") bossAlive = "slain"
+ when {
+ match.matches() -> {
+ slayerName = match.group("name")
+ slayerLevel = match.group("level")
+ }
+ noColorLine == "Slay the boss!" -> bossAlive = "slaying"
+ noColorLine == "Boss slain!" -> bossAlive = "slain"
+ }
}
- if (slayerLevel == "") AutoStatus.SLAYER.placeholderText // selected slayer in rpc but hasn't started a quest
- else if (bossAlive == "spawning") "Spawning a $slayerName $slayerLevel boss."
- else if (bossAlive == "slaying") "Slaying a $slayerName $slayerLevel boss."
- else if (bossAlive == "slain") "Finished slaying a $slayerName $slayerLevel boss."
- else "Something went wrong with slayer detection!"
+ when {
+ slayerLevel == "" -> AutoStatus.SLAYER.placeholderText // selected slayer in rpc but hasn't started a quest
+ bossAlive == "spawning" -> "Spawning a $slayerName $slayerLevel boss."
+ bossAlive == "slaying" -> "Slaying a $slayerName $slayerLevel boss."
+ bossAlive == "slain" -> "Finished slaying a $slayerName $slayerLevel boss."
+ else -> "Something went wrong with slayer detection!"
+ }
}),
CUSTOM({
diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/ghostcounter/GhostUtil.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/ghostcounter/GhostUtil.kt
index c0e506abf..365a8db0e 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/misc/ghostcounter/GhostUtil.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/misc/ghostcounter/GhostUtil.kt
@@ -31,22 +31,28 @@ object GhostUtil {
val hours = millis / 1000 / 60 / 60 % 24
val days = millis / 1000 / 60 / 60 / 24
return buildMap {
- if (millis < 0) {
- clear()
- } else if (minutes == 0L && hours == 0L && days == 0L) {
- put("seconds", seconds.toString())
- } else if (hours == 0L && days == 0L) {
- put("seconds", seconds.toString())
- put("minutes", minutes.toString())
- } else if (days == 0L) {
- put("seconds", seconds.toString())
- put("minutes", minutes.toString())
- put("hours", hours.toString())
- } else {
- put("seconds", seconds.toString())
- put("minutes", minutes.toString())
- put("hours", hours.toString())
- put("days", days.toString())
+ when {
+ millis < 0 -> {
+ clear()
+ }
+ minutes == 0L && hours == 0L && days == 0L -> {
+ put("seconds", seconds.toString())
+ }
+ hours == 0L && days == 0L -> {
+ put("seconds", seconds.toString())
+ put("minutes", minutes.toString())
+ }
+ days == 0L -> {
+ put("seconds", seconds.toString())
+ put("minutes", minutes.toString())
+ put("hours", hours.toString())
+ }
+ else -> {
+ put("seconds", seconds.toString())
+ put("minutes", minutes.toString())
+ put("hours", hours.toString())
+ put("days", days.toString())
+ }
}
}
}