From 2d23c05c476c107a1b4d0fee3bd5f8528e034782 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Fri, 12 May 2023 14:25:25 +0100 Subject: [PATCH] Added kotlin extensions to NumberUtils methods --- .../java/com/willfp/eco/util/NumberUtils.java | 2 +- .../kotlin/com/willfp/eco/util/NumberUtils.kt | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/eco-api/src/main/java/com/willfp/eco/util/NumberUtils.java b/eco-api/src/main/java/com/willfp/eco/util/NumberUtils.java index 9abdee76..5f94a2d5 100644 --- a/eco-api/src/main/java/com/willfp/eco/util/NumberUtils.java +++ b/eco-api/src/main/java/com/willfp/eco/util/NumberUtils.java @@ -268,7 +268,7 @@ public final class NumberUtils { * @deprecated Use {@link #evaluateExpression(String, PlaceholderContext)} instead. */ @Deprecated(since = "6.56.0", forRemoval = true) - @SuppressWarnings("removal") + @SuppressWarnings({"removal", "DeprecatedIsStillUsed"}) public static double evaluateExpression(@NotNull final String expression, @NotNull final com.willfp.eco.core.math.MathContext context) { return evaluateExpression(expression, context.toPlaceholderContext()); diff --git a/eco-api/src/main/kotlin/com/willfp/eco/util/NumberUtils.kt b/eco-api/src/main/kotlin/com/willfp/eco/util/NumberUtils.kt index 127049c9..53bfda73 100644 --- a/eco-api/src/main/kotlin/com/willfp/eco/util/NumberUtils.kt +++ b/eco-api/src/main/kotlin/com/willfp/eco/util/NumberUtils.kt @@ -2,6 +2,32 @@ package com.willfp.eco.util +import com.willfp.eco.core.placeholder.context.PlaceholderContext + /** @see NumberUtils.toNumeral */ fun Number.toNumeral(): String = NumberUtils.toNumeral(this.toInt()) + +/** @see NumberUtils.fromNumeral */ +fun String.parseNumeral(): Int = + NumberUtils.fromNumeral(this) + +/** @see NumberUtils.randInt */ +fun randInt(min: Int, max: Int) = + NumberUtils.randInt(min, max) + +/** @see NumberUtils.randFloat */ +fun randDouble(min: Double, max: Double) = + NumberUtils.randFloat(min, max) + +/** @see NumberUtils.randFloat */ +fun randFloat(min: Float, max: Float) = + NumberUtils.randFloat(min.toDouble(), max.toDouble()).toFloat() + +/** @see NumberUtils.evaluateExpression */ +fun evaluateExpression(expression: String) = + NumberUtils.evaluateExpression(expression) + +/** @see NumberUtils.evaluateExpression */ +fun evaluateExpression(expression: String, context: PlaceholderContext) = + NumberUtils.evaluateExpression(expression, context)