Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,12 @@ class MongoDBPersistentDataHandler(
}

override fun deserialize(value: BsonValue): Int {
return value.asInt32().value
// Handle both INT32 and DOUBLE
return when {
value.isInt32 -> value.asInt32().value
value.isDouble -> value.asDouble().value.toInt()
else -> 0 // default value
}
}
})

Expand All @@ -79,7 +84,12 @@ class MongoDBPersistentDataHandler(
}

override fun deserialize(value: BsonValue): Double {
return value.asDouble().value
// Handle both DOUBLE and INT32
return when {
value.isDouble -> value.asDouble().value
value.isInt32 -> value.asInt32().value.toDouble()
else -> 0.0 // default value
}
}
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,33 @@ class MySQLPersistentDataHandler(
}
}.createTable())

PersistentDataKeyType.INT.registerSerializer(this, object : DirectStoreSerializer<Int>() {
override val table = object : KeyTable<Int>("int") {
override val value = integer(VALUE_COLUMN_NAME)
PersistentDataKeyType.INT.registerSerializer(this, object : SingleValueSerializer<Int, String>() {
override val table = object : KeyTable<String>("int") {
override val value = varchar(VALUE_COLUMN_NAME, 64)
}

override fun convertToStored(value: Int): String {
return value.toString()
}

override fun convertFromStored(value: String): Int {
// Handle both int and double string representations
return value.toDoubleOrNull()?.toInt() ?: value.toIntOrNull() ?: 0
}
}.createTable())

PersistentDataKeyType.DOUBLE.registerSerializer(this, object : DirectStoreSerializer<Double>() {
override val table = object : KeyTable<Double>("double") {
override val value = double(VALUE_COLUMN_NAME)
PersistentDataKeyType.DOUBLE.registerSerializer(this, object : SingleValueSerializer<Double, String>() {
override val table = object : KeyTable<String>("double") {
override val value = varchar(VALUE_COLUMN_NAME, 64)
}

override fun convertToStored(value: Double): String {
return value.toString()
}

override fun convertFromStored(value: String): Double {
// Handle both double and int string representations
return value.toDoubleOrNull() ?: 0.0
}
}.createTable())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ class DelegatedExpressionHandler(
) : ExpressionHandler {
private val evaluationCache: Cache<Int, Double?> = Caffeine.newBuilder()
.expireAfterWrite(plugin.configYml.getInt("math-cache-ttl").toLong(), TimeUnit.MILLISECONDS)
.buildAsync<Int, Double?>()
.synchronous()
.build()

override fun evaluate(expression: String, context: PlaceholderContext): Double? {
expression.fastToDoubleOrNull()?.let { return it }
Expand Down