Fixed statics in expressions
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user