From 0d1dc84d2224aeb8c0ba399057ea28f5bb291eaa Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal002@users.noreply.github.com> Date: Wed, 24 Apr 2024 01:18:45 +0200 Subject: Fix: gfs error with 0 (#1528) Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> --- src/main/java/at/hannibal2/skyhanni/api/GetFromSackAPI.kt | 6 +++--- src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt | 6 +++--- 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) -- cgit