aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authoralexia <me@alexia.lol>2024-02-16 08:55:11 +0100
committerGitHub <noreply@github.com>2024-02-16 08:55:11 +0100
commit24b0c5f7313fd3f91e4f6e7686b6bac8c38d7750 (patch)
tree65bdc64bb157d5574a53cb05197de33c034312f6 /src/main
parent20f087a2597ee46260c949414bed3ce16df8a8bb (diff)
downloadskyhanni-24b0c5f7313fd3f91e4f6e7686b6bac8c38d7750.tar.gz
skyhanni-24b0c5f7313fd3f91e4f6e7686b6bac8c38d7750.tar.bz2
skyhanni-24b0c5f7313fd3f91e4f6e7686b6bac8c38d7750.zip
Clean up string pluralization methods. #975
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/bingo/card/BingoCardDisplay.kt4
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/fishing/FishingTimer.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/farming/FarmingWeightDisplay.kt4
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestFinder.kt4
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestSpawn.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt11
6 files changed, 14 insertions, 13 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/bingo/card/BingoCardDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/bingo/card/BingoCardDisplay.kt
index f7c166d37..2c0245985 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/bingo/card/BingoCardDisplay.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/bingo/card/BingoCardDisplay.kt
@@ -123,7 +123,7 @@ class BingoCardDisplay {
}
if (hiddenGoals > 0) {
- val name = StringUtils.canBePlural(hiddenGoals, "goal", "goals")
+ val name = StringUtils.pluralize(hiddenGoals, "goal")
add(Renderable.string("§7+ $hiddenGoals more §cunknown §7community $name."))
}
add(Renderable.string(" "))
@@ -156,7 +156,7 @@ class BingoCardDisplay {
addGoals(todo) { it.description.removeColor() }
if (hiddenGoals > 0) {
- val name = StringUtils.canBePlural(hiddenGoals, "goal", "goals")
+ val name = StringUtils.pluralize(hiddenGoals, "goal")
add(Renderable.string("§7+ $hiddenGoals more §cunknown §7$name."))
}
hasHiddenPersonalGoals = config.nextTipDuration.get() && nextTip != 14.days
diff --git a/src/main/java/at/hannibal2/skyhanni/features/fishing/FishingTimer.kt b/src/main/java/at/hannibal2/skyhanni/features/fishing/FishingTimer.kt
index 4257d7790..130daa29c 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/fishing/FishingTimer.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/fishing/FishingTimer.kt
@@ -113,7 +113,7 @@ class FishingTimer {
val barnTimerAlertTime = config.alertTime * 1_000
val color = if (duration > barnTimerAlertTime) "§c" else "§e"
val timeFormat = TimeUtils.formatDuration(duration, biggestUnit = TimeUnit.MINUTE)
- val name = StringUtils.canBePlural(currentCount, "sea creature", "sea creatures")
+ val name = StringUtils.pluralize(currentCount, "sea creature")
val text = "$color$timeFormat §8(§e$currentCount §b$name§8)"
config.pos.renderString(text, posLabel = "BarnTimer")
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/FarmingWeightDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/FarmingWeightDisplay.kt
index e43bbb7dd..a5fd423fb 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/FarmingWeightDisplay.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/FarmingWeightDisplay.kt
@@ -396,9 +396,9 @@ class FarmingWeightDisplay {
if (diff == 0) return
if (diff > 0) {
- showLbChange("§cdropped ${StringUtils.optionalPlural(diff, "place", "places")}", oldPosition)
+ showLbChange("§cdropped ${StringUtils.pluralize(diff, "place", withNumber = true)}", oldPosition)
} else {
- showLbChange("§arisen ${StringUtils.optionalPlural(-diff, "place", "places")}", oldPosition)
+ showLbChange("§arisen ${StringUtils.pluralize(-diff, "place", withNumber = true)}", oldPosition)
}
}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestFinder.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestFinder.kt
index 63a4b66d3..c46b73f01 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestFinder.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestFinder.kt
@@ -96,7 +96,7 @@ class PestFinder {
for (plot in getPlotsWithPests()) {
val pests = plot.pests
val plotName = plot.name
- val pestsName = StringUtils.optionalPlural(pests, "pest", "pests")
+ val pestsName = StringUtils.pluralize(pests, "pest", withNumber = true)
val renderable = Renderable.clickAndHover(
"§c$pestsName §7in §b$plotName",
listOf(
@@ -211,7 +211,7 @@ class PestFinder {
}
event.renderPlot(plot, LorenzColor.GOLD.toColor(), LorenzColor.RED.toColor())
- val pestsName = StringUtils.optionalPlural(plot.pests, "pest", "pests")
+ val pestsName = StringUtils.pluralize(plot.pests, "pest", withNumber = true)
val plotName = plot.name
val middle = plot.middle
val location = playerLocation.copy(x = middle.x, z = middle.z)
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestSpawn.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestSpawn.kt
index df044dbc1..bc1ae651c 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestSpawn.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestSpawn.kt
@@ -49,7 +49,7 @@ class PestSpawn {
private fun pestSpawn(amount: Int, plotName: String) {
PestSpawnEvent(amount, plotName).postAndCatch()
- val pestName = StringUtils.canBePlural(amount, "Pest", "Pests")
+ val pestName = StringUtils.pluralize(amount, "Pest")
val message = "§e$amount §a$pestName Spawned in §b$plotName§a!"
if (config.showTitle) {
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt
index 50bdd453b..926efc877 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt
@@ -183,11 +183,12 @@ object StringUtils {
return "$allButLast$delimiterColor, and ${list[lastIndex]}"
}
- fun optionalPlural(number: Int, singular: String, plural: String) =
- "${number.addSeparators()} " + canBePlural(number, singular, plural)
-
- fun canBePlural(number: Int, singular: String, plural: String) =
- if (number == 1) singular else plural
+ fun pluralize(number: Int, singular: String, plural: String? = null, withNumber: Boolean = false): String {
+ val pluralForm = plural ?: "${singular}s"
+ var str = if (number == 1) singular else pluralForm
+ if (withNumber) str = "${number.addSeparators()} $str"
+ return str
+ }
fun progressBar(percentage: Double, steps: Int = 24): Any {
//'§5§o§2§l§m §l§m §l§m §l§m §l§m §l§m §l§m §l§m §l§m §l§m §f§l§m §l§m §l§m §l§m §l§m §l§m §l§m §l§m §l§m §l§m §l§m §l§m §l§m §l§m §l§m §r §e348,144.3§6/§e936k'