Added error safety to CrunchHandler
This commit is contained in:
@@ -4,14 +4,17 @@ import com.willfp.eco.core.integrations.placeholder.PlaceholderManager
|
||||
import org.bukkit.entity.Player
|
||||
import redempt.crunch.CompiledExpression
|
||||
import redempt.crunch.Crunch
|
||||
import redempt.crunch.data.FastNumberParsing
|
||||
import redempt.crunch.functional.EvaluationEnvironment
|
||||
|
||||
private val cache = mutableMapOf<String, CompiledExpression>()
|
||||
|
||||
fun evaluateExpression(expression: String, player: Player?): Double {
|
||||
val placeholderValues = PlaceholderManager.findPlaceholdersIn(expression)
|
||||
.map { PlaceholderManager.getResult(player, expression).toDouble() }
|
||||
.map { PlaceholderManager.getResult(player, expression) }
|
||||
.map { runCatching { FastNumberParsing.parseDouble(it) }.getOrDefault(0.0) }
|
||||
.toDoubleArray()
|
||||
|
||||
val compiled = generateExpression(expression)
|
||||
return compiled.evaluate(*placeholderValues)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user