aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal002@users.noreply.github.com>2024-04-24 01:18:45 +0200
committerGitHub <noreply@github.com>2024-04-24 01:18:45 +0200
commit0d1dc84d2224aeb8c0ba399057ea28f5bb291eaa (patch)
tree406446053f56a29803c7b63d73c30604cf26a669 /src/main/java
parentc2a0e59d760b64b0fe7d1676470ebf931434be6d (diff)
downloadskyhanni-0d1dc84d2224aeb8c0ba399057ea28f5bb291eaa.tar.gz
skyhanni-0d1dc84d2224aeb8c0ba399057ea28f5bb291eaa.tar.bz2
skyhanni-0d1dc84d2224aeb8c0ba399057ea28f5bb291eaa.zip
Fix: gfs error with 0 (#1528)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/api/GetFromSackAPI.kt6
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt6
2 files changed, 6 insertions, 6 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/api/GetFromSackAPI.kt b/src/main/java/at/hannibal2/skyhanni/api/GetFromSackAPI.kt
index ba0e334a0..ad5ea7b6e 100644
--- a/src/main/java/at/hannibal2/skyhanni/api/GetFromSackAPI.kt
+++ b/src/main/java/at/hannibal2/skyhanni/api/GetFromSackAPI.kt
@@ -16,7 +16,7 @@ import at.hannibal2.skyhanni.utils.ChatUtils.senderIsSkyhanni
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.NEUInternalName
import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName
-import at.hannibal2.skyhanni.utils.NumberUtil.isInt
+import at.hannibal2.skyhanni.utils.NumberUtil.isDouble
import at.hannibal2.skyhanni.utils.PrimitiveItemStack
import at.hannibal2.skyhanni.utils.PrimitiveItemStack.Companion.makePrimitiveStack
import at.hannibal2.skyhanni.utils.SimpleTimeMark
@@ -169,7 +169,7 @@ object GetFromSackAPI {
var amountString = args.last()
amountString = Calculator.calculate(amountString).toString()
- if (!amountString.isInt()) return CommandResult.WRONG_AMOUNT to null
+ if (!amountString.isDouble()) return CommandResult.WRONG_AMOUNT to null
val itemString = args.dropLast(1).joinToString(" ").uppercase().replace(':', '-')
@@ -187,7 +187,7 @@ object GetFromSackAPI {
else -> return CommandResult.WRONG_IDENTIFIER to null
}
- return CommandResult.VALID to PrimitiveItemStack(item, amountString.toInt())
+ return CommandResult.VALID to PrimitiveItemStack(item, amountString.toDouble().toInt())
}
@SubscribeEvent
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt b/src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt
index d266e80ce..5df1915c0 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt
@@ -173,9 +173,9 @@ object NumberUtil {
private val numberPattern = "^[0-9]*$".toPattern()
private val formatPattern = "^[0-9,.]*[kmb]?$".toPattern()
- fun String.isInt(): Boolean {
- return isNotEmpty() && numberPattern.matcher(this).matches()
- }
+ fun String.isInt(): Boolean = isNotEmpty() && numberPattern.matcher(this).matches()
+
+ fun String.isDouble(): Boolean = runCatching { toDouble() }.getOrNull() != null
fun String.isFormatNumber(): Boolean {
return isNotEmpty() && formatPattern.matches(this)