Updated placeholder injection

This commit is contained in:
Auxilor
2022-04-22 09:48:11 +01:00
parent b75e4d59e4
commit eb9112e480
14 changed files with 248 additions and 48 deletions

View File

@@ -61,13 +61,9 @@ class EcoHandler : EcoSpigotPlugin(), Handler {
if (this.configYml.getBool("use-safer-namespacedkey-creation"))
SafeInternalNamespacedKeyFactory() else FastInternalNamespacedKeyFactory()
override fun createScheduler(plugin: EcoPlugin): EcoScheduler {
return EcoScheduler(plugin)
}
override fun createScheduler(plugin: EcoPlugin): EcoScheduler = EcoScheduler(plugin)
override fun createEventManager(plugin: EcoPlugin): EcoEventManager {
return EcoEventManager(plugin)
}
override fun createEventManager(plugin: EcoPlugin) = EcoEventManager(plugin)
override fun createNamespacedKeyFactory(plugin: EcoPlugin): EcoNamespacedKeyFactory {
return EcoNamespacedKeyFactory(plugin)

View File

@@ -176,7 +176,7 @@ abstract class EcoSpigotPlugin : EcoPlugin() {
val tpsProxy = getProxy(TPSProxy::class.java)
ServerUtils.initialize { tpsProxy.getTPS() }
NumberUtils.initCrunch { expression, player, statics -> evaluateExpression(expression, player, statics) }
NumberUtils.initCrunch { expression, player, context -> evaluateExpression(expression, player, context) }
CustomItemsManager.registerProviders()

View File

@@ -3,7 +3,7 @@ package com.willfp.eco.internal.spigot.math
import com.github.benmanes.caffeine.cache.Cache
import com.github.benmanes.caffeine.cache.Caffeine
import com.willfp.eco.core.integrations.placeholder.PlaceholderManager
import com.willfp.eco.core.placeholder.StaticPlaceholder
import com.willfp.eco.core.placeholder.PlaceholderInjectable
import org.bukkit.entity.Player
import redempt.crunch.CompiledExpression
import redempt.crunch.Crunch
@@ -13,9 +13,9 @@ import redempt.crunch.functional.EvaluationEnvironment
private val cache: Cache<String, CompiledExpression> = Caffeine.newBuilder().build()
private val goToZero = Crunch.compileExpression("0")
fun evaluateExpression(expression: String, player: Player?, statics: Iterable<StaticPlaceholder>): Double {
fun evaluateExpression(expression: String, player: Player?, context: PlaceholderInjectable): Double {
val placeholderValues = PlaceholderManager.findPlaceholdersIn(expression)
.map { PlaceholderManager.translatePlaceholders(it, player, statics.toList()) }
.map { PlaceholderManager.translatePlaceholders(it, player, context) }
.map { runCatching { FastNumberParsing.parseDouble(it) }.getOrDefault(0.0) }
.toDoubleArray()