com.skillw.pouvoir.util.CalculationUtil.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of Pouvoir Show documentation
Show all versions of Pouvoir Show documentation
Bukkit Script Engine Plugin.
package com.skillw.pouvoir.util
import com.skillw.pouvoir.Pouvoir
import com.skillw.pouvoir.util.calculate.calculateInfix
import org.bukkit.entity.LivingEntity
/**
* 计算工具类
*
* @constructor Create empty Calculation utils
*/
fun String.calculate(entity: LivingEntity? = null): Double {
return calculate(Pouvoir.placeholderManager.replace(entity, this))
}
fun String.calculateDouble(entity: LivingEntity? = null): Double {
return calculate(entity)
}
fun String.calculateInline(entity: LivingEntity? = null): String {
var previousChar = 'a'
val replacement = HashMap()
var start = -1
forEachIndexed { index, char ->
if (previousChar == '{' && char == '{') {
start = index - 1
}
if (previousChar == '}' && char == '}') {
if (start == -1) return@forEachIndexed
replacement += start..index to this.substring(start + 2, index - 1).calculate(entity).toString()
start = -1
}
previousChar = char
}
return replacementIntRange(replacement)
}
fun calculate(input: String): Double {
return input.calculateInfix()
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy