Fixed statics in expressions

This commit is contained in:
Auxilor
2022-03-11 16:28:21 +00:00
parent efcb406e9a
commit 00df39097c

View File

@@ -15,14 +15,12 @@ private val goToZero = Crunch.compileExpression("0")
fun evaluateExpression(expression: String, player: Player?, statics: Iterable<StaticPlaceholder>): Double {
val placeholderValues = PlaceholderManager.findPlaceholdersIn(expression)
.map { PlaceholderManager.translatePlaceholders(it, player) }
.union(statics.map { it.value })
.toList()
.map { PlaceholderManager.translatePlaceholders(it, player, statics.toList()) }
.map { runCatching { FastNumberParsing.parseDouble(it) }.getOrDefault(0.0) }
.toDoubleArray()
val compiled = cache.get(expression) {
val placeholders = PlaceholderManager.findPlaceholdersIn(it) union statics.map { static -> "%${static.identifier}%" }
val placeholders = PlaceholderManager.findPlaceholdersIn(it)
val env = EvaluationEnvironment()
env.setVariableNames(*placeholders.toTypedArray())
runCatching { Crunch.compileExpression(expression, env) }.getOrDefault(goToZero)