aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-05-18 14:26:18 +0200
committerLinnea Gräf <nea@nea.moe>2024-05-18 14:26:18 +0200
commitad09808c25c769be760559e1a597e29e488827bf (patch)
tree4eac7af13184e42a009c051837647bf17b905e16 /src
parenta7a1e099d5c72041f7553fb7ae96bd5a73a5316c (diff)
downloadfirmament-ad09808c25c769be760559e1a597e29e488827bf.tar.gz
firmament-ad09808c25c769be760559e1a597e29e488827bf.tar.bz2
firmament-ad09808c25c769be760559e1a597e29e488827bf.zip
Fix crash for buggy-ish repo items
Diffstat (limited to 'src')
-rw-r--r--src/main/kotlin/moe/nea/firmament/util/SkyblockId.kt14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/main/kotlin/moe/nea/firmament/util/SkyblockId.kt b/src/main/kotlin/moe/nea/firmament/util/SkyblockId.kt
index 413231d..3de5c26 100644
--- a/src/main/kotlin/moe/nea/firmament/util/SkyblockId.kt
+++ b/src/main/kotlin/moe/nea/firmament/util/SkyblockId.kt
@@ -11,10 +11,9 @@ package moe.nea.firmament.util
import io.github.moulberry.repo.data.NEUItem
import io.github.moulberry.repo.data.Rarity
-import java.util.*
+import java.util.UUID
import kotlinx.serialization.Serializable
import kotlinx.serialization.UseSerializers
-import kotlinx.serialization.decodeFromString
import kotlinx.serialization.json.Json
import net.minecraft.component.DataComponentTypes
import net.minecraft.item.ItemStack
@@ -31,7 +30,15 @@ import moe.nea.firmament.util.json.DashlessUUIDSerializer
@JvmInline
@Serializable
value class SkyblockId(val neuItem: String) {
- val identifier get() = Identifier("skyblockitem", neuItem.lowercase().replace(";", "__").replace(":", "___"))
+ val identifier
+ get() = Identifier("skyblockitem",
+ neuItem.lowercase().replace(";", "__")
+ .replace(":", "___")
+ .replace(illlegalPathRegex) {
+ it.value.toCharArray()
+ .joinToString("") { "__" + it.code.toString(16).padStart(4, '0') }
+ })
+
override fun toString(): String {
return neuItem
}
@@ -58,6 +65,7 @@ value class SkyblockId(val neuItem: String) {
private val bazaarEnchantmentRegex = "ENCHANTMENT_(\\D*)_(\\d+)".toRegex()
val NULL: SkyblockId = SkyblockId("null")
val PET_NULL: SkyblockId = SkyblockId("null_pet")
+ private val illlegalPathRegex = "[^a-z0-9_.-/]".toRegex()
}
}