aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/fame/CityProjectFeatures.kt10
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/AnitaMedalProfit.kt8
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/composter/GardenComposterInventoryFeatures.kt5
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/inventory/GardenNextPlotPrice.kt6
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt11
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt4
6 files changed, 21 insertions, 23 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/fame/CityProjectFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/fame/CityProjectFeatures.kt
index c27bc0740..706de6807 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/fame/CityProjectFeatures.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/fame/CityProjectFeatures.kt
@@ -149,12 +149,10 @@ class CityProjectFeatures {
if (line == "") break
if (line.contains("Bits")) break
- val (name, amount) = ItemUtils.readItemAmount(line)
- if (name != null) {
- val internalName = NEUItems.getRawInternalName(name)
- val old = materials.getOrPut(internalName) { 0 }
- materials[internalName] = old + amount
- }
+ val (name, amount) = ItemUtils.readItemAmount(line) ?: continue
+ val internalName = NEUItems.getRawInternalName(name)
+ val old = materials.getOrPut(internalName) { 0 }
+ materials[internalName] = old + amount
}
}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/AnitaMedalProfit.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/AnitaMedalProfit.kt
index 0fb0be6ff..dcc645f5e 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/AnitaMedalProfit.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/AnitaMedalProfit.kt
@@ -72,8 +72,7 @@ class AnitaMedalProfit {
val fullCost = getFullCost(getRequiredItems(item))
if (fullCost < 0) return
- val (name, amount) = ItemUtils.readItemAmount(itemName)
- if (name == null) return
+ val (name, amount) = ItemUtils.readItemAmount(itemName) ?: return
var internalName = NEUItems.getInternalNameOrNull(name)
if (internalName == null) {
@@ -93,12 +92,13 @@ class AnitaMedalProfit {
val jacobTicketPrice = "JACOBS_TICKET".asInternalName().getPrice()
var otherItemsPrice = 0.0
for (rawItemName in requiredItems) {
- val (name, amount) = ItemUtils.readItemAmount(rawItemName)
- if (name == null) {
+ val pair = ItemUtils.readItemAmount(rawItemName)
+ if (pair == null) {
LorenzUtils.error("§c[SkyHanni] Could not read item '$rawItemName'")
continue
}
+ val (name, amount) = pair
val medal = getMedal(name)
otherItemsPrice += if (medal != null) {
val bronze = medal.factorBronze * amount
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/composter/GardenComposterInventoryFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/composter/GardenComposterInventoryFeatures.kt
index cde25d493..0ed673431 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/composter/GardenComposterInventoryFeatures.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/composter/GardenComposterInventoryFeatures.kt
@@ -40,11 +40,12 @@ class GardenComposterInventoryFeatures {
if (next) {
if (line.endsWith(" Copper")) continue
if (line == "") break
- val (itemName, amount) = ItemUtils.readItemAmount(line)
- if (itemName == null) {
+ val pair = ItemUtils.readItemAmount(line)
+ if (pair == null) {
LorenzUtils.error("§c[SkyHanni] Could not read item '$line'")
continue
}
+ val (itemName, amount) = pair
val internalName = NEUItems.getInternalNameOrNull(itemName)
if (internalName == null) {
LorenzUtils.chat(
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/GardenNextPlotPrice.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/GardenNextPlotPrice.kt
index 759bbaa1d..ca82b3b17 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/GardenNextPlotPrice.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/GardenNextPlotPrice.kt
@@ -31,13 +31,13 @@ class GardenNextPlotPrice {
}
if (next) {
- val (itemName, amount) = ItemUtils.readItemAmount(line)
- if (itemName != null) {
+ ItemUtils.readItemAmount(line)?.let {
+ val (itemName, amount) = it
val lowestBin = NEUItems.getPrice(NEUItems.getRawInternalName(itemName))
val price = lowestBin * amount
val format = NumberUtil.format(price)
list[i] = list[i] + " §7(§6$format§7)"
- } else {
+ } ?: {
LorenzUtils.error("§c[SkyHanni] Could not read item '$line'")
}
break
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt
index 47e229355..729c1870b 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt
@@ -113,11 +113,12 @@ class GardenVisitorFeatures {
if (line == "§7Items Required:") continue
if (line.isEmpty()) break
- val (itemName, amount) = ItemUtils.readItemAmount(line)
- if (itemName == null) {
+ val pair = ItemUtils.readItemAmount(line)
+ if (pair == null) {
LorenzUtils.error("§c[SkyHanni] Could not read item '$line'")
continue
}
+ val (itemName, amount) = pair
val internalName = NEUInternalName.fromItemName(itemName)
visitor.items[internalName] = amount
}
@@ -387,8 +388,7 @@ class GardenVisitorFeatures {
readingItemsNeeded = false
}
- val (itemName, amount) = ItemUtils.readItemAmount(formattedLine)
- if (itemName == null) continue
+ val (itemName, amount) = ItemUtils.readItemAmount(formattedLine) ?: continue
val internalName = NEUItems.getInternalNameOrNull(itemName)?.replace("◆_", "") ?: continue
val price = internalName.getPrice() * amount
@@ -429,8 +429,7 @@ class GardenVisitorFeatures {
readingItemsNeeded = false
}
- val (itemName, amount) = ItemUtils.readItemAmount(formattedLine)
- if (itemName == null) continue
+ val (itemName, amount) = ItemUtils.readItemAmount(formattedLine) ?: continue
val internalName = NEUItems.getInternalNameOrNull(itemName)?.replace("◆_", "") ?: continue
val price = internalName.getPrice() * amount
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt
index 510ef0aa3..bedbebc46 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt
@@ -189,7 +189,7 @@ object ItemUtils {
private val itemAmountCache = mutableMapOf<String, Pair<String, Int>>()
- fun readItemAmount(input: String): Pair<String?, Int> {
+ fun readItemAmount(input: String): Pair<String, Int>? {
if (itemAmountCache.containsKey(input)) {
return itemAmountCache[input]!!
}
@@ -213,7 +213,7 @@ object ItemUtils {
println("")
println("input: '$input'")
println("string: '$string'")
- return Pair(null, 0)
+ return null
}
val itemName = color + matcher.group("name").trim()